Embedded TCP/IP stack  3.9.3
Sockets API

CPU-specific library API. More...

Detailed Description

CPU-specific library API.

Socket API.

IPv6 protocol API.

IPv4 protocol API.

Address-conversion functions API.

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:

Socket functions
CategoryFNET RoutineBSD RoutineMeaningServer ClientSOCK_STREAM SOCK_DGRAM
setupfnet_socket()socket()Creates a new unnamed socket within a specified communication domain family.XXX X
setupfnet_socket_bind()bind()Assigns a local address to a socket.XXXX
serverfnet_socket_listen()listen()Prepares a socket to accept the incoming connections.X
X
serverfnet_socket_accept()accept()Accepts the connections. X
X
clientfnet_socket_connect()connect()Establishes a connection to a foreign socket.
XXX
inputfnet_socket_recv()recv()Receives the data.X XXX
inputfnet_socket_recvfrom()recvfrom()Receives the data and address of the sender.XX
X
outputfnet_socket_send()send()Sends the data.X XXX
outputfnet_socket_sendto()sendto()Sends the data to a specified address.XX
X
terminationfnet_socket_shutdown()shutdown()Terminates a connection in one or both directions.XXXX
terminationfnet_socket_close()closesocket()Terminates a connection and releases the socket.XXXX
administrationfnet_socket_setopt()fnet_socket_setopt()Sets socket or protocol options.XXXX
administrationfnet_socket_getopt()getsockopt()Gets socket or protocol options.XXXX
administrationfnet_socket_getname()getsockname()Gets a local address assigned to a socket.XXXX
administrationfnet_socket_getpeername()getpeername()Gets a foreign address assigned to a socket.XXXX

Configuration parameters:

Data Structures

union  fnet_ip6_addr_t
 128-bit IPv6 address type. More...
 
struct  in_addr
 IPv4 address structure. More...
 
struct  sockaddr_in
 IPv4 Socket address structure. More...
 
struct  in6_addr
 IPv6 address structure. More...
 
struct  sockaddr_in6
 IPv6 Socket address structure. More...
 
struct  sockaddr
 Socket address structure. More...
 
struct  ip_mreq
 IPv4 multicast group information. More...
 
struct  ipv6_mreq
 IPv6 multicast group information. More...
 
struct  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 in_addr))
 Size of sa_data[] field of sockaddr structure.
It used to cover sockaddr_in and 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_tfnet_inet_ntoa (struct 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 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_tfnet_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 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 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 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 sockaddr *name, fnet_size_t namelen)
 Establishes a connection with the specified socket. More...
 
fnet_int32_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_int32_t fnet_socket_recvfrom (fnet_socket_t s, void *buf, fnet_size_t len, fnet_flag_t flags, struct sockaddr *from, fnet_size_t *fromlen)
 Receives the data and captures the address, from which the data was sent. More...
 
fnet_int32_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_int32_t fnet_socket_sendto (fnet_socket_t s, const void *buf, fnet_size_t len, fnet_flag_t flags, const struct 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 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 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 sockaddr *addr1, const struct sockaddr *addr2)
 Compares socket addresses. More...
 
fnet_bool_t fnet_socket_addr_is_unspecified (const struct sockaddr *addr)
 Determines, if socket address is unspecified. More...
 
fnet_bool_t fnet_socket_addr_is_multicast (const struct 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-2017 by Andrey Butok. http://fnet.sourceforge.net