Zephyr Project API  3.3.0
A Scalable Open Source RTOS
socket.h File Reference

BSD Sockets compatible API definitions. More...

#include <sys/types.h>
#include <zephyr/types.h>
#include <zephyr/net/net_ip.h>
#include <zephyr/net/dns_resolve.h>
#include <zephyr/net/socket_select.h>
#include <stdlib.h>
#include <syscalls/socket.h>

Go to the source code of this file.

Data Structures

struct  zsock_pollfd
 
struct  zsock_addrinfo
 
struct  ifreq
 

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_SEC_TAG_LIST   1
 
#define TLS_HOSTNAME   2
 
#define TLS_CIPHERSUITE_LIST   3
 
#define TLS_CIPHERSUITE_USED   4
 
#define TLS_PEER_VERIFY   5
 
#define TLS_DTLS_ROLE   6
 
#define TLS_ALPN_LIST   7
 
#define TLS_DTLS_HANDSHAKE_TIMEOUT_MIN   8
 
#define TLS_DTLS_HANDSHAKE_TIMEOUT_MAX   9
 
#define TLS_CERT_NOCOPY   10
 
#define TLS_NATIVE   11
 
#define TLS_SESSION_CACHE   12
 
#define TLS_SESSION_CACHE_PURGE   13
 
#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 TLS_CERT_NOCOPY_NONE   0
 
#define TLS_CERT_NOCOPY_OPTIONAL   1
 
#define TLS_SESSION_CACHE_DISABLED   0
 
#define TLS_SESSION_CACHE_ENABLED   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 pollfd   zsock_pollfd
 
#define fcntl   zsock_fcntl_wrapper
 
#define addrinfo   zsock_addrinfo
 
#define POLLIN   ZSOCK_POLLIN
 
#define POLLOUT   ZSOCK_POLLOUT
 
#define POLLERR   ZSOCK_POLLERR
 
#define POLLHUP   ZSOCK_POLLHUP
 
#define POLLNVAL   ZSOCK_POLLNVAL
 
#define MSG_PEEK   ZSOCK_MSG_PEEK
 
#define MSG_TRUNC   ZSOCK_MSG_TRUNC
 
#define MSG_DONTWAIT   ZSOCK_MSG_DONTWAIT
 
#define MSG_WAITALL   ZSOCK_MSG_WAITALL
 
#define SHUT_RD   ZSOCK_SHUT_RD
 
#define SHUT_WR   ZSOCK_SHUT_WR
 
#define SHUT_RDWR   ZSOCK_SHUT_RDWR
 
#define EAI_BADFLAGS   DNS_EAI_BADFLAGS
 
#define EAI_NONAME   DNS_EAI_NONAME
 
#define EAI_AGAIN   DNS_EAI_AGAIN
 
#define EAI_FAIL   DNS_EAI_FAIL
 
#define EAI_NODATA   DNS_EAI_NODATA
 
#define EAI_MEMORY   DNS_EAI_MEMORY
 
#define EAI_SYSTEM   DNS_EAI_SYSTEM
 
#define EAI_SERVICE   DNS_EAI_SERVICE
 
#define EAI_SOCKTYPE   DNS_EAI_SOCKTYPE
 
#define EAI_FAMILY   DNS_EAI_FAMILY
 
#define IFNAMSIZ   Z_DEVICE_MAX_NAME_LEN
 
#define SOL_SOCKET   1
 
#define SO_DEBUG   1
 
#define SO_REUSEADDR   2
 
#define SO_TYPE   3
 
#define SO_ERROR   4
 
#define SO_DONTROUTE   5
 
#define SO_BROADCAST   6
 
#define SO_SNDBUF   7
 
#define SO_RCVBUF   8
 
#define SO_KEEPALIVE   9
 
#define SO_OOBINLINE   10
 
#define SO_LINGER   13
 
#define SO_REUSEPORT   15
 
#define SO_RCVLOWAT   18
 
#define SO_SNDLOWAT   19
 
#define SO_RCVTIMEO   20
 
#define SO_SNDTIMEO   21
 
#define SO_BINDTODEVICE   25
 
#define SO_ACCEPTCONN   30
 
#define SO_TIMESTAMPING   37
 
#define SO_PROTOCOL   38
 
#define SO_DOMAIN   39
 
#define TCP_NODELAY   1
 
#define IP_TOS   1
 
#define IPV6_V6ONLY   26
 
#define IPV6_TCLASS   67
 
#define SO_PRIORITY   12
 
#define SO_TXTIME   61
 
#define SCM_TXTIME   SO_TXTIME
 
#define SO_SOCKS5   60
 
#define SOMAXCONN   128
 

Functions

void * zsock_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_getpeername (int sock, struct sockaddr *addr, socklen_t *addrlen)
 Get peer name. 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...
 
static int socket (int family, int type, int proto)
 
static int socketpair (int family, int type, int proto, int sv[2])
 
static int close (int sock)
 
static int shutdown (int sock, int how)
 
static int bind (int sock, const struct sockaddr *addr, socklen_t addrlen)
 
static int connect (int sock, const struct sockaddr *addr, socklen_t addrlen)
 
static int listen (int sock, int backlog)
 
static int accept (int sock, struct sockaddr *addr, socklen_t *addrlen)
 
static ssize_t send (int sock, const void *buf, size_t len, int flags)
 
static ssize_t recv (int sock, void *buf, size_t max_len, int flags)
 
static int zsock_fcntl_wrapper (int sock, int cmd,...)
 
static ssize_t sendto (int sock, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen)
 
static ssize_t sendmsg (int sock, const struct msghdr *message, int flags)
 
static ssize_t recvfrom (int sock, void *buf, size_t max_len, int flags, struct sockaddr *src_addr, socklen_t *addrlen)
 
static int poll (struct zsock_pollfd *fds, int nfds, int timeout)
 
static int getsockopt (int sock, int level, int optname, void *optval, socklen_t *optlen)
 
static int setsockopt (int sock, int level, int optname, const void *optval, socklen_t optlen)
 
static int getpeername (int sock, struct sockaddr *addr, socklen_t *addrlen)
 
static int getsockname (int sock, struct sockaddr *addr, socklen_t *addrlen)
 
static int getaddrinfo (const char *host, const char *service, const struct zsock_addrinfo *hints, struct zsock_addrinfo **res)
 
static void freeaddrinfo (struct zsock_addrinfo *ai)
 
static const char * gai_strerror (int errcode)
 
static int getnameinfo (const struct sockaddr *addr, socklen_t addrlen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, int flags)
 
static int gethostname (char *buf, size_t len)
 
static int inet_pton (sa_family_t family, const char *src, void *dst)
 
static char * inet_ntop (sa_family_t family, const void *src, char *dst, size_t size)
 

Detailed Description

BSD Sockets compatible API definitions.

An API for applications to use BSD Sockets like API.