Zephyr Project API 3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
BSD Sockets compatible API

BSD Sockets compatible API. More...

Modules

 Socket options for TLS
 

Data Structures

struct  zsock_addrinfo
 Definition used when querying address information. More...
 
struct  ifreq
 Interface description structure. More...
 
struct  in_pktinfo
 Incoming IPv4 packet information. More...
 
struct  ip_mreqn
 Struct used when joining or leaving a IPv4 multicast group. More...
 
struct  ipv6_mreq
 Struct used when joining or leaving a IPv6 multicast group. More...
 
struct  in6_pktinfo
 Incoming IPv6 packet information. More...
 
struct  zsock_pollfd
 Definition of the monitored socket/file descriptor. More...
 
struct  zsock_fd_set
 Socket file descriptor set. More...
 

Macros

#define ZSOCK_FD_SETSIZE   (sizeof(((zsock_fd_set *)0)->bitset) * 8)
 Number of file descriptors which can be added to zsock_fd_set.
 

Typedefs

typedef struct zsock_fd_set zsock_fd_set
 Socket file descriptor set.
 

Functions

void * zsock_get_context_object (int sock)
 Obtain a file descriptor's associated net context.
 
int zsock_socket (int family, int type, int proto)
 Create a network socket.
 
int zsock_socketpair (int family, int type, int proto, int *sv)
 Create an unnamed pair of connected sockets.
 
int zsock_close (int sock)
 Close a network socket.
 
int zsock_shutdown (int sock, int how)
 Shutdown socket send/receive operations.
 
int zsock_bind (int sock, const struct sockaddr *addr, socklen_t addrlen)
 Bind a socket to a local network address.
 
int zsock_connect (int sock, const struct sockaddr *addr, socklen_t addrlen)
 Connect a socket to a peer network address.
 
int zsock_listen (int sock, int backlog)
 Set up a STREAM socket to accept peer connections.
 
int zsock_accept (int sock, struct sockaddr *addr, socklen_t *addrlen)
 Accept a connection on listening socket.
 
ssize_t zsock_sendto (int sock, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen)
 Send data to an arbitrary network address.
 
static ssize_t zsock_send (int sock, const void *buf, size_t len, int flags)
 Send data to a connected peer.
 
ssize_t zsock_sendmsg (int sock, const struct msghdr *msg, int flags)
 Send data to an arbitrary network address.
 
ssize_t zsock_recvfrom (int sock, void *buf, size_t max_len, int flags, struct sockaddr *src_addr, socklen_t *addrlen)
 Receive data from an arbitrary network address.
 
ssize_t zsock_recvmsg (int sock, struct msghdr *msg, int flags)
 Receive a message from an arbitrary network address.
 
static ssize_t zsock_recv (int sock, void *buf, size_t max_len, int flags)
 Receive data from a connected peer.
 
int zsock_fcntl_impl (int sock, int cmd, int flags)
 Control blocking/non-blocking mode of a socket.
 
int zsock_ioctl_impl (int sock, unsigned long request, va_list ap)
 Control underlying socket parameters.
 
int zsock_poll (struct zsock_pollfd *fds, int nfds, int timeout)
 Efficiently poll multiple sockets for events.
 
int zsock_getsockopt (int sock, int level, int optname, void *optval, socklen_t *optlen)
 Get various socket options.
 
int zsock_setsockopt (int sock, int level, int optname, const void *optval, socklen_t optlen)
 Set various socket options.
 
int zsock_getpeername (int sock, struct sockaddr *addr, socklen_t *addrlen)
 Get peer name.
 
int zsock_getsockname (int sock, struct sockaddr *addr, socklen_t *addrlen)
 Get socket name.
 
int zsock_gethostname (char *buf, size_t len)
 Get local host name.
 
static char * zsock_inet_ntop (sa_family_t family, const void *src, char *dst, size_t size)
 Convert network address from internal to numeric ASCII form.
 
int zsock_inet_pton (sa_family_t family, const char *src, void *dst)
 Convert network address from numeric ASCII form to internal representation.
 
int zsock_getaddrinfo (const char *host, const char *service, const struct zsock_addrinfo *hints, struct zsock_addrinfo **res)
 Resolve a domain name to one or more network addresses.
 
void zsock_freeaddrinfo (struct zsock_addrinfo *ai)
 Free results returned by zsock_getaddrinfo()
 
const char * zsock_gai_strerror (int errcode)
 Convert zsock_getaddrinfo() error code to textual message.
 
int zsock_getnameinfo (const struct sockaddr *addr, socklen_t addrlen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, int flags)
 Resolve a network address to a domain name or ASCII address.
 
int zsock_select (int nfds, zsock_fd_set *readfds, zsock_fd_set *writefds, zsock_fd_set *exceptfds, struct zsock_timeval *timeout)
 Legacy function to poll multiple sockets for events.
 
void ZSOCK_FD_ZERO (zsock_fd_set *set)
 Initialize (clear) fd_set.
 
int ZSOCK_FD_ISSET (int fd, zsock_fd_set *set)
 Check whether socket is a member of fd_set.
 
void ZSOCK_FD_CLR (int fd, zsock_fd_set *set)
 Remove socket from fd_set.
 
void ZSOCK_FD_SET (int fd, zsock_fd_set *set)
 Add socket to fd_set.
 

Socket APIs available if CONFIG_NET_SOCKETS_POSIX_NAMES is enabled

static int socket (int family, int type, int proto)
 POSIX wrapper for zsock_socket.
 
static int socketpair (int family, int type, int proto, int sv[2])
 POSIX wrapper for zsock_socketpair.
 
static int close (int sock)
 POSIX wrapper for zsock_close.
 
static int shutdown (int sock, int how)
 POSIX wrapper for zsock_shutdown.
 
static int bind (int sock, const struct sockaddr *addr, socklen_t addrlen)
 POSIX wrapper for zsock_bind.
 
static int connect (int sock, const struct sockaddr *addr, socklen_t addrlen)
 POSIX wrapper for zsock_connect.
 
static int listen (int sock, int backlog)
 POSIX wrapper for zsock_listen.
 
static int accept (int sock, struct sockaddr *addr, socklen_t *addrlen)
 POSIX wrapper for zsock_accept.
 
static ssize_t send (int sock, const void *buf, size_t len, int flags)
 POSIX wrapper for zsock_send.
 
static ssize_t recv (int sock, void *buf, size_t max_len, int flags)
 POSIX wrapper for zsock_recv.
 
static ssize_t sendto (int sock, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen)
 POSIX wrapper for zsock_sendto.
 
static ssize_t sendmsg (int sock, const struct msghdr *message, int flags)
 POSIX wrapper for zsock_sendmsg.
 
static ssize_t recvfrom (int sock, void *buf, size_t max_len, int flags, struct sockaddr *src_addr, socklen_t *addrlen)
 POSIX wrapper for zsock_recvfrom.
 
static ssize_t recvmsg (int sock, struct msghdr *msg, int flags)
 POSIX wrapper for zsock_recvmsg.
 
static int poll (struct zsock_pollfd *fds, int nfds, int timeout)
 POSIX wrapper for zsock_poll.
 
static int getsockopt (int sock, int level, int optname, void *optval, socklen_t *optlen)
 POSIX wrapper for zsock_getsockopt.
 
static int setsockopt (int sock, int level, int optname, const void *optval, socklen_t optlen)
 POSIX wrapper for zsock_setsockopt.
 
static int getpeername (int sock, struct sockaddr *addr, socklen_t *addrlen)
 POSIX wrapper for zsock_getpeername.
 
static int getsockname (int sock, struct sockaddr *addr, socklen_t *addrlen)
 POSIX wrapper for zsock_getsockname.
 
static int getaddrinfo (const char *host, const char *service, const struct zsock_addrinfo *hints, struct zsock_addrinfo **res)
 POSIX wrapper for zsock_getaddrinfo.
 
static void freeaddrinfo (struct zsock_addrinfo *ai)
 POSIX wrapper for zsock_freeaddrinfo.
 
static const char * gai_strerror (int errcode)
 POSIX wrapper for zsock_gai_strerror.
 
static int getnameinfo (const struct sockaddr *addr, socklen_t addrlen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, int flags)
 POSIX wrapper for zsock_getnameinfo.
 
static int gethostname (char *buf, size_t len)
 POSIX wrapper for zsock_gethostname.
 
static int inet_pton (sa_family_t family, const char *src, void *dst)
 POSIX wrapper for zsock_inet_pton.
 
static char * inet_ntop (sa_family_t family, const void *src, char *dst, size_t size)
 POSIX wrapper for zsock_inet_ntop.
 
#define pollfd   zsock_pollfd
 POSIX wrapper for zsock_pollfd.
 
#define addrinfo   zsock_addrinfo
 POSIX wrapper for zsock_addrinfo.
 
#define POLLIN   ZSOCK_POLLIN
 POSIX wrapper for ZSOCK_POLLIN.
 
#define POLLOUT   ZSOCK_POLLOUT
 POSIX wrapper for ZSOCK_POLLOUT.
 
#define POLLERR   ZSOCK_POLLERR
 POSIX wrapper for ZSOCK_POLLERR.
 
#define POLLHUP   ZSOCK_POLLHUP
 POSIX wrapper for ZSOCK_POLLHUP.
 
#define POLLNVAL   ZSOCK_POLLNVAL
 POSIX wrapper for ZSOCK_POLLNVAL.
 
#define MSG_PEEK   ZSOCK_MSG_PEEK
 POSIX wrapper for ZSOCK_MSG_PEEK.
 
#define MSG_CTRUNC   ZSOCK_MSG_CTRUNC
 POSIX wrapper for ZSOCK_MSG_CTRUNC.
 
#define MSG_TRUNC   ZSOCK_MSG_TRUNC
 POSIX wrapper for ZSOCK_MSG_TRUNC.
 
#define MSG_DONTWAIT   ZSOCK_MSG_DONTWAIT
 POSIX wrapper for ZSOCK_MSG_DONTWAIT.
 
#define MSG_WAITALL   ZSOCK_MSG_WAITALL
 POSIX wrapper for ZSOCK_MSG_WAITALL.
 
#define SHUT_RD   ZSOCK_SHUT_RD
 POSIX wrapper for ZSOCK_SHUT_RD.
 
#define SHUT_WR   ZSOCK_SHUT_WR
 POSIX wrapper for ZSOCK_SHUT_WR.
 
#define SHUT_RDWR   ZSOCK_SHUT_RDWR
 POSIX wrapper for ZSOCK_SHUT_RDWR.
 
#define EAI_BADFLAGS   DNS_EAI_BADFLAGS
 POSIX wrapper for DNS_EAI_BADFLAGS.
 
#define EAI_NONAME   DNS_EAI_NONAME
 POSIX wrapper for DNS_EAI_NONAME.
 
#define EAI_AGAIN   DNS_EAI_AGAIN
 POSIX wrapper for DNS_EAI_AGAIN.
 
#define EAI_FAIL   DNS_EAI_FAIL
 POSIX wrapper for DNS_EAI_FAIL.
 
#define EAI_NODATA   DNS_EAI_NODATA
 POSIX wrapper for DNS_EAI_NODATA.
 
#define EAI_MEMORY   DNS_EAI_MEMORY
 POSIX wrapper for DNS_EAI_MEMORY.
 
#define EAI_SYSTEM   DNS_EAI_SYSTEM
 POSIX wrapper for DNS_EAI_SYSTEM.
 
#define EAI_SERVICE   DNS_EAI_SERVICE
 POSIX wrapper for DNS_EAI_SERVICE.
 
#define EAI_SOCKTYPE   DNS_EAI_SOCKTYPE
 POSIX wrapper for DNS_EAI_SOCKTYPE.
 
#define EAI_FAMILY   DNS_EAI_FAMILY
 POSIX wrapper for DNS_EAI_FAMILY.
 

Options for poll()

#define ZSOCK_POLLIN   1
 zsock_poll: Poll for readability
 
#define ZSOCK_POLLPRI   2
 zsock_poll: Poll for exceptional condition
 
#define ZSOCK_POLLOUT   4
 zsock_poll: Poll for writability
 
#define ZSOCK_POLLERR   8
 zsock_poll: Poll results in error condition (output value only)
 
#define ZSOCK_POLLHUP   0x10
 zsock_poll: Poll detected closed connection (output value only)
 
#define ZSOCK_POLLNVAL   0x20
 zsock_poll: Invalid socket (output value only)
 

Options for sending and receiving data

#define ZSOCK_MSG_PEEK   0x02
 zsock_recv: Read data without removing it from socket input queue
 
#define ZSOCK_MSG_CTRUNC   0x08
 zsock_recvmsg: Control data buffer too small.
 
#define ZSOCK_MSG_TRUNC   0x20
 zsock_recv: return the real length of the datagram, even when it was longer than the passed buffer
 
#define ZSOCK_MSG_DONTWAIT   0x40
 zsock_recv/zsock_send: Override operation to non-blocking
 
#define ZSOCK_MSG_WAITALL   0x100
 zsock_recv: block until the full amount of data can be returned
 

Options for shutdown() function

#define ZSOCK_SHUT_RD   0
 zsock_shutdown: Shut down for reading
 
#define ZSOCK_SHUT_WR   1
 zsock_shutdown: Shut down for writing
 
#define ZSOCK_SHUT_RDWR   2
 zsock_shutdown: Shut down for both reading and writing
 

Flags for getaddrinfo() hints

#define AI_PASSIVE   0x1
 Address for bind() (vs for connect())
 
#define AI_CANONNAME   0x2
 Fill in ai_canonname.
 
#define AI_NUMERICHOST   0x4
 Assume host address is in numeric notation, don't DNS lookup.
 
#define AI_V4MAPPED   0x8
 May return IPv4 mapped address for IPv6

 
#define AI_ALL   0x10
 May return both native IPv6 and mapped IPv4 address for IPv6.
 
#define AI_ADDRCONFIG   0x20
 IPv4/IPv6 support depends on local system config.
 
#define AI_NUMERICSERV   0x400
 Assume service (port) is numeric.
 
#define AI_EXTFLAGS   0x800
 Extra flags present (see RFC 5014)
 

Flags for getnameinfo()

#define NI_NUMERICHOST   1
 zsock_getnameinfo(): Resolve to numeric address.
 
#define NI_NUMERICSERV   2
 zsock_getnameinfo(): Resolve to numeric port number.
 
#define NI_NOFQDN   4
 zsock_getnameinfo(): Return only hostname instead of FQDN
 
#define NI_NAMEREQD   8
 zsock_getnameinfo(): Dummy option for compatibility
 
#define NI_DGRAM   16
 zsock_getnameinfo(): Dummy option for compatibility
 
#define NI_MAXHOST   64
 zsock_getnameinfo(): Max supported hostname length
 

Network interface name description

#define IFNAMSIZ   Z_DEVICE_MAX_NAME_LEN
 Network interface name length.
 

Socket level options (SOL_SOCKET)

#define SOL_SOCKET   1
 Socket-level option.
 
#define SO_DEBUG   1
 Recording debugging information (ignored, for compatibility)
 
#define SO_REUSEADDR   2
 address reuse
 
#define SO_TYPE   3
 Type of the socket.
 
#define SO_ERROR   4
 Async error.
 
#define SO_DONTROUTE   5
 Bypass normal routing and send directly to host (ignored, for compatibility)
 
#define SO_BROADCAST   6
 Transmission of broadcast messages is supported (ignored, for compatibility)
 
#define SO_SNDBUF   7
 Size of socket send buffer.
 
#define SO_RCVBUF   8
 Size of socket recv buffer.
 
#define SO_KEEPALIVE   9
 Enable sending keep-alive messages on connections.
 
#define SO_OOBINLINE   10
 Place out-of-band data into receive stream (ignored, for compatibility)
 
#define SO_PRIORITY   12
 Socket priority.
 
#define SO_LINGER   13
 Socket lingers on close (ignored, for compatibility)
 
#define SO_REUSEPORT   15
 Allow multiple sockets to reuse a single port.
 
#define SO_RCVLOWAT   18
 Receive low watermark (ignored, for compatibility)
 
#define SO_SNDLOWAT   19
 Send low watermark (ignored, for compatibility)
 
#define SO_RCVTIMEO   20
 Receive timeout Applies to receive functions like recv(), but not to connect()
 
#define SO_SNDTIMEO   21
 Send timeout.
 
#define SO_BINDTODEVICE   25
 Bind a socket to an interface.
 
#define SO_ACCEPTCONN   30
 Socket accepts incoming connections (ignored, for compatibility)
 
#define SO_TIMESTAMPING   37
 Timestamp TX RX or both packets.
 
#define SO_PROTOCOL   38
 Protocol used with the socket.
 
#define SO_DOMAIN   39
 Domain used with SOCKET.
 
#define SO_SOCKS5   60
 Enable SOCKS5 for Socket.
 
#define SO_TXTIME   61
 Socket TX time (when the data should be sent)
 
#define SCM_TXTIME   SO_TXTIME
 Socket TX time (same as SO_TXTIME)
 
#define SOF_TIMESTAMPING_RX_HARDWARE   BIT(0)
 Timestamp generation flags.
 
#define SOF_TIMESTAMPING_TX_HARDWARE   BIT(1)
 Request TX timestamps generated by network adapter.
 

TCP level options (IPPROTO_TCP)

#define TCP_NODELAY   1
 Disable TCP buffering (ignored, for compatibility)
 
#define TCP_KEEPIDLE   2
 Start keepalives after this period (seconds)
 
#define TCP_KEEPINTVL   3
 Interval between keepalives (seconds)
 
#define TCP_KEEPCNT   4
 Number of keepalives before dropping connection.
 

IPv4 level options (IPPROTO_IP)

#define IP_TOS   1
 Set or receive the Type-Of-Service value for an outgoing packet.
 
#define IP_TTL   2
 Set or receive the Time-To-Live value for an outgoing packet.
 
#define IP_PKTINFO   8
 Pass an IP_PKTINFO ancillary message that contains a pktinfo structure that supplies some information about the incoming packet.
 
#define IP_MULTICAST_TTL   33
 Set IPv4 multicast TTL value.
 
#define IP_ADD_MEMBERSHIP   35
 Join IPv4 multicast group.
 
#define IP_DROP_MEMBERSHIP   36
 Leave IPv4 multicast group.
 

IPv6 level options (IPPROTO_IPV6)

#define IPV6_UNICAST_HOPS   16
 Set the unicast hop limit for the socket.
 
#define IPV6_MULTICAST_HOPS   18
 Set the multicast hop limit for the socket.
 
#define IPV6_ADD_MEMBERSHIP   20
 Join IPv6 multicast group.
 
#define IPV6_DROP_MEMBERSHIP   21
 Leave IPv6 multicast group.
 
#define IPV6_V6ONLY   26
 Don't support IPv4 access.
 
#define IPV6_RECVPKTINFO   49
 Pass an IPV6_RECVPKTINFO ancillary message that contains a in6_pktinfo structure that supplies some information about the incoming packet.
 
#define IPV6_ADDR_PREFERENCES   72
 RFC5014: Source address selection.
 
#define IPV6_PREFER_SRC_TMP   0x0001
 Prefer temporary address as source.
 
#define IPV6_PREFER_SRC_PUBLIC   0x0002
 Prefer public address as source.
 
#define IPV6_PREFER_SRC_PUBTMP_DEFAULT   0x0100
 Either public or temporary address is selected as a default source depending on the output interface configuration (this is the default value).
 
#define IPV6_PREFER_SRC_COA   0x0004
 Prefer Care-of address as source.
 
#define IPV6_PREFER_SRC_HOME   0x0400
 Prefer Home address as source.
 
#define IPV6_PREFER_SRC_CGA   0x0008
 Prefer CGA (Cryptographically Generated Address) address as source.
 
#define IPV6_PREFER_SRC_NONCGA   0x0800
 Prefer non-CGA address as source.
 
#define IPV6_TCLASS   67
 Set or receive the traffic class value for an outgoing packet.
 

Backlog size for listen()

#define SOMAXCONN   128
 listen: The maximum backlog queue length
 

Detailed Description

BSD Sockets compatible API.

Macro Definition Documentation

◆ addrinfo

#define addrinfo   zsock_addrinfo

#include <include/zephyr/net/socket.h>

POSIX wrapper for zsock_addrinfo.

◆ AI_ADDRCONFIG

#define AI_ADDRCONFIG   0x20

#include <include/zephyr/net/socket.h>

IPv4/IPv6 support depends on local system config.

◆ AI_ALL

#define AI_ALL   0x10

#include <include/zephyr/net/socket.h>

May return both native IPv6 and mapped IPv4 address for IPv6.

◆ AI_CANONNAME

#define AI_CANONNAME   0x2

#include <include/zephyr/net/socket.h>

Fill in ai_canonname.

◆ AI_EXTFLAGS

#define AI_EXTFLAGS   0x800

#include <include/zephyr/net/socket.h>

Extra flags present (see RFC 5014)

◆ AI_NUMERICHOST

#define AI_NUMERICHOST   0x4

#include <include/zephyr/net/socket.h>

Assume host address is in numeric notation, don't DNS lookup.

◆ AI_NUMERICSERV

#define AI_NUMERICSERV   0x400

#include <include/zephyr/net/socket.h>

Assume service (port) is numeric.

◆ AI_PASSIVE

#define AI_PASSIVE   0x1

#include <include/zephyr/net/socket.h>

Address for bind() (vs for connect())

◆ AI_V4MAPPED

#define AI_V4MAPPED   0x8

#include <include/zephyr/net/socket.h>

May return IPv4 mapped address for IPv6

◆ EAI_AGAIN

#define EAI_AGAIN   DNS_EAI_AGAIN

#include <include/zephyr/net/socket.h>

POSIX wrapper for DNS_EAI_AGAIN.

◆ EAI_BADFLAGS

#define EAI_BADFLAGS   DNS_EAI_BADFLAGS

#include <include/zephyr/net/socket.h>

POSIX wrapper for DNS_EAI_BADFLAGS.

◆ EAI_FAIL

#define EAI_FAIL   DNS_EAI_FAIL

#include <include/zephyr/net/socket.h>

POSIX wrapper for DNS_EAI_FAIL.

◆ EAI_FAMILY

#define EAI_FAMILY   DNS_EAI_FAMILY

#include <include/zephyr/net/socket.h>

POSIX wrapper for DNS_EAI_FAMILY.

◆ EAI_MEMORY

#define EAI_MEMORY   DNS_EAI_MEMORY

#include <include/zephyr/net/socket.h>

POSIX wrapper for DNS_EAI_MEMORY.

◆ EAI_NODATA

#define EAI_NODATA   DNS_EAI_NODATA

#include <include/zephyr/net/socket.h>

POSIX wrapper for DNS_EAI_NODATA.

◆ EAI_NONAME

#define EAI_NONAME   DNS_EAI_NONAME

#include <include/zephyr/net/socket.h>

POSIX wrapper for DNS_EAI_NONAME.

◆ EAI_SERVICE

#define EAI_SERVICE   DNS_EAI_SERVICE

#include <include/zephyr/net/socket.h>

POSIX wrapper for DNS_EAI_SERVICE.

◆ EAI_SOCKTYPE

#define EAI_SOCKTYPE   DNS_EAI_SOCKTYPE

#include <include/zephyr/net/socket.h>

POSIX wrapper for DNS_EAI_SOCKTYPE.

◆ EAI_SYSTEM

#define EAI_SYSTEM   DNS_EAI_SYSTEM

#include <include/zephyr/net/socket.h>

POSIX wrapper for DNS_EAI_SYSTEM.

◆ IFNAMSIZ

#define IFNAMSIZ   Z_DEVICE_MAX_NAME_LEN

#include <include/zephyr/net/socket.h>

Network interface name length.

◆ IP_ADD_MEMBERSHIP

#define IP_ADD_MEMBERSHIP   35

#include <include/zephyr/net/socket.h>

Join IPv4 multicast group.

◆ IP_DROP_MEMBERSHIP

#define IP_DROP_MEMBERSHIP   36

#include <include/zephyr/net/socket.h>

Leave IPv4 multicast group.

◆ IP_MULTICAST_TTL

#define IP_MULTICAST_TTL   33

#include <include/zephyr/net/socket.h>

Set IPv4 multicast TTL value.

◆ IP_PKTINFO

#define IP_PKTINFO   8

#include <include/zephyr/net/socket.h>

Pass an IP_PKTINFO ancillary message that contains a pktinfo structure that supplies some information about the incoming packet.

◆ IP_TOS

#define IP_TOS   1

#include <include/zephyr/net/socket.h>

Set or receive the Type-Of-Service value for an outgoing packet.

◆ IP_TTL

#define IP_TTL   2

#include <include/zephyr/net/socket.h>

Set or receive the Time-To-Live value for an outgoing packet.

◆ IPV6_ADD_MEMBERSHIP

#define IPV6_ADD_MEMBERSHIP   20

#include <include/zephyr/net/socket.h>

Join IPv6 multicast group.

◆ IPV6_ADDR_PREFERENCES

#define IPV6_ADDR_PREFERENCES   72

#include <include/zephyr/net/socket.h>

RFC5014: Source address selection.

◆ IPV6_DROP_MEMBERSHIP

#define IPV6_DROP_MEMBERSHIP   21

#include <include/zephyr/net/socket.h>

Leave IPv6 multicast group.

◆ IPV6_MULTICAST_HOPS

#define IPV6_MULTICAST_HOPS   18

#include <include/zephyr/net/socket.h>

Set the multicast hop limit for the socket.

◆ IPV6_PREFER_SRC_CGA

#define IPV6_PREFER_SRC_CGA   0x0008

#include <include/zephyr/net/socket.h>

Prefer CGA (Cryptographically Generated Address) address as source.

Ignored in Zephyr.

◆ IPV6_PREFER_SRC_COA

#define IPV6_PREFER_SRC_COA   0x0004

#include <include/zephyr/net/socket.h>

Prefer Care-of address as source.

Ignored in Zephyr.

◆ IPV6_PREFER_SRC_HOME

#define IPV6_PREFER_SRC_HOME   0x0400

#include <include/zephyr/net/socket.h>

Prefer Home address as source.

Ignored in Zephyr.

◆ IPV6_PREFER_SRC_NONCGA

#define IPV6_PREFER_SRC_NONCGA   0x0800

#include <include/zephyr/net/socket.h>

Prefer non-CGA address as source.

Ignored in Zephyr.

◆ IPV6_PREFER_SRC_PUBLIC

#define IPV6_PREFER_SRC_PUBLIC   0x0002

#include <include/zephyr/net/socket.h>

Prefer public address as source.

◆ IPV6_PREFER_SRC_PUBTMP_DEFAULT

#define IPV6_PREFER_SRC_PUBTMP_DEFAULT   0x0100

#include <include/zephyr/net/socket.h>

Either public or temporary address is selected as a default source depending on the output interface configuration (this is the default value).

This is Linux specific option not found in the RFC.

◆ IPV6_PREFER_SRC_TMP

#define IPV6_PREFER_SRC_TMP   0x0001

#include <include/zephyr/net/socket.h>

Prefer temporary address as source.

◆ IPV6_RECVPKTINFO

#define IPV6_RECVPKTINFO   49

#include <include/zephyr/net/socket.h>

Pass an IPV6_RECVPKTINFO ancillary message that contains a in6_pktinfo structure that supplies some information about the incoming packet.

See RFC 3542.

◆ IPV6_TCLASS

#define IPV6_TCLASS   67

#include <include/zephyr/net/socket.h>

Set or receive the traffic class value for an outgoing packet.

◆ IPV6_UNICAST_HOPS

#define IPV6_UNICAST_HOPS   16

#include <include/zephyr/net/socket.h>

Set the unicast hop limit for the socket.

◆ IPV6_V6ONLY

#define IPV6_V6ONLY   26

#include <include/zephyr/net/socket.h>

Don't support IPv4 access.

◆ MSG_CTRUNC

#define MSG_CTRUNC   ZSOCK_MSG_CTRUNC

#include <include/zephyr/net/socket.h>

POSIX wrapper for ZSOCK_MSG_CTRUNC.

◆ MSG_DONTWAIT

#define MSG_DONTWAIT   ZSOCK_MSG_DONTWAIT

#include <include/zephyr/net/socket.h>

POSIX wrapper for ZSOCK_MSG_DONTWAIT.

◆ MSG_PEEK

#define MSG_PEEK   ZSOCK_MSG_PEEK

#include <include/zephyr/net/socket.h>

POSIX wrapper for ZSOCK_MSG_PEEK.

◆ MSG_TRUNC

#define MSG_TRUNC   ZSOCK_MSG_TRUNC

#include <include/zephyr/net/socket.h>

POSIX wrapper for ZSOCK_MSG_TRUNC.

◆ MSG_WAITALL

#define MSG_WAITALL   ZSOCK_MSG_WAITALL

#include <include/zephyr/net/socket.h>

POSIX wrapper for ZSOCK_MSG_WAITALL.

◆ NI_DGRAM

#define NI_DGRAM   16

#include <include/zephyr/net/socket.h>

zsock_getnameinfo(): Dummy option for compatibility

◆ NI_MAXHOST

#define NI_MAXHOST   64

#include <include/zephyr/net/socket.h>

zsock_getnameinfo(): Max supported hostname length

◆ NI_NAMEREQD

#define NI_NAMEREQD   8

#include <include/zephyr/net/socket.h>

zsock_getnameinfo(): Dummy option for compatibility

◆ NI_NOFQDN

#define NI_NOFQDN   4

#include <include/zephyr/net/socket.h>

zsock_getnameinfo(): Return only hostname instead of FQDN

◆ NI_NUMERICHOST

#define NI_NUMERICHOST   1

#include <include/zephyr/net/socket.h>

zsock_getnameinfo(): Resolve to numeric address.

◆ NI_NUMERICSERV

#define NI_NUMERICSERV   2

#include <include/zephyr/net/socket.h>

zsock_getnameinfo(): Resolve to numeric port number.

◆ POLLERR

#define POLLERR   ZSOCK_POLLERR

#include <include/zephyr/net/socket.h>

POSIX wrapper for ZSOCK_POLLERR.

◆ pollfd

#define pollfd   zsock_pollfd

#include <include/zephyr/net/socket.h>

POSIX wrapper for zsock_pollfd.

◆ POLLHUP

#define POLLHUP   ZSOCK_POLLHUP

#include <include/zephyr/net/socket.h>

POSIX wrapper for ZSOCK_POLLHUP.

◆ POLLIN

#define POLLIN   ZSOCK_POLLIN

#include <include/zephyr/net/socket.h>

POSIX wrapper for ZSOCK_POLLIN.

◆ POLLNVAL

#define POLLNVAL   ZSOCK_POLLNVAL

#include <include/zephyr/net/socket.h>

POSIX wrapper for ZSOCK_POLLNVAL.

◆ POLLOUT

#define POLLOUT   ZSOCK_POLLOUT

#include <include/zephyr/net/socket.h>

POSIX wrapper for ZSOCK_POLLOUT.

◆ SCM_TXTIME

#define SCM_TXTIME   SO_TXTIME

#include <include/zephyr/net/socket.h>

Socket TX time (same as SO_TXTIME)

◆ SHUT_RD

#define SHUT_RD   ZSOCK_SHUT_RD

#include <include/zephyr/net/socket.h>

POSIX wrapper for ZSOCK_SHUT_RD.

◆ SHUT_RDWR

#define SHUT_RDWR   ZSOCK_SHUT_RDWR

#include <include/zephyr/net/socket.h>

POSIX wrapper for ZSOCK_SHUT_RDWR.

◆ SHUT_WR

#define SHUT_WR   ZSOCK_SHUT_WR

#include <include/zephyr/net/socket.h>

POSIX wrapper for ZSOCK_SHUT_WR.

◆ SO_ACCEPTCONN

#define SO_ACCEPTCONN   30

#include <include/zephyr/net/socket.h>

Socket accepts incoming connections (ignored, for compatibility)

◆ SO_BINDTODEVICE

#define SO_BINDTODEVICE   25

#include <include/zephyr/net/socket.h>

Bind a socket to an interface.

◆ SO_BROADCAST

#define SO_BROADCAST   6

#include <include/zephyr/net/socket.h>

Transmission of broadcast messages is supported (ignored, for compatibility)

◆ SO_DEBUG

#define SO_DEBUG   1

#include <include/zephyr/net/socket.h>

Recording debugging information (ignored, for compatibility)

◆ SO_DOMAIN

#define SO_DOMAIN   39

#include <include/zephyr/net/socket.h>

Domain used with SOCKET.

◆ SO_DONTROUTE

#define SO_DONTROUTE   5

#include <include/zephyr/net/socket.h>

Bypass normal routing and send directly to host (ignored, for compatibility)

◆ SO_ERROR

#define SO_ERROR   4

#include <include/zephyr/net/socket.h>

Async error.

◆ SO_KEEPALIVE

#define SO_KEEPALIVE   9

#include <include/zephyr/net/socket.h>

Enable sending keep-alive messages on connections.

◆ SO_LINGER

#define SO_LINGER   13

#include <include/zephyr/net/socket.h>

Socket lingers on close (ignored, for compatibility)

◆ SO_OOBINLINE

#define SO_OOBINLINE   10

#include <include/zephyr/net/socket.h>

Place out-of-band data into receive stream (ignored, for compatibility)

◆ SO_PRIORITY

#define SO_PRIORITY   12

#include <include/zephyr/net/socket.h>

Socket priority.

◆ SO_PROTOCOL

#define SO_PROTOCOL   38

#include <include/zephyr/net/socket.h>

Protocol used with the socket.

◆ SO_RCVBUF

#define SO_RCVBUF   8

#include <include/zephyr/net/socket.h>

Size of socket recv buffer.

◆ SO_RCVLOWAT

#define SO_RCVLOWAT   18

#include <include/zephyr/net/socket.h>

Receive low watermark (ignored, for compatibility)

◆ SO_RCVTIMEO

#define SO_RCVTIMEO   20

#include <include/zephyr/net/socket.h>

Receive timeout Applies to receive functions like recv(), but not to connect()

◆ SO_REUSEADDR

#define SO_REUSEADDR   2

#include <include/zephyr/net/socket.h>

address reuse

◆ SO_REUSEPORT

#define SO_REUSEPORT   15

#include <include/zephyr/net/socket.h>

Allow multiple sockets to reuse a single port.

◆ SO_SNDBUF

#define SO_SNDBUF   7

#include <include/zephyr/net/socket.h>

Size of socket send buffer.

◆ SO_SNDLOWAT

#define SO_SNDLOWAT   19

#include <include/zephyr/net/socket.h>

Send low watermark (ignored, for compatibility)

◆ SO_SNDTIMEO

#define SO_SNDTIMEO   21

#include <include/zephyr/net/socket.h>

Send timeout.

◆ SO_SOCKS5

#define SO_SOCKS5   60

#include <include/zephyr/net/socket.h>

Enable SOCKS5 for Socket.

◆ SO_TIMESTAMPING

#define SO_TIMESTAMPING   37

#include <include/zephyr/net/socket.h>

Timestamp TX RX or both packets.

Supports multiple timestamp sources.

◆ SO_TXTIME

#define SO_TXTIME   61

#include <include/zephyr/net/socket.h>

Socket TX time (when the data should be sent)

◆ SO_TYPE

#define SO_TYPE   3

#include <include/zephyr/net/socket.h>

Type of the socket.

◆ SOF_TIMESTAMPING_RX_HARDWARE

#define SOF_TIMESTAMPING_RX_HARDWARE   BIT(0)

#include <include/zephyr/net/socket.h>

Timestamp generation flags.

Request RX timestamps generated by network adapter.

◆ SOF_TIMESTAMPING_TX_HARDWARE

#define SOF_TIMESTAMPING_TX_HARDWARE   BIT(1)

#include <include/zephyr/net/socket.h>

Request TX timestamps generated by network adapter.

This can be enabled via socket option or control messages.

◆ SOL_SOCKET

#define SOL_SOCKET   1

#include <include/zephyr/net/socket.h>

Socket-level option.

◆ SOMAXCONN

#define SOMAXCONN   128

#include <include/zephyr/net/socket.h>

listen: The maximum backlog queue length

◆ TCP_KEEPCNT

#define TCP_KEEPCNT   4

#include <include/zephyr/net/socket.h>

Number of keepalives before dropping connection.

◆ TCP_KEEPIDLE

#define TCP_KEEPIDLE   2

#include <include/zephyr/net/socket.h>

Start keepalives after this period (seconds)

◆ TCP_KEEPINTVL

#define TCP_KEEPINTVL   3

#include <include/zephyr/net/socket.h>

Interval between keepalives (seconds)

◆ TCP_NODELAY

#define TCP_NODELAY   1

#include <include/zephyr/net/socket.h>

Disable TCP buffering (ignored, for compatibility)

◆ ZSOCK_FD_SETSIZE

#define ZSOCK_FD_SETSIZE   (sizeof(((zsock_fd_set *)0)->bitset) * 8)

#include <include/zephyr/net/socket_select.h>

Number of file descriptors which can be added to zsock_fd_set.

◆ ZSOCK_MSG_CTRUNC

#define ZSOCK_MSG_CTRUNC   0x08

#include <include/zephyr/net/socket.h>

zsock_recvmsg: Control data buffer too small.

◆ ZSOCK_MSG_DONTWAIT

#define ZSOCK_MSG_DONTWAIT   0x40

#include <include/zephyr/net/socket.h>

zsock_recv/zsock_send: Override operation to non-blocking

◆ ZSOCK_MSG_PEEK

#define ZSOCK_MSG_PEEK   0x02

#include <include/zephyr/net/socket.h>

zsock_recv: Read data without removing it from socket input queue

◆ ZSOCK_MSG_TRUNC

#define ZSOCK_MSG_TRUNC   0x20

#include <include/zephyr/net/socket.h>

zsock_recv: return the real length of the datagram, even when it was longer than the passed buffer

◆ ZSOCK_MSG_WAITALL

#define ZSOCK_MSG_WAITALL   0x100

#include <include/zephyr/net/socket.h>

zsock_recv: block until the full amount of data can be returned

◆ ZSOCK_POLLERR

#define ZSOCK_POLLERR   8

#include <include/zephyr/net/socket.h>

zsock_poll: Poll results in error condition (output value only)

◆ ZSOCK_POLLHUP

#define ZSOCK_POLLHUP   0x10

#include <include/zephyr/net/socket.h>

zsock_poll: Poll detected closed connection (output value only)

◆ ZSOCK_POLLIN

#define ZSOCK_POLLIN   1

#include <include/zephyr/net/socket.h>

zsock_poll: Poll for readability

◆ ZSOCK_POLLNVAL

#define ZSOCK_POLLNVAL   0x20

#include <include/zephyr/net/socket.h>

zsock_poll: Invalid socket (output value only)

◆ ZSOCK_POLLOUT

#define ZSOCK_POLLOUT   4

#include <include/zephyr/net/socket.h>

zsock_poll: Poll for writability

◆ ZSOCK_POLLPRI

#define ZSOCK_POLLPRI   2

#include <include/zephyr/net/socket.h>

zsock_poll: Poll for exceptional condition

◆ ZSOCK_SHUT_RD

#define ZSOCK_SHUT_RD   0

#include <include/zephyr/net/socket.h>

zsock_shutdown: Shut down for reading

◆ ZSOCK_SHUT_RDWR

#define ZSOCK_SHUT_RDWR   2

#include <include/zephyr/net/socket.h>

zsock_shutdown: Shut down for both reading and writing

◆ ZSOCK_SHUT_WR

#define ZSOCK_SHUT_WR   1

#include <include/zephyr/net/socket.h>

zsock_shutdown: Shut down for writing

Typedef Documentation

◆ zsock_fd_set

typedef struct zsock_fd_set zsock_fd_set

#include <include/zephyr/net/socket_select.h>

Socket file descriptor set.

Function Documentation

◆ accept()

static int accept ( int  sock,
struct sockaddr addr,
socklen_t addrlen 
)
inlinestatic

#include <include/zephyr/net/socket.h>

POSIX wrapper for zsock_accept.

◆ bind()

static int bind ( int  sock,
const struct sockaddr addr,
socklen_t  addrlen 
)
inlinestatic

#include <include/zephyr/net/socket.h>

POSIX wrapper for zsock_bind.

◆ close()

static int close ( int  sock)
inlinestatic

#include <include/zephyr/net/socket.h>

POSIX wrapper for zsock_close.

◆ connect()

static int connect ( int  sock,
const struct sockaddr addr,
socklen_t  addrlen 
)
inlinestatic

#include <include/zephyr/net/socket.h>

POSIX wrapper for zsock_connect.

◆ freeaddrinfo()

static void freeaddrinfo ( struct zsock_addrinfo ai)
inlinestatic

#include <include/zephyr/net/socket.h>

POSIX wrapper for zsock_freeaddrinfo.

◆ gai_strerror()

static const char * gai_strerror ( int  errcode)
inlinestatic

#include <include/zephyr/net/socket.h>

POSIX wrapper for zsock_gai_strerror.

◆ getaddrinfo()

static int getaddrinfo ( const char *  host,
const char *  service,
const struct zsock_addrinfo hints,
struct zsock_addrinfo **  res 
)
inlinestatic

#include <include/zephyr/net/socket.h>

POSIX wrapper for zsock_getaddrinfo.

◆ gethostname()

static int gethostname ( char *  buf,
size_t  len 
)
inlinestatic

#include <include/zephyr/net/socket.h>

POSIX wrapper for zsock_gethostname.

◆ getnameinfo()

static int getnameinfo ( const struct sockaddr addr,
socklen_t  addrlen,
char *  host,
socklen_t  hostlen,
char *  serv,
socklen_t  servlen,
int  flags 
)
inlinestatic

#include <include/zephyr/net/socket.h>

POSIX wrapper for zsock_getnameinfo.

◆ getpeername()

static int getpeername ( int  sock,
struct sockaddr addr,
socklen_t addrlen 
)
inlinestatic

#include <include/zephyr/net/socket.h>

POSIX wrapper for zsock_getpeername.

◆ getsockname()

static int getsockname ( int  sock,
struct sockaddr addr,
socklen_t addrlen 
)
inlinestatic

#include <include/zephyr/net/socket.h>

POSIX wrapper for zsock_getsockname.

◆ getsockopt()

static int getsockopt ( int  sock,
int  level,
int  optname,
void *  optval,
socklen_t optlen 
)
inlinestatic

#include <include/zephyr/net/socket.h>

POSIX wrapper for zsock_getsockopt.

◆ inet_ntop()

static char * inet_ntop ( sa_family_t  family,
const void *  src,
char *  dst,
size_t  size 
)
inlinestatic

#include <include/zephyr/net/socket.h>

POSIX wrapper for zsock_inet_ntop.

◆ inet_pton()

static int inet_pton ( sa_family_t  family,
const char *  src,
void *  dst 
)
inlinestatic

#include <include/zephyr/net/socket.h>

POSIX wrapper for zsock_inet_pton.

◆ listen()

static int listen ( int  sock,
int  backlog 
)
inlinestatic

#include <include/zephyr/net/socket.h>

POSIX wrapper for zsock_listen.

◆ poll()

static int poll ( struct zsock_pollfd fds,
int  nfds,
int  timeout 
)
inlinestatic

#include <include/zephyr/net/socket.h>

POSIX wrapper for zsock_poll.

◆ recv()

static ssize_t recv ( int  sock,
void *  buf,
size_t  max_len,
int  flags 
)
inlinestatic

#include <include/zephyr/net/socket.h>

POSIX wrapper for zsock_recv.

◆ recvfrom()

static ssize_t recvfrom ( int  sock,
void *  buf,
size_t  max_len,
int  flags,
struct sockaddr src_addr,
socklen_t addrlen 
)
inlinestatic

#include <include/zephyr/net/socket.h>

POSIX wrapper for zsock_recvfrom.

◆ recvmsg()

static ssize_t recvmsg ( int  sock,
struct msghdr msg,
int  flags 
)
inlinestatic

#include <include/zephyr/net/socket.h>

POSIX wrapper for zsock_recvmsg.

◆ send()

static ssize_t send ( int  sock,
const void *  buf,
size_t  len,
int  flags 
)
inlinestatic

#include <include/zephyr/net/socket.h>

POSIX wrapper for zsock_send.

◆ sendmsg()

static ssize_t sendmsg ( int  sock,
const struct msghdr message,
int  flags 
)
inlinestatic

#include <include/zephyr/net/socket.h>

POSIX wrapper for zsock_sendmsg.

◆ sendto()

static ssize_t sendto ( int  sock,
const void *  buf,
size_t  len,
int  flags,
const struct sockaddr dest_addr,
socklen_t  addrlen 
)
inlinestatic

#include <include/zephyr/net/socket.h>

POSIX wrapper for zsock_sendto.

◆ setsockopt()

static int setsockopt ( int  sock,
int  level,
int  optname,
const void *  optval,
socklen_t  optlen 
)
inlinestatic

#include <include/zephyr/net/socket.h>

POSIX wrapper for zsock_setsockopt.

◆ shutdown()

static int shutdown ( int  sock,
int  how 
)
inlinestatic

#include <include/zephyr/net/socket.h>

POSIX wrapper for zsock_shutdown.

◆ socket()

static int socket ( int  family,
int  type,
int  proto 
)
inlinestatic

#include <include/zephyr/net/socket.h>

POSIX wrapper for zsock_socket.

◆ socketpair()

static int socketpair ( int  family,
int  type,
int  proto,
int  sv[2] 
)
inlinestatic

#include <include/zephyr/net/socket.h>

POSIX wrapper for zsock_socketpair.

◆ zsock_accept()

int zsock_accept ( int  sock,
struct sockaddr addr,
socklen_t addrlen 
)

#include <include/zephyr/net/socket.h>

Accept a connection on listening socket.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/accept.html>`__
* for normative description.
* This function is also exposed as ``accept()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* 

◆ zsock_bind()

int zsock_bind ( int  sock,
const struct sockaddr addr,
socklen_t  addrlen 
)

#include <include/zephyr/net/socket.h>

Bind a socket to a local network address.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html>`__
* for normative description.
* This function is also exposed as ``bind()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* 

◆ zsock_close()

int zsock_close ( int  sock)

#include <include/zephyr/net/socket.h>

Close a network socket.

embed:rst:leading-asterisk
* Close a network socket.
* This function is also exposed as ``close()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined (in which case it
* may conflict with generic POSIX ``close()`` function).
* 

◆ zsock_connect()

int zsock_connect ( int  sock,
const struct sockaddr addr,
socklen_t  addrlen 
)

#include <include/zephyr/net/socket.h>

Connect a socket to a peer network address.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html>`__
* for normative description.
* This function is also exposed as ``connect()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* 

◆ zsock_fcntl_impl()

int zsock_fcntl_impl ( int  sock,
int  cmd,
int  flags 
)

#include <include/zephyr/net/socket.h>

Control blocking/non-blocking mode of a socket.

embed:rst:leading-asterisk
* This functions allow to (only) configure a socket for blocking or
* non-blocking operation (O_NONBLOCK).
* This function is also exposed as ``fcntl()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined (in which case
* it may conflict with generic POSIX ``fcntl()`` function).
* 

◆ ZSOCK_FD_CLR()

void ZSOCK_FD_CLR ( int  fd,
zsock_fd_set set 
)

#include <include/zephyr/net/socket_select.h>

Remove socket from fd_set.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/select.html>`__
* for normative description.
* This function is also exposed as ``FD_CLR()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* 

◆ ZSOCK_FD_ISSET()

int ZSOCK_FD_ISSET ( int  fd,
zsock_fd_set set 
)

#include <include/zephyr/net/socket_select.h>

Check whether socket is a member of fd_set.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/select.html>`__
* for normative description.
* This function is also exposed as ``FD_ISSET()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* 

◆ ZSOCK_FD_SET()

void ZSOCK_FD_SET ( int  fd,
zsock_fd_set set 
)

#include <include/zephyr/net/socket_select.h>

Add socket to fd_set.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/select.html>`__
* for normative description.
* This function is also exposed as ``FD_SET()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* 

◆ ZSOCK_FD_ZERO()

void ZSOCK_FD_ZERO ( zsock_fd_set set)

#include <include/zephyr/net/socket_select.h>

Initialize (clear) fd_set.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/select.html>`__
* for normative description.
* This function is also exposed as ``FD_ZERO()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* 

◆ zsock_freeaddrinfo()

void zsock_freeaddrinfo ( struct zsock_addrinfo ai)

#include <include/zephyr/net/socket.h>

Free results returned by zsock_getaddrinfo()

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/freeaddrinfo.html>`__
* for normative description.
* This function is also exposed as ``freeaddrinfo()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* 

◆ zsock_gai_strerror()

const char * zsock_gai_strerror ( int  errcode)

#include <include/zephyr/net/socket.h>

Convert zsock_getaddrinfo() error code to textual message.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/gai_strerror.html>`__
* for normative description.
* This function is also exposed as ``gai_strerror()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* 

◆ zsock_get_context_object()

void * zsock_get_context_object ( int  sock)

#include <include/zephyr/net/socket.h>

Obtain a file descriptor's associated net context.

With CONFIG_USERSPACE enabled, the kernel's object permission system must apply to socket file descriptors. When a socket is opened, by default only the caller has permission, access by other threads will fail unless they have been specifically granted permission.

This is achieved by tagging data structure definitions that implement the underlying object associated with a network socket file descriptor with '__net_socket`. All pointers to instances of these will be known to the kernel as kernel objects with type K_OBJ_NET_SOCKET.

This API is intended for threads that need to grant access to the object associated with a particular file descriptor to another thread. The returned pointer represents the underlying K_OBJ_NET_SOCKET and may be passed to APIs like k_object_access_grant().

In a system like Linux which has the notion of threads running in processes in a shared virtual address space, this sort of management is unnecessary as the scope of file descriptors is implemented at the process level.

However in Zephyr the file descriptor scope is global, and MPU-based systems are not able to implement a process-like model due to the lack of memory virtualization hardware. They use discrete object permissions and memory domains instead to define thread access scope.

User threads will have no direct access to the returned object and will fault if they try to access its memory; the pointer can only be used to make permission assignment calls, which follow exactly the rules for other kernel objects like device drivers and IPC.

Parameters
sockfile descriptor
Returns
pointer to associated network socket object, or NULL if the file descriptor wasn't valid or the caller had no access permission

◆ zsock_getaddrinfo()

int zsock_getaddrinfo ( const char *  host,
const char *  service,
const struct zsock_addrinfo hints,
struct zsock_addrinfo **  res 
)

#include <include/zephyr/net/socket.h>

Resolve a domain name to one or more network addresses.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html>`__
* for normative description.
* This function is also exposed as ``getaddrinfo()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* 

◆ zsock_gethostname()

int zsock_gethostname ( char *  buf,
size_t  len 
)

#include <include/zephyr/net/socket.h>

Get local host name.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/gethostname.html>`__
* for normative description.
* This function is also exposed as ``gethostname()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* 

◆ zsock_getnameinfo()

int zsock_getnameinfo ( const struct sockaddr addr,
socklen_t  addrlen,
char *  host,
socklen_t  hostlen,
char *  serv,
socklen_t  servlen,
int  flags 
)

#include <include/zephyr/net/socket.h>

Resolve a network address to a domain name or ASCII address.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/getnameinfo.html>`__
* for normative description.
* This function is also exposed as ``getnameinfo()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* 

◆ zsock_getpeername()

int zsock_getpeername ( int  sock,
struct sockaddr addr,
socklen_t addrlen 
)

#include <include/zephyr/net/socket.h>

Get peer name.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/getpeername.html>`__
* for normative description.
* This function is also exposed as ``getpeername()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* 

◆ zsock_getsockname()

int zsock_getsockname ( int  sock,
struct sockaddr addr,
socklen_t addrlen 
)

#include <include/zephyr/net/socket.h>

Get socket name.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockname.html>`__
* for normative description.
* This function is also exposed as ``getsockname()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* 

◆ zsock_getsockopt()

int zsock_getsockopt ( int  sock,
int  level,
int  optname,
void *  optval,
socklen_t optlen 
)

#include <include/zephyr/net/socket.h>

Get various socket options.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html>`__
* for normative description. In Zephyr this function supports a subset of
* socket options described by POSIX, but also some additional options
* available in Linux (some options are dummy and provided to ease porting
* of existing code).
* This function is also exposed as ``getsockopt()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* 

◆ zsock_inet_ntop()

static char * zsock_inet_ntop ( sa_family_t  family,
const void *  src,
char *  dst,
size_t  size 
)
inlinestatic

#include <include/zephyr/net/socket.h>

Convert network address from internal to numeric ASCII form.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/inet_ntop.html>`__
* for normative description.
* This function is also exposed as ``inet_ntop()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* 

◆ zsock_inet_pton()

int zsock_inet_pton ( sa_family_t  family,
const char *  src,
void *  dst 
)

#include <include/zephyr/net/socket.h>

Convert network address from numeric ASCII form to internal representation.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/inet_pton.html>`__
* for normative description.
* This function is also exposed as ``inet_pton()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* 

◆ zsock_ioctl_impl()

int zsock_ioctl_impl ( int  sock,
unsigned long  request,
va_list  ap 
)

#include <include/zephyr/net/socket.h>

Control underlying socket parameters.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <https://pubs.opengroup.org/onlinepubs/9699919799/functions/ioctl.html>`__
* for normative description.
* This function enables querying or manipulating underlying socket parameters.
* Currently supported @p request values include ``ZFD_IOCTL_FIONBIO``, and
* ``ZFD_IOCTL_FIONREAD``, to set non-blocking mode, and query the number of
* bytes available to read, respectively.
* This function is also exposed as ``ioctl()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined (in which case
* it may conflict with generic POSIX ``ioctl()`` function).
* 

◆ zsock_listen()

int zsock_listen ( int  sock,
int  backlog 
)

#include <include/zephyr/net/socket.h>

Set up a STREAM socket to accept peer connections.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/listen.html>`__
* for normative description.
* This function is also exposed as ``listen()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* 

◆ zsock_poll()

int zsock_poll ( struct zsock_pollfd fds,
int  nfds,
int  timeout 
)

#include <include/zephyr/net/socket.h>

Efficiently poll multiple sockets for events.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/poll.html>`__
* for normative description.
* This function is also exposed as ``poll()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined (in which case
* it may conflict with generic POSIX ``poll()`` function).
* 

◆ zsock_recv()

static ssize_t zsock_recv ( int  sock,
void *  buf,
size_t  max_len,
int  flags 
)
inlinestatic

#include <include/zephyr/net/socket.h>

Receive data from a connected peer.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/recv.html>`__
* for normative description.
* This function is also exposed as ``recv()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* 

◆ zsock_recvfrom()

ssize_t zsock_recvfrom ( int  sock,
void *  buf,
size_t  max_len,
int  flags,
struct sockaddr src_addr,
socklen_t addrlen 
)

#include <include/zephyr/net/socket.h>

Receive data from an arbitrary network address.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/recvfrom.html>`__
* for normative description.
* This function is also exposed as ``recvfrom()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* 

◆ zsock_recvmsg()

ssize_t zsock_recvmsg ( int  sock,
struct msghdr msg,
int  flags 
)

#include <include/zephyr/net/socket.h>

Receive a message from an arbitrary network address.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/recvmsg.html>`__
* for normative description.
* This function is also exposed as ``recvmsg()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* 

◆ zsock_select()

int zsock_select ( int  nfds,
zsock_fd_set readfds,
zsock_fd_set writefds,
zsock_fd_set exceptfds,
struct zsock_timeval *  timeout 
)

#include <include/zephyr/net/socket_select.h>

Legacy function to poll multiple sockets for events.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/select.html>`__
* for normative description. This function is provided to ease porting of
* existing code and not recommended for usage due to its inefficiency,
* use zsock_poll() instead. In Zephyr this function works only with
* sockets, not arbitrary file descriptors.
* This function is also exposed as ``select()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined (in which case
* it may conflict with generic POSIX ``select()`` function).
* 

◆ zsock_send()

static ssize_t zsock_send ( int  sock,
const void *  buf,
size_t  len,
int  flags 
)
inlinestatic

#include <include/zephyr/net/socket.h>

Send data to a connected peer.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/send.html>`__
* for normative description.
* This function is also exposed as ``send()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* 

◆ zsock_sendmsg()

ssize_t zsock_sendmsg ( int  sock,
const struct msghdr msg,
int  flags 
)

#include <include/zephyr/net/socket.h>

Send data to an arbitrary network address.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/sendmsg.html>`__
* for normative description.
* This function is also exposed as ``sendmsg()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* 

◆ zsock_sendto()

ssize_t zsock_sendto ( int  sock,
const void *  buf,
size_t  len,
int  flags,
const struct sockaddr dest_addr,
socklen_t  addrlen 
)

#include <include/zephyr/net/socket.h>

Send data to an arbitrary network address.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/sendto.html>`__
* for normative description.
* This function is also exposed as ``sendto()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* 

◆ zsock_setsockopt()

int zsock_setsockopt ( int  sock,
int  level,
int  optname,
const void *  optval,
socklen_t  optlen 
)

#include <include/zephyr/net/socket.h>

Set various socket options.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html>`__
* for normative description. In Zephyr this function supports a subset of
* socket options described by POSIX, but also some additional options
* available in Linux (some options are dummy and provided to ease porting
* of existing code).
* This function is also exposed as ``setsockopt()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* 

◆ zsock_shutdown()

int zsock_shutdown ( int  sock,
int  how 
)

#include <include/zephyr/net/socket.h>

Shutdown socket send/receive operations.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/shutdown.html>`__
* for normative description, but currently this function has no effect in
* Zephyr and provided solely for compatibility with existing code.
* This function is also exposed as ``shutdown()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* 

◆ zsock_socket()

int zsock_socket ( int  family,
int  type,
int  proto 
)

#include <include/zephyr/net/socket.h>

Create a network socket.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <http://pubs.opengroup.org/onlinepubs/9699919799/functions/socket.html>`__
* for normative description.
* This function is also exposed as ``socket()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* 

If CONFIG_USERSPACE is enabled, the caller will be granted access to the context object associated with the returned file descriptor.

See also
zsock_get_context_object()

◆ zsock_socketpair()

int zsock_socketpair ( int  family,
int  type,
int  proto,
int *  sv 
)

#include <include/zephyr/net/socket.h>

Create an unnamed pair of connected sockets.

embed:rst:leading-asterisk
* See `POSIX.1-2017 article
* <https://pubs.opengroup.org/onlinepubs/009695399/functions/socketpair.html>`__
* for normative description.
* This function is also exposed as ``socketpair()``
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
*