Socket API#
Modules#
Ancillary data object information MACROS#
Returns the length of the data with the required alignment.
Returns the number of bytes an ancillary element with payload of the passed data length occupies.
Returns the value to store in the cmsg_len member of the cmsghdr structure.
Returns a pointer to the first control message header in the given msghdr structure.
Returns a pointer to the next control message header in the ancillary data buffer.
Returns a pointer to the data portion of a cmsghdr.
Flags we can use with recv(), recvfrom() and recvmsg()#
Normal data truncated, to be used as msg_flags field in the msghdr structure.
Control data truncated, to be used as msg_flags field in the msghdr structure.
Leave received data in queue, to be used as the flags parameter.
Protocol levels used for socket_setsockopt.#
Socket option level.
Application socket option level.
IPV6 socket option level.
application level socket options#
application level socket options summaryopt_name data type set/get sendmsg recvmsg SO_EVENT_MODE uint32_t Set only No Yes SO_NONBLOCK uint32_t Set only Yes Yes
Enable/disable nonblocking mode.
socket level options#
socket level options summaryopt_name data type set/get sendmsg recvmsg SO_RCVBUF int32_t Set/Get No Yes SO_SNDBUF int32_t Set/Get Yes No SO_SNDLOWAT int32_t Set/Get Yes No SO_WRITABLE int32_t Get No No SO_READABLE int32_t Get No No
Specify send buffer size in payload bytes.
Specify send low water mark in payload bytes.
Non-standard POSIX option SO_WRITABLE.
Non-standard POSIX option SO_READABLE.
Socket DSCP (Differentiated Services Code Point) QoS supported levels.#
Standard priority and it is socket default.
Application high priority service: Stack priorities these messages over the default priority messages.
Expedited Forwarding (EF) QoS level enable high priority state: low loss, low delay, and low jitter services.
IPv6 socket options#
IPv6 socket options summaryopt_name Data type set/getsockopt sendmsg recvmsg IPV6_TCLASS int Set/Get Yes No IPV6_UNICAST_HOPS int Set/Get No No IPV6_MULTICAST_HOPS int Set/Get No No IPV6_USE_MIN_MTU int Set/Get Yes No IPV6_HOPLIMIT int None Yes Yes IPV6_RECVHOPLIMIT int Set/Get No No IPV6_MULTICAST_LOOP int Set/Get Yes No IPV6_JOIN_GROUP ipv6_mreq_t Set only No No IPV6_ADD_MEMBERSHIP ipv6_mreq_t Set only No No IPV6_LEAVE_GROUP ipv6_mreq_t Set only No No IPV6_DROP_MEMBERSHIP ipv6_mreq_t Set only No No IPV6_PKTINFO in6_pktinfo_t None Yes Yes IPV6_RCVPKTINFO int Set/Get No No IPV6_RECVTCLASS int Set/Get No No IPV6_DONTFRAG int Set/Get Yes No SO_EDFE_MODE int32_t Set only Yes No
IPv6 header has a field traffic class that contains a 6-bit Differentiated Services Code Point (DSCP) field that is used for packet classification.
Set the unicast hop limit for the socket, as int.
Set the multicast hop limit for the socket, as int.
Specify PMTU preference, as int; Valid values -1 (PMTUD for unicast, default), 0 (PMTUD always), 1 (PMTUD off).
Ancillary data option on sendmsg()/recvmsg(), value to be used for single ongoing packet, as int; Valid values 0-255, -1 for default.
Ancillary data option on recvmsg(), specifies hop-limit for the single received ongoing packet, as int; A nonzero value enables the option; a value of 0 disables the option.
Specify whether outgoing multicast packets are looped back, as int.
Join a multicast group.
IPv6 header has a field traffic class that contains a 6-bit Differentiated Services Code Point (DSCP) field that is used for packet classification.
Leave a multicast group.
IPv6 header has a field traffic class that contains a 6-bit Differentiated Services Code Point (DSCP) field that is used for packet classification.
Specify control messages packet info for recvmsg() as struct in6_pktinfo.
Set delivery of the IPV6_PKTINFO control message on incoming datagrams, as int.
Enables the application to receive the value of the traffic class field from the IPv6 header, as int; A nonzero value enables the option; a value of 0 disables the option.
Specify not to fragment datagrams, as int; For Wi-SUN, direct neighbors can receive frames up to 1504 bytes, while the other nodes can receive frames up to 1280 bytes.
Experimental: Enable Extended Directed Frame Exchange mode.
IPv6 header has a field traffic class that contains a 6-bit Differentiated Services Code Point (DSCP) field that is used for packet classification.
Enumerations#
Enumerations for socket event mode.
Typedefs#
IPv6 Internet address.
Structure to store the IPv6 packet information.
Structure to store the IPv6 MTU (Maximum Transmission Unit) information.
Structure to specify the multicast group and the interface.
Address family.
Supported address families.
IP protocols.
Socket types.
Socket id.
IPv6 address format.
Socket address length type definition.
Variables#
IPv6 wildcard address.
Functions#
Accept a connection on a socket.
Bind a name to a socket.
Close a socket.
Initiate a connection on a socket.
Get the address of the peer connected to the socket.
Retrieves the local address of a socket.
Get socket option.
Listen for connections on a socket.
Receive a message from a socket.
Receive messages from a socket.
Receive a message from a socket.
Send a message on a socket.
Send a message through a connection-mode or connectionless-mode socket.
Send a message to a given address.
Set socket option designated by optname at a given protocol level to the value pointed by optval.
Create an endpoint for communication and returns an Id that refers to that endpoint.
Macros#
For backward compatibility.
Size of an IPv6 address.
Size of 64 bit IPv6 prefix byte array.
When bitwise ored with socket's type, it sets the O_NONBLOCK status flag on the opened socket file description.
Ancillary data object information MACROS Documentation#
Flags we can use with recv(), recvfrom() and recvmsg() Documentation#
Protocol levels used for socket_setsockopt. Documentation#
application level socket options Documentation#
socket level options Documentation#
Socket DSCP (Differentiated Services Code Point) QoS supported levels. Documentation#
IPv6 socket options Documentation#
Enumeration Documentation#
sl_wisun_socket_event_mode_t#
sl_wisun_socket_event_mode_t
Enumerations for socket event mode.
Enumerator | |
---|---|
SL_WISUN_SOCKET_EVENT_MODE_INDICATION | SL_WISUN_MSG_SOCKET_DATA_IND_ID is sent to the app with the packet contained in the indication. |
SL_WISUN_SOCKET_EVENT_MODE_POLLING | SL_WISUN_MSG_SOCKET_DATA_AVAILABLE_IND_ID is sent to the app indicating the amount of data received recv() or recvfrom() should be invoked after indication reception to retrieve data This is the default socket event mode option. |
349
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
socket_domain#
socket_domain
Supported address families.
Enumerator | |
---|---|
AF_INET6 | IP version 6. |
359
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
socket_protocol#
socket_protocol
IP protocols.
Enumerator | |
---|---|
IPPROTO_IP | Dummy protocol. |
IPPROTO_ICMP | Internet Control Message Protocol. |
IPPROTO_TCP | Transmission Control Protocol. |
IPPROTO_UDP | User Datagram Protocol. |
371
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
socket_type#
socket_type
Socket types.
Enumerator | |
---|---|
SOCK_STREAM | stream (connection) socket (TCP) |
SOCK_DGRAM | datagram (connectionless) socket (UDP) |
SOCK_RAW | raw socket |
364
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
Typedef Documentation#
cmsghdr_t#
typedef struct cmsghdr cmsghdr_t
Control messages.
417
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
in6_addr_t#
typedef struct in6_addr in6_addr_t
IPv6 Internet address.
387
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
in6_pktinfo_t#
typedef struct in6_pktinfo in6_pktinfo_t
Structure to store the IPv6 packet information.
423
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
iovec_t#
typedef struct iovec iovec_t
Structure to store scatter/gather array elements.
429
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
ip6_mtuinfo_t#
typedef struct ip6_mtuinfo ip6_mtuinfo_t
Structure to store the IPv6 MTU (Maximum Transmission Unit) information.
437
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
ipv6_mreq_t#
typedef struct ipv6_mreq ipv6_mreq_t
Structure to specify the multicast group and the interface.
445
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
msghdr_t#
typedef struct msghdr msghdr_t
The msghdr structure is used by the recvmsg() and sendmsg() functions.
410
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
sa_family_t#
typedef uint32_t sa_family_t
Address family.
343
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
sl_socket_domain_t#
typedef enum socket_domain sl_socket_domain_t
Supported address families.
361
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
sl_socket_protocol_t#
typedef enum socket_protocol sl_socket_protocol_t
IP protocols.
376
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
sl_socket_type_t#
typedef enum socket_type sl_socket_type_t
Socket types.
368
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
sl_wisun_socket_id_t#
typedef int sl_wisun_socket_id_t
Socket id.
346
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
sockaddr_in6_t#
typedef struct sockaddr_in6 sockaddr_in6_t
IPv6 address format.
399
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
socklen_t#
typedef uint32_t socklen_t
Socket address length type definition.
340
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
Variable Documentation#
in6addr_any#
const in6_addr_t in6addr_any
IPv6 wildcard address.
390
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
Function Documentation#
accept#
int accept (int sockid, struct sockaddr * addr, socklen_t * addrlen)
Accept a connection on a socket.
[in] | sockid | socket descriptor |
[inout] | addr | A pointer to sockaddr structure filled in with the address of the peer (remote) socket. When addr is NULL, nothing is filled in; in this case, addrlen is not used, and should also be NULL. |
[inout] | addrlen | The caller must initialize it to contain the size (in bytes) of the structure pointed to by addr. On return it will contain the actual size of the peer address. |
Returns
The socket id of the accepted socket on success, -1 if an error occurred.
Used with connection-based socket types (TCP). It extracts the first connection request on the queue of pending connections for the listening socket.
603
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
bind#
int bind (int sockid, const struct sockaddr * addr, socklen_t addrlen)
Bind a name to a socket.
[in] | sockid | socket id |
[in] | addr | address structure ptr |
[in] | addrlen | address structure size |
Returns
0 on success, -1 on failure.
Assigns the address to the socket, referred to by the socket ID, as specified by addr. It is normally necessary to assign a local address using bind() before a SOCK_STREAM socket may receive connections.
496
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
close#
int close (int sockid)
Close a socket.
[in] | sockid | socket id |
Returns
0 on success, -1 on failure.
Close a socket and remove from the socket handler storage.
482
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
connect#
int connect (int sockid, const struct sockaddr * addr, socklen_t addrlen)
Initiate a connection on a socket.
[in] | sockid | socket descriptor. |
[in] | addr | If the socket sockid is of type SOCK_DGRAM, addr is the address to which datagrams are sent by default and the only address from which datagrams are received. If the socket is of type SOCK_STREAM, this call attempts to make a connection to the socket that is bound to the address specified by addr. |
[in] | addrlen | length of the supplied sockaddr structure. |
Returns
0 on connection or binding success, -1 if an error occurred.
Connects the socket referred to by the sockid to the address specified by address.
619
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
getpeername#
int getpeername (int socket, struct sockaddr *restrict address, socklen_t *restrict address_len)
Get the address of the peer connected to the socket.
[in] | socket | The socket file descriptor. |
[out] | address | A pointer to a sockaddr structure where the peer's address will be stored. |
[inout] | address_len | A pointer to a socklen_t variable that specifies the size of the 'address' structure. |
This function retrieves the address of the peer connected to the specified socket. The peer's address is stored in the provided 'address' structure, and the length of the address is stored in 'address_len'.
Returns
0 on success, -1 on failure and sets
errno
appropriately.
726
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
getsockname#
int getsockname (int socket, struct sockaddr *restrict address, socklen_t *restrict address_len)
Retrieves the local address of a socket.
[in] | socket | The socket descriptor. |
[out] | address | A pointer to a |
[inout] | address_len | A pointer to a |
Returns
On success, returns zero. On failure, returns -1 and sets
errno
appropriately.
This function retrieves the local address associated with a socket. It populates the provided address
structure with the local address information.
709
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
getsockopt#
int getsockopt (int sockid, int level, int optname, void * optval, socklen_t * optlen)
Get socket option.
[in] | sockid | socket descriptor. |
[in] | level | socket protocol level. |
[in] | optname | Option name. Supported options:
|
[out] | optval | option value structure pointer. |
[in] | optlen | size of the option value structure. |
Returns
0 on success, -1 if an error occurred.
The function gets socket option by optname, and copies option data to optval ptr.
690
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
listen#
int listen (int sockid, int backlog)
Listen for connections on a socket.
[in] | sockid | socket id |
[in] | backlog | Argument defines the maximum length to which the queue of pending connections for sockid may grow. Not implemented for Wi-SUN, the connection queue size is always 1 |
Returns
0 on success, -1 if an error occurred.
Marks the socket referred to by sockid as a passive socket, that is, as a socket that will be used to accept incoming connection requests using accept.
633
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
recv#
ssize_t recv (int sockid, void * buf, size_t len, int flags)
Receive a message from a socket.
[in] | sockid | descriptor of socket to receive the message from. |
[out] | buf | pointer to destination data buffer. |
[in] | len | length of destination data buffer. |
[in] | flags | flags to select type of message reception. Ignored in our implementation. |
Returns
The number of bytes received on success, -1 if an error occurred.
Should be used for connection-oriented protocol (TCP)
569
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
recvfrom#
ssize_t recvfrom (int sockid, void * buf, size_t len, int flags, struct sockaddr * src_addr, socklen_t * addrlen)
Receive messages from a socket.
[in] | sockid | descriptor of socket to receive the message from. |
[out] | buf | pointer to destination data buffer. |
[in] | len | length of destination data buffer. |
[in] | flags | flags to select type of message reception. Ignored in our implementation. |
[in] | src_addr | pointer to a sockaddr structure in which the sending address is to be stored. |
[in] | addrlen | length of the supplied sockaddr structure. |
Returns
The number of bytes received on success, -1 if an error occurred.
Receives data on a socket whether or not it is connection-oriented.
554
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
recvmsg#
ssize_t recvmsg (int socket, struct msghdr * message, int flags)
Receive a message from a socket.
[in] | socket | Specifies the socket file descriptor. |
[inout] | message | Points to a msghdr structure, containing both the buffer to store the source address and the buffers for the incoming message. |
[in] | flags | Specifies the type of message reception. |
Returns
The number of bytes received on success, -1 if an error occurred.
This function is typically used with connectionless-mode sockets because it permits the application to retrieve the source address of received data.
584
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
send#
ssize_t send (int sockid, const void * buff, size_t len, int flags)
Send a message on a socket.
[in] | sockid | socket descriptor. |
[in] | buff | pointer to data buffer to send. |
[in] | len | length of data buffer to send. |
[in] | flags | flags to select send options. Ignored in our implementation. |
Returns
The number of bytes sent on success, -1 if an error occurred.
Preferred with connection-oriented sockets (TCP).
509
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
sendmsg#
ssize_t sendmsg (int socket, const struct msghdr * message, int flags)
Send a message through a connection-mode or connectionless-mode socket.
[in] | socket | Specifies the socket file descriptor. |
[in] | message | Points to a msghdr structure, containing both the destination address and the buffers for the outgoing message. |
[in] | flags | Specifies the type of message transmission. |
Returns
The number of bytes received on success, -1 if an error occurred.
537
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
sendto#
ssize_t sendto (int sockid, const void * buff, size_t len, int flags, const struct sockaddr * dest_addr, socklen_t addr_len)
Send a message to a given address.
[in] | sockid | socket descriptor. |
[in] | buff | pointer to data buffer to send. |
[in] | len | length of data buffer to send. |
[in] | flags | flags to select send options. Ignored in our implementation. |
[in] | dest_addr | pointer to destination address buffer; Required for datagram sockets. |
[in] | addr_len | length of destination address buffer. |
Returns
The number of bytes sent on success, -1 if an error occurred.
Preferred in datagram mode (UDP).
524
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
setsockopt#
int setsockopt (int sockid, int level, int optname, const void * optval, socklen_t optlen)
Set socket option designated by optname at a given protocol level to the value pointed by optval.
[in] | sockid | socket ID |
[in] | level | protocol level at which the option resides. it could be: |
[in] | optname | option name. it could be: |
[in] | optval | Pointer to the socket option new value. The type of variable pointed by optval depends level and optname values. |
[in] | optlen | Must be the size of the symbol pointed by optval. |
Returns
0 on success, -1 if an error occurred.
This function can set socket properties.
667
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
socket#
int socket (int domain, int type, int protocol)
Create an endpoint for communication and returns an Id that refers to that endpoint.
[in] | domain | Specifies a communication domain. It selects the protocol family which will be used for communication. Must be set to AF_INET6 (IPv6 network socket) |
[in] | type | The communication semantics It can be:
|
[in] | protocol | Specifies the particular protocol to be used. It can be:
|
Returns
The socket's id on success, (-1) on failure.
466
of file /mnt/raid/workspaces/ws.9FtfRPWpI/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h