Embedded TCP/IP stack
4.1.0
|
Sockets API
Detailed Description
The Socket Application Program Interface (API) defines the way, in which the application program interacts with the TCP/IP stack. It has the BSD-like, non-blocking socket interface that makes porting of existing network applications to the FNET more convenient.
The following table summarizes the supported socket API functions:
Category | FNET Routine | BSD Routine | Meaning | Server | Client | SOCK_STREAM | SOCK_DGRAM |
---|---|---|---|---|---|---|---|
setup | fnet_socket() | socket() | Creates a new unnamed socket within a specified communication domain family. | X | X | X | X |
setup | fnet_socket_bind() | bind() | Assigns a local address to a socket. | X | X | X | X |
server | fnet_socket_listen() | listen() | Prepares a socket to accept the incoming connections. | X | X | ||
server | fnet_socket_accept() | accept() | Accepts the connections. | X | X | ||
client | fnet_socket_connect() | connect() | Establishes a connection to a foreign socket. | X | X | X | |
input | fnet_socket_recv() | recv() | Receives the data. | X | X | X | X |
input | fnet_socket_recvfrom() | recvfrom() | Receives the data and address of the sender. | X | X | X | |
output | fnet_socket_send() | send() | Sends the data. | X | X | X | X |
output | fnet_socket_sendto() | sendto() | Sends the data to a specified address. | X | X | X | |
termination | fnet_socket_shutdown() | shutdown() | Terminates a connection in one or both directions. | X | X | X | X |
termination | fnet_socket_close() | closesocket() | Terminates a connection and releases the socket. | X | X | X | X |
administration | fnet_socket_setopt() | fnet_socket_setopt() | Sets socket or protocol options. | X | X | X | X |
administration | fnet_socket_getopt() | getsockopt() | Gets socket or protocol options. | X | X | X | X |
administration | fnet_socket_getname() | getsockname() | Gets a local address assigned to a socket. | X | X | X | X |
administration | fnet_socket_getpeername() | getpeername() | Gets a foreign address assigned to a socket. | X | X | X | X |
Configuration parameters:
- FNET_CFG_SOCKET_MAX
- FNET_CFG_SOCKET_TCP_TX_BUF_SIZE
- FNET_CFG_SOCKET_TCP_RX_BUF_SIZE
- FNET_CFG_SOCKET_UDP_TX_BUF_SIZE
- FNET_CFG_SOCKET_UDP_RX_BUF_SIZE
- FNET_CFG_SOCKET_TCP_MSS
- FNET_CFG_RAW
- FNET_CFG_SOCKET_BSD_NAMES
- FNET_CFG_SOCKET_CALLBACK_ON_RX
Data Structures | |
union | fnet_ip6_addr_t |
128-bit IPv6 address type. More... | |
struct | fnet_in_addr |
IPv4 address structure. More... | |
struct | fnet_sockaddr_in |
IPv4 Socket address structure. More... | |
struct | fnet_in6_addr |
IPv6 address structure. More... | |
struct | fnet_sockaddr_in6 |
IPv6 Socket address structure. More... | |
struct | fnet_sockaddr |
Socket address structure. More... | |
struct | fnet_ip_mreq |
IPv4 multicast group information. More... | |
struct | fnet_ipv6_mreq |
IPv6 multicast group information. More... | |
struct | fnet_linger |
This structure is used for the SO_LINGER option. More... | |
Macros | |
#define | FNET_HTONS(short_var) |
Macros which converts the unsigned short integer from host byte order to network byte order. More... | |
#define | FNET_NTOHS(short_var) |
Macros which converts the unsigned 16-bit integer from network byte order to host byte order. More... | |
#define | FNET_HTONL(long_var) |
Macros which converts the unsigned long integer from host byte order to network byte order. More... | |
#define | FNET_NTOHL(long_var) |
Macros which converts the unsigned long integer from network byte order to host byte order. More... | |
#define | FNET_IP4_ADDR_INIT(a, b, c, d) |
Converts the standard dotted-decimal notation a.b.c.d to an integer value, suitable for use as an Internet address (in network byte order). More... | |
#define | FNET_IP4_ADDR_STR_SIZE sizeof("255.255.255.255") |
Size of the string buffer that will contain null-terminated ASCII string of an IPv4 address in standard "." notation. More... | |
#define | FNET_IP6_ADDR_STR_SIZE sizeof("abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd") |
Size of the string buffer that will contain null-terminated ASCII string of an IPv6 address in standard ":" notation. More... | |
#define | INADDR_ANY |
It means to use any network interface. More... | |
#define | INADDR_BROADCAST |
Broadcast address. It can be used to send the broadcast UDP datagrams over an IP network. More... | |
#define | AF_UNSPEC |
Unspecified address family. More... | |
#define | AF_INET |
IPv4 address family. More... | |
#define | AF_INET6 |
IPv6 address family. More... | |
#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))) |
Bitmask of supported address families. . More... | |
#define | FNET_SA_DATA_SIZE (sizeof(struct fnet_in_addr)) |
Size of sa_data[] field of fnet_sockaddr structure. It used to cover fnet_sockaddr_in and fnet_sockaddr_in6. . More... | |
#define | FNET_IP_ADDR_STR_SIZE FNET_IP4_ADDR_STR_SIZE |
Size of the string buffer that will contain null-terminated ASCII string of an IP address. It depends on if disabled or enabled IPv6. More... | |
Typedefs | |
typedef fnet_uint32_t | fnet_ip4_addr_t |
32-bit IPv4 address type. More... | |
typedef fnet_uint16_t | fnet_address_family_t |
Address family type. More... | |
typedef fnet_uint32_t | fnet_scope_id_t |
cope zone index type, defining network interface. More... | |
typedef void * | fnet_socket_t |
Socket descriptor. More... | |
Enumerations |
Functions | |
fnet_uint16_t | fnet_htons (fnet_uint16_t short_var) |
Converts 16-bit value from host to network byte order. More... | |
fnet_uint16_t | fnet_ntohs (fnet_uint16_t short_var) |
Converts 16-bit value from network to host byte order. More... | |
fnet_uint32_t | fnet_htonl (fnet_uint32_t long_var) |
Converts 32-bit value from host to network byte order. More... | |
fnet_uint32_t | fnet_ntohl (fnet_uint32_t long_var) |
Converts 32-bit value from network to host byte order. More... | |
fnet_char_t * | fnet_inet_ntoa (struct fnet_in_addr addr, fnet_char_t *res_str) |
Converts an IPv4 address into a string in Internet standard dotted-decimal format. More... | |
fnet_return_t | fnet_inet_aton (fnet_char_t *cp, struct fnet_in_addr *addr) |
Converts the string in the standard dotted-decimal notation to an integer value, suitable for use as an IPv4 address. More... | |
fnet_char_t * | fnet_inet_ntop (fnet_address_family_t family, const void *addr, fnet_char_t *str, fnet_size_t str_len) |
Converts IPv4 or IPv6 address from binary to text form. More... | |
fnet_return_t | fnet_inet_pton (fnet_address_family_t family, const fnet_char_t *str, void *addr, fnet_size_t addr_len) |
Converts IPv4 and IPv6 addresses from text to binary form. More... | |
fnet_return_t | fnet_inet_ptos (const fnet_char_t *str, struct fnet_sockaddr *addr) |
Converts IPv4 and IPv6 addresses from text to socket-address structure. More... | |
fnet_socket_t | fnet_socket (fnet_address_family_t family, fnet_socket_type_t type, fnet_uint32_t protocol) |
Creates a socket. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
fnet_return_t | fnet_socket_shutdown (fnet_socket_t s, fnet_sd_flags_t how) |
Terminates the connection in one or both directions. More... | |
fnet_return_t | fnet_socket_close (fnet_socket_t s) |
Closes an existing socket. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
fnet_bool_t | fnet_socket_addr_are_equal (const struct fnet_sockaddr *addr1, const struct fnet_sockaddr *addr2) |
Compares socket addresses. More... | |
fnet_bool_t | fnet_socket_addr_is_unspecified (const struct fnet_sockaddr *addr) |
Determines, if socket address is unspecified. More... | |
fnet_bool_t | fnet_socket_addr_is_multicast (const struct fnet_sockaddr *addr) |
Determines, if socket address is multicast. More... | |
void | fnet_socket_set_callback_on_rx (void(*callback)(void)) |
Registers the "Socket Rx" event handler callback. More... | |
© 2005-2018 by Andrey Butok. http://fnet.sourceforge.net