Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
BSD Sockets compatible API

BSD Sockets compatible API. More...

Modules

 Socket options for TLS
 

Data Structures

struct  zsock_pollfd
 
struct  zsock_addrinfo
 
struct  ifreq
 
struct  zsock_fd_set
 
struct  zsock_timeval
 

Macros

#define ZSOCK_POLLIN   1
 
#define ZSOCK_POLLPRI   2
 
#define ZSOCK_POLLOUT   4
 
#define ZSOCK_POLLERR   8
 
#define ZSOCK_POLLHUP   0x10
 
#define ZSOCK_POLLNVAL   0x20
 
#define ZSOCK_MSG_PEEK   0x02
 
#define ZSOCK_MSG_TRUNC   0x20
 
#define ZSOCK_MSG_DONTWAIT   0x40
 
#define ZSOCK_MSG_WAITALL   0x100
 
#define ZSOCK_SHUT_RD   0
 
#define ZSOCK_SHUT_WR   1
 
#define ZSOCK_SHUT_RDWR   2
 
#define SOL_TLS   282
 
#define TLS_PEER_VERIFY_NONE   0
 
#define TLS_PEER_VERIFY_OPTIONAL   1
 
#define TLS_PEER_VERIFY_REQUIRED   2
 
#define TLS_DTLS_ROLE_CLIENT   0
 
#define TLS_DTLS_ROLE_SERVER   1
 
#define AI_PASSIVE   0x1
 
#define AI_CANONNAME   0x2
 
#define AI_NUMERICHOST   0x4
 
#define AI_V4MAPPED   0x8
 
#define AI_ALL   0x10
 
#define AI_ADDRCONFIG   0x20
 
#define AI_NUMERICSERV   0x400
 
#define NI_NUMERICHOST   1
 
#define NI_NUMERICSERV   2
 
#define NI_NOFQDN   4
 
#define NI_NAMEREQD   8
 
#define NI_DGRAM   16
 
#define NI_MAXHOST   64
 
#define IFNAMSIZ   Z_DEVICE_MAX_NAME_LEN
 
#define SOL_SOCKET   1
 
#define SO_REUSEADDR   2
 
#define SO_TYPE   3
 
#define SO_ERROR   4
 
#define SO_RCVTIMEO   20
 
#define SO_SNDTIMEO   21
 
#define SO_BINDTODEVICE   25
 
#define SO_TIMESTAMPING   37
 
#define SO_PROTOCOL   38
 
#define TCP_NODELAY   1
 
#define IPV6_V6ONLY   26
 
#define SO_PRIORITY   12
 
#define SO_TXTIME   61
 
#define SCM_TXTIME   SO_TXTIME
 
#define SO_SOCKS5   60
 
#define ZSOCK_FD_SETSIZE   (sizeof(((zsock_fd_set *)0)->bitset) * 8)
 

Typedefs

typedef struct zsock_fd_set zsock_fd_set
 

Functions

voidzsock_get_context_object (int sock)
 Obtain a file descriptor's associated net context. More...
 
int zsock_socket (int family, int type, int proto)
 Create a network socket. More...
 
int zsock_socketpair (int family, int type, int proto, int *sv)
 Create an unnamed pair of connected sockets. More...
 
int zsock_close (int sock)
 Close a network socket. More...
 
int zsock_shutdown (int sock, int how)
 Shutdown socket send/receive operations. More...
 
int zsock_bind (int sock, const struct sockaddr *addr, socklen_t addrlen)
 Bind a socket to a local network address. More...
 
int zsock_connect (int sock, const struct sockaddr *addr, socklen_t addrlen)
 Connect a socket to a peer network address. More...
 
int zsock_listen (int sock, int backlog)
 Set up a STREAM socket to accept peer connections. More...
 
int zsock_accept (int sock, struct sockaddr *addr, socklen_t *addrlen)
 Accept a connection on listening socket. More...
 
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. More...
 
static ssize_t zsock_send (int sock, const void *buf, size_t len, int flags)
 Send data to a connected peer. More...
 
ssize_t zsock_sendmsg (int sock, const struct msghdr *msg, int flags)
 Send data to an arbitrary network address. More...
 
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. More...
 
static ssize_t zsock_recv (int sock, void *buf, size_t max_len, int flags)
 Receive data from a connected peer. More...
 
int zsock_fcntl (int sock, int cmd, int flags)
 Control blocking/non-blocking mode of a socket. More...
 
int zsock_poll (struct zsock_pollfd *fds, int nfds, int timeout)
 Efficiently poll multiple sockets for events. More...
 
int zsock_getsockopt (int sock, int level, int optname, void *optval, socklen_t *optlen)
 Get various socket options. More...
 
int zsock_setsockopt (int sock, int level, int optname, const void *optval, socklen_t optlen)
 Set various socket options. More...
 
int zsock_getsockname (int sock, struct sockaddr *addr, socklen_t *addrlen)
 Get socket name. More...
 
int zsock_gethostname (char *buf, size_t len)
 Get local host name. More...
 
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. More...
 
int zsock_inet_pton (sa_family_t family, const char *src, void *dst)
 Convert network address from numeric ASCII form to internal representation. More...
 
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. More...
 
void zsock_freeaddrinfo (struct zsock_addrinfo *ai)
 Free results returned by zsock_getaddrinfo() More...
 
const char * zsock_gai_strerror (int errcode)
 Convert zsock_getaddrinfo() error code to textual message. More...
 
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. More...
 
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. More...
 
void ZSOCK_FD_ZERO (zsock_fd_set *set)
 Initialize (clear) fd_set. More...
 
int ZSOCK_FD_ISSET (int fd, zsock_fd_set *set)
 Check whether socket is a member of fd_set. More...
 
void ZSOCK_FD_CLR (int fd, zsock_fd_set *set)
 Remove socket from fd_set. More...
 
void ZSOCK_FD_SET (int fd, zsock_fd_set *set)
 Add socket to fd_set. More...
 

Detailed Description

BSD Sockets compatible API.

Macro Definition Documentation

◆ AI_ADDRCONFIG

#define AI_ADDRCONFIG   0x20

#include <include/net/socket.h>

IPv4/IPv6 support depends on local system config

◆ AI_ALL

#define AI_ALL   0x10

#include <include/net/socket.h>

May return both native IPv6 and mapped IPv4 address for IPv6

◆ AI_CANONNAME

#define AI_CANONNAME   0x2

#include <include/net/socket.h>

Fill in ai_canonname

◆ AI_NUMERICHOST

#define AI_NUMERICHOST   0x4

#include <include/net/socket.h>

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

◆ AI_NUMERICSERV

#define AI_NUMERICSERV   0x400

#include <include/net/socket.h>

Assume service (port) is numeric

◆ AI_PASSIVE

#define AI_PASSIVE   0x1

#include <include/net/socket.h>

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

◆ AI_V4MAPPED

#define AI_V4MAPPED   0x8

#include <include/net/socket.h>

May return IPv4 mapped address for IPv6

◆ IFNAMSIZ

#define IFNAMSIZ   Z_DEVICE_MAX_NAME_LEN

◆ IPV6_V6ONLY

#define IPV6_V6ONLY   26

#include <include/net/socket.h>

sockopt: Don't support IPv4 access (ignored, for compatibility)

◆ NI_DGRAM

#define NI_DGRAM   16

#include <include/net/socket.h>

zsock_getnameinfo(): Dummy option for compatibility

◆ NI_MAXHOST

#define NI_MAXHOST   64

#include <include/net/socket.h>

zsock_getnameinfo(): Max supported hostname length

◆ NI_NAMEREQD

#define NI_NAMEREQD   8

#include <include/net/socket.h>

zsock_getnameinfo(): Dummy option for compatibility

◆ NI_NOFQDN

#define NI_NOFQDN   4

#include <include/net/socket.h>

zsock_getnameinfo(): Return only hostname instead of FQDN

◆ NI_NUMERICHOST

#define NI_NUMERICHOST   1

#include <include/net/socket.h>

zsock_getnameinfo(): Resolve to numeric address.

◆ NI_NUMERICSERV

#define NI_NUMERICSERV   2

#include <include/net/socket.h>

zsock_getnameinfo(): Resolve to numeric port number.

◆ SCM_TXTIME

#define SCM_TXTIME   SO_TXTIME

◆ SO_BINDTODEVICE

#define SO_BINDTODEVICE   25

#include <include/net/socket.h>

sockopt: Bind a socket to an interface

◆ SO_ERROR

#define SO_ERROR   4

#include <include/net/socket.h>

sockopt: Async error (ignored, for compatibility)

◆ SO_PRIORITY

#define SO_PRIORITY   12

#include <include/net/socket.h>

sockopt: Socket priority

◆ SO_PROTOCOL

#define SO_PROTOCOL   38

#include <include/net/socket.h>

sockopt: Protocol used with the socket

◆ SO_RCVTIMEO

#define SO_RCVTIMEO   20

#include <include/net/socket.h>

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

◆ SO_REUSEADDR

#define SO_REUSEADDR   2

#include <include/net/socket.h>

sockopt: Enable server address reuse (ignored, for compatibility)

◆ SO_SNDTIMEO

#define SO_SNDTIMEO   21

#include <include/net/socket.h>

sockopt: Send timeout

◆ SO_SOCKS5

#define SO_SOCKS5   60

#include <include/net/socket.h>

sockopt: Enable SOCKS5 for Socket

◆ SO_TIMESTAMPING

#define SO_TIMESTAMPING   37

#include <include/net/socket.h>

sockopt: Timestamp TX packets

◆ SO_TXTIME

#define SO_TXTIME   61

#include <include/net/socket.h>

sockopt: Socket TX time (when the data should be sent)

◆ SO_TYPE

#define SO_TYPE   3

#include <include/net/socket.h>

sockopt: Type of the socket

◆ SOL_SOCKET

#define SOL_SOCKET   1

#include <include/net/socket.h>

sockopt: Socket-level option

◆ SOL_TLS

#define SOL_TLS   282

#include <include/net/socket.h>

Protocol level for TLS. Here, the same socket protocol level for TLS as in Linux was used.

◆ TCP_NODELAY

#define TCP_NODELAY   1

#include <include/net/socket.h>

sockopt: Disable TCP buffering (ignored, for compatibility)

◆ TLS_DTLS_ROLE_CLIENT

#define TLS_DTLS_ROLE_CLIENT   0

#include <include/net/socket.h>

Client role in a DTLS session.

◆ TLS_DTLS_ROLE_SERVER

#define TLS_DTLS_ROLE_SERVER   1

#include <include/net/socket.h>

Server role in a DTLS session.

◆ TLS_PEER_VERIFY_NONE

#define TLS_PEER_VERIFY_NONE   0

#include <include/net/socket.h>

Peer verification disabled.

◆ TLS_PEER_VERIFY_OPTIONAL

#define TLS_PEER_VERIFY_OPTIONAL   1

#include <include/net/socket.h>

Peer verification optional.

◆ TLS_PEER_VERIFY_REQUIRED

#define TLS_PEER_VERIFY_REQUIRED   2

#include <include/net/socket.h>

Peer verification required.

◆ ZSOCK_FD_SETSIZE

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

#include <include/net/socket_select.h>

Number of file descriptors which can be added to zsock_fd_set

◆ ZSOCK_MSG_DONTWAIT

#define ZSOCK_MSG_DONTWAIT   0x40

#include <include/net/socket.h>

zsock_recv/zsock_send: Override operation to non-blocking

◆ ZSOCK_MSG_PEEK

#define ZSOCK_MSG_PEEK   0x02

#include <include/net/socket.h>

zsock_recv: Read data without removing it from socket input queue

◆ ZSOCK_MSG_TRUNC

#define ZSOCK_MSG_TRUNC   0x20

#include <include/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/net/socket.h>

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

◆ ZSOCK_POLLERR

#define ZSOCK_POLLERR   8

#include <include/net/socket.h>

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

◆ ZSOCK_POLLHUP

#define ZSOCK_POLLHUP   0x10

#include <include/net/socket.h>

zsock_poll: Poll detected closed connection (output value only)

◆ ZSOCK_POLLIN

#define ZSOCK_POLLIN   1

#include <include/net/socket.h>

zsock_poll: Poll for readability

◆ ZSOCK_POLLNVAL

#define ZSOCK_POLLNVAL   0x20

#include <include/net/socket.h>

zsock_poll: Invalid socket (output value only)

◆ ZSOCK_POLLOUT

#define ZSOCK_POLLOUT   4

#include <include/net/socket.h>

zsock_poll: Poll for writability

◆ ZSOCK_POLLPRI

#define ZSOCK_POLLPRI   2

#include <include/net/socket.h>

zsock_poll: Compatibility value, ignored

◆ ZSOCK_SHUT_RD

#define ZSOCK_SHUT_RD   0

#include <include/net/socket.h>

zsock_shutdown: Shut down for reading

◆ ZSOCK_SHUT_RDWR

#define ZSOCK_SHUT_RDWR   2

#include <include/net/socket.h>

zsock_shutdown: Shut down for both reading and writing

◆ ZSOCK_SHUT_WR

#define ZSOCK_SHUT_WR   1

#include <include/net/socket.h>

zsock_shutdown: Shut down for writing

Typedef Documentation

◆ zsock_fd_set

Function Documentation

◆ zsock_accept()

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

#include <include/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:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
* 

◆ zsock_bind()

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

#include <include/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:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
* 

◆ zsock_close()

int zsock_close ( int  sock)

#include <include/net/socket.h>

Close a network socket.

embed:rst:leading-asterisk
* Close a network socket.
* This function is also exposed as ``close()``
* if :kconfig:`CONFIG_NET_SOCKETS_POSIX_NAMES` 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/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:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
* 

◆ zsock_fcntl()

int zsock_fcntl ( int  sock,
int  cmd,
int  flags 
)

#include <include/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:`CONFIG_NET_SOCKETS_POSIX_NAMES` 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/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:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
* 

◆ ZSOCK_FD_ISSET()

int ZSOCK_FD_ISSET ( int  fd,
zsock_fd_set set 
)

#include <include/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:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
* 

◆ ZSOCK_FD_SET()

void ZSOCK_FD_SET ( int  fd,
zsock_fd_set set 
)

#include <include/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:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
* 

◆ ZSOCK_FD_ZERO()

void ZSOCK_FD_ZERO ( zsock_fd_set set)

#include <include/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:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
* 

◆ zsock_freeaddrinfo()

void zsock_freeaddrinfo ( struct zsock_addrinfo ai)

#include <include/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:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
* 

◆ zsock_gai_strerror()

const char * zsock_gai_strerror ( int  errcode)

#include <include/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:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
* 

◆ zsock_get_context_object()

void * zsock_get_context_object ( int  sock)

#include <include/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/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:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
* 

◆ zsock_gethostname()

int zsock_gethostname ( char *  buf,
size_t  len 
)

#include <include/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:`CONFIG_NET_SOCKETS_POSIX_NAMES` 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/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:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
* 

◆ zsock_getsockname()

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

#include <include/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:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
* 

◆ zsock_getsockopt()

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

#include <include/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:`CONFIG_NET_SOCKETS_POSIX_NAMES` 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/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:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
* 

◆ zsock_inet_pton()

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

#include <include/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:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
* 

◆ zsock_listen()

int zsock_listen ( int  sock,
int  backlog 
)

#include <include/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:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
* 

◆ zsock_poll()

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

#include <include/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. (In Zephyr this function works only with
* sockets, not arbitrary file descriptors.)
* This function is also exposed as ``poll()``
* if :kconfig:`CONFIG_NET_SOCKETS_POSIX_NAMES` 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/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:`CONFIG_NET_SOCKETS_POSIX_NAMES` 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/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:`CONFIG_NET_SOCKETS_POSIX_NAMES` 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/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 :c:func:`zsock_poll()` instead. In Zephyr this function works only with
* sockets, not arbitrary file descriptors.
* This function is also exposed as ``select()``
* if :kconfig:`CONFIG_NET_SOCKETS_POSIX_NAMES` 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/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:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
* 

◆ zsock_sendmsg()

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

#include <include/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:`CONFIG_NET_SOCKETS_POSIX_NAMES` 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/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:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
* 

◆ zsock_setsockopt()

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

#include <include/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:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
* 

◆ zsock_shutdown()

int zsock_shutdown ( int  sock,
int  how 
)

#include <include/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:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
* 

◆ zsock_socket()

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

#include <include/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:`CONFIG_NET_SOCKETS_POSIX_NAMES` 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/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:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
*