25 #ifndef _FNET_SOCKET_H_ 27 #define _FNET_SOCKET_H_ 125 #define INADDR_ANY (fnet_ip4_addr_t)(0x00000000U) 131 #define INADDR_BROADCAST (fnet_ip4_addr_t)(0xffffffffU) 147 #define AF_UNSPEC (0U) 155 #define AF_INET6 (2U) 160 #define AF_SUPPORTED ((fnet_address_family_t)((fnet_address_family_t)(AF_INET6*(fnet_address_family_t)FNET_CFG_IP6) | (fnet_address_family_t)(AF_INET*(fnet_address_family_t)FNET_CFG_IP4))) 168 #define FNET_SA_DATA_SIZE (sizeof(struct fnet_in6_addr)) 170 #define FNET_SA_DATA_SIZE (sizeof(struct fnet_in_addr)) 182 #define FNET_IP_ADDR_STR_SIZE FNET_IP6_ADDR_STR_SIZE 184 #define FNET_IP_ADDR_STR_SIZE FNET_IP4_ADDR_STR_SIZE 187 #define FNET_IP_ADDR_STR_SIZE_MAX FNET_IP6_ADDR_STR_SIZE 719 #if defined(__cplusplus) 1424 #if FNET_CFG_SOCKET_CALLBACK_ON_RX || defined(__DOXYGEN__) 1448 #if FNET_CFG_SOCKET_BSD_NAMES 1449 #define socket fnet_socket 1450 #define bind fnet_socket_bind 1451 #define listen fnet_socket_listen 1452 #define accept fnet_socket_accept 1453 #define connect fnet_socket_connect 1454 #define recv fnet_socket_recv 1455 #define recvfrom fnet_socket_recvfrom 1456 #define send fnet_socket_send 1457 #define sendto fnet_socket_sendto 1458 #define shutdown fnet_socket_shutdown 1459 #define closesocket fnet_socket_close 1460 #define setsockopt fnet_socket_setopt 1461 #define getsockopt fnet_socket_getopt 1462 #define getpeername fnet_socket_getpeername 1463 #define getsockname fnet_socket_getname 1466 #if defined(__cplusplus) fnet_return_t fnet_socket_getname(fnet_socket_t s, struct fnet_sockaddr *name, fnet_size_t *namelen)
Retrieves the current name for the specified socket.
IPv6 Socket address structure.
fnet_socket_event_t events
A bit mask specifying the events the application is interested in.
There is no registered event.
fnet_ssize_t fnet_socket_sendto(fnet_socket_t s, const void *buf, fnet_size_t len, fnet_flag_t flags, const struct fnet_sockaddr *to, fnet_size_t tolen)
Sends the data to a specific destination.
Socket options level number for fnet_socket_getopt() and fnet_socket_setopt().
This option defines the IPv4 TTL (time-to-live) vlaue for outgoing datagrams.
When the SO_KEEPALIVE option is enabled, TCP probes a connection that has been idle for some amount o...
fnet_uint16_t sin6_port
16-bit port number used to demultiplex the transport-level messages (in network byte order)...
Complete queue length of the socket. If it has the nonzeo value, unaccepted complete connections are ...
Join the socket to the IPv4 multicast group on the specified interface. It tells the system to receiv...
fnet_uint32_t fnet_scope_id_t
cope zone index type, defining network interface.
fnet_socket_t s
Socket descriptor. If its value is zero, it is ignored.
fnet_scope_id_t imr_interface
Interface index. It equals to the scope zone index, defining network interface. If this member is zer...
fnet_address_family_t sa_family
Address family. Specifies the address family, to which the address belongs. It is defined by fnet_ad...
IPv4 multicast group information.
fnet_sd_flags_t
The flags used by fnet_socket_shutdown().
fnet_return_t fnet_socket_shutdown(fnet_socket_t s, fnet_sd_flags_t how)
Terminates the connection in one or both directions.
fnet_bool_t fnet_socket_addr_are_equal(const struct fnet_sockaddr *addr1, const struct fnet_sockaddr *addr2)
Compares socket addresses.
This option is used to determine the amount of data pending in the socket-input buffer. This is a read-only option.
There is a free buffer space and the socket may accept data for writing. Also, it may be used as the ...
This option defines hop limit used for outgoing unicast IPv6 packets. Its value can be from 0 till ...
unsigned int fnet_flag_t
Unsigned integer type representing the bit flag.
Set the hop limit to use for outgoing multicast IPv6 packets. If IPV6_MULTICAST_HOPS is not set...
Stream socket. Provides reliable, two-way, connection-based byte stream. It corresponds to the TCP p...
Bitmask of all event types.
fnet_return_t fnet_socket_connect(fnet_socket_t s, struct fnet_sockaddr *name, fnet_size_t namelen)
Establishes a connection with the specified socket.
struct fnet_in_addr imr_multiaddr
IPv4 multicast address of group.
Drops membership to a IPv4 multicast group and interface. This option is available only if FNET_CFG_...
struct fnet_in6_addr sin6_addr
128-bit IPv6 internet address.
If this option is set to 1, the Nagle algorithm is disabled (and vice versa). The Nagle algorithm i...
Returns 1 if a socket is in listening mode and returns 0 when vice versa. This is the read-only optio...
fnet_socket_options_t
Socket options for the fnet_socket_setopt() and the fnet_socket_getopt().
This option is set when the urgent byte arrives, and reset when this byte is read. This option can be set only if the SO_OOBINLINE option is set to 0. This is the read-only option. This option is avalable only if FNET_CFG_TCP_URGENT is set to 1.
Data sending is disabled.
fnet_scope_id_t sa_scope_id
Scope zone index, defining network interface.
fnet_return_t
General return codes, used by most of API functions.
Process out-of-band data instead of regular data. This option is avalable only if FNET_CFG_TCP_URGE...
fnet_ssize_t fnet_socket_recv(fnet_socket_t s, void *buf, fnet_size_t len, fnet_flag_t flags)
Receives the data from a connected socket.
This option enables bypassing of a routing algorithm. It means that the network interface tries to se...
fnet_scope_id_t sin6_scope_id
Scope zone index, defining network interface.
Receive a copy of the data without consuming it.
This option is used to determine the amount of data in the socket output buffer. This is a read-onl...
This option enables keep-alive probes for a socket connection. These probes are used to maintain a TC...
This option defines the maximum size of the input segments (MSS). The TCP Maximum Segment Size (MSS...
This option is set when the final (FIN) segment arrives. This option indicates that another side wi...
fnet_scope_id_t ipv6imr_interface
Interface index. It equals to the scope zone index, defining network interface. If this member is zer...
fnet_ip6_addr_t s6_addr
128-bit IPv6 address.
IPv6 options level number for fnet_socket_getopt() and fnet_socket_setopt().
fnet_uint16_t sa_port
16-bit port number used to demultiplex the transport-level messages (in network byte order)...
(RFC3493) Join a multicast group on a specified local interface. It is valid only for the SOCK_DGRAM...
fnet_bool_t l_onoff
Determines, whether the option will be turned on FNET_TRUE, or off FNET_FALSE.
void * fnet_socket_t
Socket descriptor.
unsigned long fnet_size_t
Unsigned integer type representing the size in bytes.
128-bit IPv6 address type.
fnet_return_t fnet_socket_getopt(fnet_socket_t s, fnet_protocol_t level, fnet_socket_options_t optname, void *optval, fnet_size_t *optvallen)
Gets a socket option.
fnet_socket_event_t events_occurred
A bit mask specifying the events that actually occurred. It is filled by by the fnet_socket_poll() an...
fnet_ssize_t fnet_socket_send(fnet_socket_t s, const void *buf, fnet_size_t len, fnet_flag_t flags)
Sends the data on a connected socket.
fnet_size_t fnet_socket_poll(fnet_socket_poll_t *socket_poll, fnet_size_t socket_poll_size)
Polls socket event state.
IPv4 options level number for fnet_socket_getopt() and fnet_socket_setopt().
Data receiving is disabled.
fnet_protocol_t
Protocol numbers and Level numbers for the fnet_socket_setopt() and the fnet_socket_getopt().
This structure is used for the SO_LINGER option.
fnet_socket_state_t
Socket state.
This option allows to change IPv4 "time to live" (TTL) value for outgoing multicast datagrams...
fnet_return_t fnet_socket_bind(fnet_socket_t s, const struct fnet_sockaddr *name, fnet_size_t namelen)
Assigns a local address to a socket.
This option defines the maximum per-socket buffer size for output data.
#define FNET_SA_DATA_SIZE
Size of sa_data[] field of fnet_sockaddr structure. It used to cover fnet_sockaddr_in and fnet_socka...
This option returns a per-socket-based error code. The error code is defined by the fnet_error_t typ...
IPv6 multicast group information.
Send without using routing tables.
In process of closing connection. For TCP, after FIN receive.
Both receiving and sending are disabled.
struct fnet_in6_addr ipv6imr_multiaddr
IPv6 multicast address of group.
fnet_ip4_addr_t s_addr
32-bit IPv4 address (in network byte order).
fnet_address_family_t sin_family
Specifies the address family. It must ne set to AF_INET.
There is a socket error. It may happen when a connect attempt is failed, or connection is closed by r...
fnet_uint8_t sa_data[FNET_SA_DATA_SIZE]
Address value. For the TCP/IP stack, it contains the destination address and port number for a socket...
fnet_return_t fnet_socket_setopt(fnet_socket_t s, fnet_protocol_t level, fnet_socket_options_t optname, const void *optval, fnet_size_t optvallen)
Sets a socket option.
fnet_socket_t fnet_socket(fnet_address_family_t family, fnet_socket_type_t type, fnet_uint32_t protocol)
Creates a socket.
TCP protocol number; TCP options level number for fnet_socket_getopt() and fnet_socket_setopt().
struct fnet_in_addr sin_addr
32-bit internet address.
Datagram socket. Provides unreliable, connectionless datagrams. It corresponds to the UDP protocol...
This option defines the type of the socket. This is a read-only option and it is defined by the fnet_...
fnet_msg_flags_t
The flags parameters for receiving and sending functions fnet_socket_recv(), fnet_socket_recvfrom(), fnet_socket_send(), and fnet_socket_sendto().
When the SO_KEEPALIVE option is enabled, TCP probes a connection that has been idle for some amount o...
There is data for reading or a new pending connection for accepting.
fnet_ssize_t fnet_socket_recvfrom(fnet_socket_t s, void *buf, fnet_size_t len, fnet_flag_t flags, struct fnet_sockaddr *from, fnet_size_t *fromlen)
Receives the data and captures the address, from which the data was sent.
IPv4 Socket address structure.
Backlog limit of the socket or the maximal number of queued connections, which is set by fnet_socket_...
This option defines the current state of the socket. This is the read-only option and it is defined ...
fnet_bool_t fnet_socket_addr_is_unspecified(const struct fnet_sockaddr *addr)
Determines, if socket address is unspecified.
This option defines the maximum per-socket buffer size for input data.
This option specifies that out-of-band (OOB) data will be received in line with regular data...
fnet_return_t fnet_socket_close(fnet_socket_t s)
Closes an existing socket.
Not connected to any socket.
fnet_socket_type_t
Socket types.
fnet_bool_t fnet_socket_addr_is_multicast(const struct fnet_sockaddr *addr)
Determines, if socket address is multicast.
fnet_socket_event_t
Socket event type, used by fnet_socket_poll_t.
If this option is set to 1, the BSD interpretation of the urgent pointer is used. In this case the ur...
This option controls the action taken when unsent data is present, and fnet_socket_close() is called...
void fnet_socket_set_callback_on_rx(void(*callback)(void))
Registers the "Socket Rx" event handler callback.
fnet_uint32_t fnet_ip4_addr_t
32-bit IPv4 address type.
This option defines the IPv4 TOS (type-of-service) field for outgoing datagrams.
fnet_address_family_t sin6_family
Specifies the address family. It must ne set to AF_INET6.
When the SO_KEEPALIVE option is enabled, TCP probes a connection that has been idle for some amount o...
Socket poll structure used by fnet_socket_poll().
fnet_uint16_t l_linger
Specifies the amount of time (in seconds) to wait when the connection is closed and unsent data is di...
Raw socket. Raw sockets allow an application to have direct access to lower-level communication prot...
In process of connecting.
fnet_return_t fnet_socket_getpeername(fnet_socket_t s, struct fnet_sockaddr *name, fnet_size_t *namelen)
Retrieves the name of a peer connected to a socket.
long fnet_ssize_t
Signed integer type representing the size in bytes.
fnet_uint16_t fnet_address_family_t
Address family type.
Socket address structure.
fnet_socket_t fnet_socket_accept(fnet_socket_t s, struct fnet_sockaddr *addr, fnet_size_t *addrlen)
Accepts a connection on the specified socket.
(RFC3493) Leave a multicast group on a specified interface. It is valid only for the SOCK_DGRAM (UDP...
fnet_return_t fnet_socket_listen(fnet_socket_t s, fnet_size_t backlog)
Places the socket into a state, where it is listening for an incoming connection. ...
fnet_scope_id_t sin_scope_id
Scope zone index, defining network interface.
fnet_uint16_t sin_port
16-bit port number used to demultiplex the transport-level messages (in network byte order)...