Socket API#
Modules#
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 int16_t Set only No Yes SO_NONBLOCK int16_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
Specify send buffer size in payload bytes.
Specify send low water mark in payload bytes.
IPv6 socket options#
IPv6 socket options summaryopt_name Data type set/getsockopt sendmsg recvmsg IPV6_UNICAST_HOPS int16_t Set/Get Yes No IPV6_MULTICAST_HOPS int16_t Set/Get Yes No IPV6_JOIN_GROUP ns_ipv6_mreq_t Set only Yes Yes IPV6_LEAVE_GROUP ns_ipv6_mreq_t Set only Yes Yes SO_EDFE_MODE uint32_t Set only Yes No
Set the multicast hop limit for the socket.
Join a multicast group.
Leave a multicast group.
Experimental: Enable Extended Directed Frame Exchange mode.
Enumerations#
Enumerations for socket event mode.
Typedefs#
Socket address length type definition.
Socket id.
Supported address families.
Socket types.
IP protocols.
IPv6 Internet address.
IPv6 address format.
Variables#
IPv6 wildcard address.
Functions#
Creates an endpoint for communication and returns an Id that refers to that endpoint.
Close a socket.
Bind a name to a socket.
Send a message on a socket.
Send a message to a given address.
Receive messages from a socket.
Receive a message from a socket.
Accept a connection on a socket.
Initiate a connection on a socket.
Listen for connections on a socket.
Set socket option designated by optname at a given protocol level to the value pointed by optval.
Get socket option.
Convert the long host byte order to network order.
Convert the short host byte order to network order.
Convert the long network byte order to host byte order.
Convert the short network byte order to host byte order.
Convert the IPv4 and IPv6 addresses from text to binary form.
Convert IPv6 addresses from binary to text form.
Macros#
Size of an IPv6 address.
When bitwise ored with socket's type, it sets the O_NONBLOCK status flag on the opened socket file description.
Protocol levels used for socket_setsockopt. Documentation#
SOL_SOCKET#
#define SOL_SOCKETValue:
0
Socket option level.
61
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
SOL_APPLICATION#
#define SOL_APPLICATIONValue:
1
Application socket option level.
62
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
IPPROTO_IPV6#
#define IPPROTO_IPV6Value:
41
IPV6 socket option level.
63
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
application level socket options Documentation#
SO_EVENT_MODE#
#define SO_EVENT_MODEValue:
10
Specify event mode of a socket. When set, optval must point to an uint32_t.
Possible values are:
SL_WISUN_SOCKET_EVENT_MODE_INDICATION: received data is included in SL_WISUN_MSG_SOCKET_DATA_IND_ID indication
SL_WISUN_SOCKET_EVENT_MODE_POLLING: only the amount of received data is included SL_WISUN_MSG_SOCKET_DATA_AVAILABLE_IND_ID indication. recv() or recvfrom() shouldbe invoked after indication reception to retrieve data
93
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
SOCKET_EVENT_MODE#
#define SOCKET_EVENT_MODEValue:
SO_EVENT_MODE
Specify event mode of a socket. When set, optval must point to an uint32_t.
Possible values are:
SL_WISUN_SOCKET_EVENT_MODE_INDICATION: received data is included in SL_WISUN_MSG_SOCKET_DATA_IND_ID indication
SL_WISUN_SOCKET_EVENT_MODE_POLLING: only the amount of received data is included SL_WISUN_MSG_SOCKET_DATA_AVAILABLE_IND_ID indication. recv() or recvfrom() shouldbe invoked after indication reception to retrieve data
94
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
SO_NONBLOCK#
#define SO_NONBLOCKValue:
11
Enable/disable nonblocking mode.
This option takes an uint32_t value.
Possible values are:
(1) enables nonblocking mode
(0) disables nonblocking mode
102
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
socket level options Documentation#
SO_RCVBUF#
#define SO_RCVBUFValue:
1
Specify receive buffer size in payload bytes. When set, optval must point to an int32_t.
0 means unread data are dropped, unless read in data callback.
123
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
SO_SNDBUF#
#define SO_SNDBUFValue:
2
Specify send buffer size in payload bytes.
When set, optval must point to an int32_t.
Used only for stream sockets.
129
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
SO_SNDLOWAT#
#define SO_SNDLOWATValue:
4
Specify send low water mark in payload bytes.
When set, optval must point to an int32_t.
133
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
IPv6 socket options Documentation#
IPV6_UNICAST_HOPS#
#define IPV6_UNICAST_HOPSValue:
2
Set the unicast hop limit for the socket. When set, optval must point to an int16_t.
-1 in the value means use the route default, otherwise it should be between 0 and 255.
157
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
IPV6_MULTICAST_HOPS#
#define IPV6_MULTICAST_HOPSValue:
3
Set the multicast hop limit for the socket.
When set, optval must point to an int16_t.
-1 in the value means use the route default, otherwise it should be between 0 and 255.
162
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
IPV6_JOIN_GROUP#
#define IPV6_JOIN_GROUPValue:
15
Join a multicast group.
When set, optval must point to an in6_addr_t.
165
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
IPV6_LEAVE_GROUP#
#define IPV6_LEAVE_GROUPValue:
16
Leave a multicast group.
When set, optval must point to an in6_addr_t.
168
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
SO_EDFE_MODE#
#define SO_EDFE_MODEValue:
0xfb
Experimental: Enable Extended Directed Frame Exchange mode.
When set, optval must point to an uint32_t.
171
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
SOCKET_EDFE_MODE#
#define SOCKET_EDFE_MODEValue:
SO_EDFE_MODE
Set the unicast hop limit for the socket. When set, optval must point to an int16_t.
-1 in the value means use the route default, otherwise it should be between 0 and 255.
172
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
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. |
189
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
socket_domain#
socket_domain
Supported address families.
Enumerator | |
---|---|
AF_INET6 | IP version 6. |
199
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/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 |
204
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/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. |
211
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
Typedef Documentation#
socklen_t#
typedef uint32_t socklen_t
Socket address length type definition.
183
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
sl_wisun_socket_id_t#
typedef int32_t sl_wisun_socket_id_t
Socket id.
186
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
sl_socket_domain_t#
typedef enum socket_domain sl_socket_domain_t
Supported address families.
201
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
sl_socket_type_t#
typedef enum socket_type sl_socket_type_t
Socket types.
208
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
sl_socket_protocol_t#
typedef enum socket_protocol sl_socket_protocol_t
IP protocols.
216
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
in6_addr_t#
typedef struct in6_addr in6_addr_t
IPv6 Internet address.
227
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
sockaddr_in6_t#
typedef struct sockaddr_in6 sockaddr_in6_t
IPv6 address format.
239
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
Variable Documentation#
in6addr_any#
const in6_addr_t in6addr_any
IPv6 wildcard address.
230
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
Function Documentation#
socket#
int32_t socket (int32_t domain, int32_t type, int32_t protocol)
Creates 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.
261
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
close#
int32_t close (int32_t 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.
277
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
bind#
int32_t bind (int32_t 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.
291
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
send#
int32_t send (int32_t sockid, const void * buff, uint32_t len, int32_t 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).
304
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
sendto#
int32_t sendto (int32_t sockid, const void * buff, uint32_t len, int32_t 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).
319
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
recvfrom#
int32_t recvfrom (int32_t sockid, void * buf, uint32_t len, int32_t 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.
337
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
recv#
int32_t recv (int32_t sockid, void * buf, uint32_t len, int32_t 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)
352
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
accept#
int32_t accept (int32_t 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.
372
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
connect#
int32_t connect (int32_t 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.
388
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
listen#
int32_t listen (int32_t sockid, int32_t 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.
402
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
setsockopt#
int32_t setsockopt (int32_t sockid, int32_t level, int32_t 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.
436
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
getsockopt#
int32_t getsockopt (int32_t sockid, int32_t level, int32_t 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.
459
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
htonl#
__STATIC_INLINE uint32_t htonl (uint32_t hostlong)
Convert the long host byte order to network order.
[in] | hostlong | Long host integer |
Returns
Long network integer
This function converts the unsigned integer hostlong from host byte order to network byte order. For Wi-SUN, the conversion is not needed. Dummy implementation
471
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
htons#
__STATIC_INLINE uint16_t htons (uint16_t hostshort)
Convert the short host byte order to network order.
[in] | hostshort | Short host integer |
Returns
Short network integer
This function converts the unsigned short integer hostshort from host byte order to network byte order. For Wi-SUN, the conversion is not needed. Dummy implementation
485
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
ntohl#
__STATIC_INLINE uint32_t ntohl (uint32_t netlong)
Convert the long network byte order to host byte order.
[in] | netlong | Long network integer |
Returns
Long host integer
This function converts the unsigned integer netlong from network byte order to host byte order. For Wi-SUN, the conversion is not needed. Dummy implementation
499
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
ntohs#
__STATIC_INLINE uint16_t ntohs (uint16_t netshort)
Convert the short network byte order to host byte order.
[in] | netshort |
Returns
Short host integer
This function converts the unsigned short integer netshort from the network byte order to host byte order.For Wi-SUN, the conversion is not needed. Dummy implementation.
514
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
inet_pton#
int32_t inet_pton (int32_t af, const char * src, void * dst)
Convert the IPv4 and IPv6 addresses from text to binary form.
[in] | af | The address family. Only AF_INET6 is supported by our implementation. |
[in] | src | Source string |
[out] | dst | Destination address pointer |
Returns
1 on succes, -1 if an error occurred. (POSIX described the 0 value too)
This function converts the character string src into a network address structure in the af address family, then copies the network address structure to dst. AF_INET (IPv4) case not supported.
531
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
inet_ntop#
const char * inet_ntop (int32_t af, const void * src, char * dst, socklen_t size)
Convert IPv6 addresses from binary to text form.
[in] | af | - Address family.
|
[in] | src | Source address in byte form |
[out] | dst | Destination buffer ptr |
[in] | size | Size of the destination buffer. |
Returns
It returns a non-null pointer to dst. NULL if an error occurred.
Converts the network address structure src in the af address family into a character string. The resulting string is copied to the buffer pointed to by dst, which must be a non-null pointer. The caller specifies the number of bytes available in this buffer in the argument size. AF_INET (IPv4) case not supported.
549
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
Macro Definition Documentation#
APP_LEVEL_SOCKET#
#define APP_LEVEL_SOCKETValue:
SOL_APPLICATION
67
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
IPV6_ADDR_SIZE#
#define IPV6_ADDR_SIZEValue:
16
Size of an IPv6 address.
176
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h
SOCK_NONBLOCK#
#define SOCK_NONBLOCKValue:
0X00010000
When bitwise ored with socket's type, it sets the O_NONBLOCK status flag on the opened socket file description.
180
of file /mnt/raid/workspaces/ws.3mvRcZlJ0/overlay/gsdk/protocol/wisun/stack/inc/socket/socket.h