15#ifndef ZEPHYR_INCLUDE_NET_SOCKET_H_
16#define ZEPHYR_INCLUDE_NET_SOCKET_H_
51#define ZSOCK_POLLPRI 2
53#define ZSOCK_POLLOUT 4
55#define ZSOCK_POLLERR 8
57#define ZSOCK_POLLHUP 0x10
59#define ZSOCK_POLLNVAL 0x20
67#define ZSOCK_MSG_PEEK 0x02
70#define ZSOCK_MSG_CTRUNC 0x08
74#define ZSOCK_MSG_TRUNC 0x20
76#define ZSOCK_MSG_DONTWAIT 0x40
78#define ZSOCK_MSG_WAITALL 0x100
90#define ZSOCK_SHUT_RD 0
92#define ZSOCK_SHUT_WR 1
94#define ZSOCK_SHUT_RDWR 2
117#define TLS_SEC_TAG_LIST 1
122#define TLS_HOSTNAME 2
128#define TLS_CIPHERSUITE_LIST 3
133#define TLS_CIPHERSUITE_USED 4
144#define TLS_PEER_VERIFY 5
153#define TLS_DTLS_ROLE 6
159#define TLS_ALPN_LIST 7
164#define TLS_DTLS_HANDSHAKE_TIMEOUT_MIN 8
170#define TLS_DTLS_HANDSHAKE_TIMEOUT_MAX 9
176#define TLS_CERT_NOCOPY 10
192#define TLS_SESSION_CACHE 12
196#define TLS_SESSION_CACHE_PURGE 13
208#define TLS_DTLS_CID 14
218#define TLS_DTLS_CID_STATUS 15
223#define TLS_DTLS_CID_VALUE 16
230#define TLS_DTLS_PEER_CID_VALUE 17
238#define TLS_DTLS_HANDSHAKE_ON_CONNECT 18
241#define TLS_PEER_VERIFY_NONE 0
242#define TLS_PEER_VERIFY_OPTIONAL 1
243#define TLS_PEER_VERIFY_REQUIRED 2
246#define TLS_DTLS_ROLE_CLIENT 0
247#define TLS_DTLS_ROLE_SERVER 1
250#define TLS_CERT_NOCOPY_NONE 0
251#define TLS_CERT_NOCOPY_OPTIONAL 1
254#define TLS_SESSION_CACHE_DISABLED 0
255#define TLS_SESSION_CACHE_ENABLED 1
258#define TLS_DTLS_CID_DISABLED 0
259#define TLS_DTLS_CID_SUPPORTED 1
260#define TLS_DTLS_CID_ENABLED 2
263#define TLS_DTLS_CID_STATUS_DISABLED 0
264#define TLS_DTLS_CID_STATUS_DOWNLINK 1
265#define TLS_DTLS_CID_STATUS_UPLINK 2
266#define TLS_DTLS_CID_STATUS_BIDIRECTIONAL 3
537static inline int zsock_fcntl_wrapper(
int sock,
int cmd, ...)
543 flags = va_arg(args,
int);
548#define zsock_fcntl zsock_fcntl_wrapper
571static inline int zsock_ioctl_wrapper(
int sock,
unsigned long request, ...)
576 va_start(args, request);
583#define zsock_ioctl zsock_ioctl_wrapper
684 char *dst,
size_t size)
702__syscall
int z_zsock_getaddrinfo_internal(
const char *host,
715#define AI_PASSIVE 0x1
717#define AI_CANONNAME 0x2
719#define AI_NUMERICHOST 0x4
721#define AI_V4MAPPED 0x8
725#define AI_ADDRCONFIG 0x20
727#define AI_NUMERICSERV 0x400
729#define AI_EXTFLAGS 0x800
775#define NI_NUMERICHOST 1
777#define NI_NUMERICSERV 2
807#if defined(CONFIG_NET_SOCKETS_POSIX_NAMES)
815#define pollfd zsock_pollfd
818static inline int socket(
int family,
int type,
int proto)
824static inline int socketpair(
int family,
int type,
int proto,
int sv[2])
855static inline int listen(
int sock,
int backlog)
913static inline int getsockopt(
int sock,
int level,
int optname,
920static inline int setsockopt(
int sock,
int level,
int optname,
941static inline int getaddrinfo(
const char *host,
const char *service,
966 serv, servlen,
flags);
970#define addrinfo zsock_addrinfo
992#define POLLIN ZSOCK_POLLIN
994#define POLLOUT ZSOCK_POLLOUT
996#define POLLERR ZSOCK_POLLERR
998#define POLLHUP ZSOCK_POLLHUP
1000#define POLLNVAL ZSOCK_POLLNVAL
1003#define MSG_PEEK ZSOCK_MSG_PEEK
1005#define MSG_CTRUNC ZSOCK_MSG_CTRUNC
1007#define MSG_TRUNC ZSOCK_MSG_TRUNC
1009#define MSG_DONTWAIT ZSOCK_MSG_DONTWAIT
1011#define MSG_WAITALL ZSOCK_MSG_WAITALL
1014#define SHUT_RD ZSOCK_SHUT_RD
1016#define SHUT_WR ZSOCK_SHUT_WR
1018#define SHUT_RDWR ZSOCK_SHUT_RDWR
1021#define EAI_BADFLAGS DNS_EAI_BADFLAGS
1023#define EAI_NONAME DNS_EAI_NONAME
1025#define EAI_AGAIN DNS_EAI_AGAIN
1027#define EAI_FAIL DNS_EAI_FAIL
1029#define EAI_NODATA DNS_EAI_NODATA
1031#define EAI_MEMORY DNS_EAI_MEMORY
1033#define EAI_SYSTEM DNS_EAI_SYSTEM
1035#define EAI_SERVICE DNS_EAI_SERVICE
1037#define EAI_SOCKTYPE DNS_EAI_SOCKTYPE
1039#define EAI_FAMILY DNS_EAI_FAMILY
1048#if defined(CONFIG_NET_INTERFACE_NAME)
1049#define IFNAMSIZ CONFIG_NET_INTERFACE_NAME_LEN
1051#define IFNAMSIZ Z_DEVICE_MAX_NAME_LEN
1072#define SO_REUSEADDR 2
1078#define SO_DONTROUTE 5
1080#define SO_BROADCAST 6
1088#define SO_KEEPALIVE 9
1090#define SO_OOBINLINE 10
1092#define SO_PRIORITY 12
1096#define SO_REUSEPORT 15
1099#define SO_RCVLOWAT 18
1101#define SO_SNDLOWAT 19
1107#define SO_RCVTIMEO 20
1109#define SO_SNDTIMEO 21
1112#define SO_BINDTODEVICE 25
1115#define SO_ACCEPTCONN 30
1118#define SO_TIMESTAMPING 37
1121#define SO_PROTOCOL 38
1132#define SCM_TXTIME SO_TXTIME
1137#define SOF_TIMESTAMPING_RX_HARDWARE BIT(0)
1142#define SOF_TIMESTAMPING_TX_HARDWARE BIT(1)
1154#define TCP_NODELAY 1
1156#define TCP_KEEPIDLE 2
1158#define TCP_KEEPINTVL 3
1160#define TCP_KEEPCNT 4
1194#define IP_MULTICAST_TTL 33
1196#define IP_ADD_MEMBERSHIP 35
1198#define IP_DROP_MEMBERSHIP 36
1217#define IPV6_UNICAST_HOPS 16
1220#define IPV6_MULTICAST_HOPS 18
1223#define IPV6_ADD_MEMBERSHIP 20
1226#define IPV6_DROP_MEMBERSHIP 21
1240#define IPV6_V6ONLY 26
1246#define IPV6_RECVPKTINFO 49
1249#define IPV6_ADDR_PREFERENCES 72
1252#define IPV6_PREFER_SRC_TMP 0x0001
1254#define IPV6_PREFER_SRC_PUBLIC 0x0002
1259#define IPV6_PREFER_SRC_PUBTMP_DEFAULT 0x0100
1261#define IPV6_PREFER_SRC_COA 0x0004
1263#define IPV6_PREFER_SRC_HOME 0x0400
1265#define IPV6_PREFER_SRC_CGA 0x0008
1267#define IPV6_PREFER_SRC_NONCGA 0x0800
1281#define IPV6_TCLASS 67
1289#define SOMAXCONN 128
1296struct net_socket_register {
1299 bool (*is_supported)(
int family,
int type,
int proto);
1300 int (*handler)(
int family,
int type,
int proto);
1301#if defined(CONFIG_NET_SOCKETS_OBJ_CORE)
1305 const char *
const name;
1309#define NET_SOCKET_DEFAULT_PRIO CONFIG_NET_SOCKETS_PRIORITY_DEFAULT
1311#define NET_SOCKET_GET_NAME(socket_name, prio) \
1312 __net_socket_register_##prio##_##socket_name
1314#if defined(CONFIG_NET_SOCKETS_OBJ_CORE)
1315#define K_OBJ_TYPE_SOCK K_OBJ_TYPE_ID_GEN("SOCK")
1317#define NET_SOCKET_REGISTER_NAME(_name) \
1318 .name = STRINGIFY(_name),
1320#define NET_SOCKET_REGISTER_NAME(_name)
1323#define _NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler, _is_offloaded) \
1324 static const STRUCT_SECTION_ITERABLE(net_socket_register, \
1325 NET_SOCKET_GET_NAME(socket_name, prio)) = { \
1326 .family = _family, \
1327 .is_offloaded = _is_offloaded, \
1328 .is_supported = _is_supported, \
1329 .handler = _handler, \
1330 NET_SOCKET_REGISTER_NAME(socket_name) \
1333#define NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler) \
1334 _NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler, false)
1336#define NET_SOCKET_OFFLOAD_REGISTER(socket_name, prio, _family, _is_supported, _handler) \
1337 _NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler, true)
1345#include <zephyr/syscalls/socket.h>
1361#if defined(CONFIG_POSIX_API)
1362#if !defined(ZEPHYR_INCLUDE_POSIX_ARPA_INET_H_)
1365#if !defined(ZEPHYR_INCLUDE_POSIX_NETDB_H_)
1368#if !defined(ZEPHYR_INCLUDE_POSIX_UNISTD_H_)
1371#if !defined(ZEPHYR_INCLUDE_POSIX_POLL_H_)
1374#if !defined(ZEPHYR_INCLUDE_POSIX_SYS_SOCKET_H_)
int zvfs_poll(struct zvfs_pollfd *fds, int nfds, int poll_timeout)
static int socket(int family, int type, int proto)
POSIX wrapper for zsock_socket.
Definition socket.h:818
int zsock_ioctl_impl(int sock, unsigned long request, va_list ap)
Control underlying socket parameters.
static int getpeername(int sock, struct sockaddr *addr, socklen_t *addrlen)
POSIX wrapper for zsock_getpeername.
Definition socket.h:927
int zsock_getpeername(int sock, struct sockaddr *addr, socklen_t *addrlen)
Get peer name.
static int getaddrinfo(const char *host, const char *service, const struct zsock_addrinfo *hints, struct zsock_addrinfo **res)
POSIX wrapper for zsock_getaddrinfo.
Definition socket.h:941
static int bind(int sock, const struct sockaddr *addr, socklen_t addrlen)
POSIX wrapper for zsock_bind.
Definition socket.h:842
static int gethostname(char *buf, size_t len)
POSIX wrapper for zsock_gethostname.
Definition socket.h:973
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.
int zsock_connect(int sock, const struct sockaddr *addr, socklen_t addrlen)
Connect a socket to a peer network address.
static ssize_t sendmsg(int sock, const struct msghdr *message, int flags)
POSIX wrapper for zsock_sendmsg.
Definition socket.h:887
int zsock_socketpair(int family, int type, int proto, int *sv)
Create an unnamed pair of connected sockets.
void * zsock_get_context_object(int sock)
Obtain a file descriptor's associated net context.
int zsock_accept(int sock, struct sockaddr *addr, socklen_t *addrlen)
Accept a connection on listening socket.
static int inet_pton(sa_family_t family, const char *src, void *dst)
POSIX wrapper for zsock_inet_pton.
Definition socket.h:979
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.
Definition socket.h:894
static ssize_t zsock_send(int sock, const void *buf, size_t len, int flags)
Send data to a connected peer.
Definition socket.h:458
static int getsockopt(int sock, int level, int optname, void *optval, socklen_t *optlen)
POSIX wrapper for zsock_getsockopt.
Definition socket.h:913
static int accept(int sock, struct sockaddr *addr, socklen_t *addrlen)
POSIX wrapper for zsock_accept.
Definition socket.h:861
static int listen(int sock, int backlog)
POSIX wrapper for zsock_listen.
Definition socket.h:855
static int close(int sock)
POSIX wrapper for zsock_close.
Definition socket.h:830
int zsock_bind(int sock, const struct sockaddr *addr, socklen_t addrlen)
Bind a socket to a local network address.
static int zsock_poll(struct zsock_pollfd *fds, int nfds, int timeout)
Efficiently poll multiple sockets for events.
Definition socket.h:598
int zsock_socket(int family, int type, int proto)
Create a network socket.
int zsock_getsockopt(int sock, int level, int optname, void *optval, socklen_t *optlen)
Get various socket options.
static ssize_t recvmsg(int sock, struct msghdr *msg, int flags)
POSIX wrapper for zsock_recvmsg.
Definition socket.h:901
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.
Definition socket.h:961
void zsock_freeaddrinfo(struct zsock_addrinfo *ai)
Free results returned by zsock_getaddrinfo()
static ssize_t zsock_recv(int sock, void *buf, size_t max_len, int flags)
Receive data from a connected peer.
Definition socket.h:513
int zsock_gethostname(char *buf, size_t len)
Get local host name.
static int setsockopt(int sock, int level, int optname, const void *optval, socklen_t optlen)
POSIX wrapper for zsock_setsockopt.
Definition socket.h:920
int zsock_getsockname(int sock, struct sockaddr *addr, socklen_t *addrlen)
Get socket name.
static int getsockname(int sock, struct sockaddr *addr, socklen_t *addrlen)
POSIX wrapper for zsock_getsockname.
Definition socket.h:934
const char * zsock_gai_strerror(int errcode)
Convert zsock_getaddrinfo() error code to textual message.
int zsock_fcntl_impl(int sock, int cmd, int flags)
Control blocking/non-blocking mode of a socket.
static const char * gai_strerror(int errcode)
POSIX wrapper for zsock_gai_strerror.
Definition socket.h:955
int zsock_shutdown(int sock, int how)
Shutdown socket send/receive operations.
ssize_t zsock_recvmsg(int sock, struct msghdr *msg, int flags)
Receive a message from 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.
#define IFNAMSIZ
Network interface name length.
Definition socket.h:1051
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.
Definition socket.h:879
int zsock_setsockopt(int sock, int level, int optname, const void *optval, socklen_t optlen)
Set various socket options.
static ssize_t send(int sock, const void *buf, size_t len, int flags)
POSIX wrapper for zsock_send.
Definition socket.h:867
static int socketpair(int family, int type, int proto, int sv[2])
POSIX wrapper for zsock_socketpair.
Definition socket.h:824
ssize_t zsock_sendmsg(int sock, const struct msghdr *msg, int flags)
Send data to an arbitrary network address.
static int connect(int sock, const struct sockaddr *addr, socklen_t addrlen)
POSIX wrapper for zsock_connect.
Definition socket.h:848
static ssize_t recv(int sock, void *buf, size_t max_len, int flags)
POSIX wrapper for zsock_recv.
Definition socket.h:873
static int poll(struct zsock_pollfd *fds, int nfds, int timeout)
POSIX wrapper for zsock_poll.
Definition socket.h:907
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.
Definition socket.h:683
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_close(int sock)
Close a network socket.
int zsock_listen(int sock, int backlog)
Set up a STREAM socket to accept peer connections.
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.
static char * inet_ntop(sa_family_t family, const void *src, char *dst, size_t size)
POSIX wrapper for zsock_inet_ntop.
Definition socket.h:985
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.
static void freeaddrinfo(struct zsock_addrinfo *ai)
POSIX wrapper for zsock_freeaddrinfo.
Definition socket.h:949
static int shutdown(int sock, int how)
POSIX wrapper for zsock_shutdown.
Definition socket.h:836
#define DNS_MAX_NAME_SIZE
Max size of the resolved name.
Definition dns_resolve.h:46
static void cmd(uint32_t command)
Execute a display list command by co-processor engine.
Definition ft8xx_reference_api.h:153
unsigned short int sa_family_t
Socket address family type.
Definition net_ip.h:167
char * net_addr_ntop(sa_family_t family, const void *src, char *dst, size_t size)
Convert IP address to string form.
size_t socklen_t
Length of a socket address.
Definition net_ip.h:171
__SIZE_TYPE__ ssize_t
Definition types.h:28
IPv6 and IPv4 definitions.
flags
Definition parser.h:96
BSD select support functions.
#define bool
Definition stdbool.h:13
Interface description structure.
Definition socket.h:1055
char ifr_name[Z_DEVICE_MAX_NAME_LEN]
Network interface name.
Definition socket.h:1056
IPv6 address struct.
Definition net_ip.h:142
Incoming IPv6 packet information.
Definition socket.h:1275
struct in6_addr ipi6_addr
Destination IPv6 address.
Definition socket.h:1276
unsigned int ipi6_ifindex
Receive interface index.
Definition socket.h:1277
IPv4 address struct.
Definition net_ip.h:154
Incoming IPv4 packet information.
Definition socket.h:1187
unsigned int ipi_ifindex
Network interface index.
Definition socket.h:1188
struct in_addr ipi_spec_dst
Local address.
Definition socket.h:1189
struct in_addr ipi_addr
Header Destination address.
Definition socket.h:1190
Struct used when joining or leaving a IPv4 multicast group.
Definition socket.h:1203
int imr_ifindex
Network interface index.
Definition socket.h:1206
struct in_addr imr_multiaddr
IP multicast group address.
Definition socket.h:1204
struct in_addr imr_address
IP address of local interface.
Definition socket.h:1205
Struct used when joining or leaving a IPv6 multicast group.
Definition socket.h:1231
struct in6_addr ipv6mr_multiaddr
IPv6 multicast address of group.
Definition socket.h:1233
int ipv6mr_ifindex
Network interface index of the local IPv6 address.
Definition socket.h:1236
Message struct.
Definition net_ip.h:250
Generic sockaddr struct.
Definition net_ip.h:388
Definition used when querying address information.
Definition socket.h:276
struct zsock_addrinfo * ai_next
Pointer to next address entry.
Definition socket.h:277
int ai_family
Address family of the returned addresses.
Definition socket.h:279
int ai_flags
Additional options.
Definition socket.h:278
char * ai_canonname
Optional official name of the host.
Definition socket.h:285
int ai_protocol
Protocol for addresses, 0 means any protocol.
Definition socket.h:281
struct sockaddr * ai_addr
Pointer to the address.
Definition socket.h:284
int ai_socktype
Socket type, for example SOCK_STREAM or SOCK_DGRAM.
Definition socket.h:280
int ai_eflags
Extended flags for special usage.
Definition socket.h:282
socklen_t ai_addrlen
Length of the socket address.
Definition socket.h:283
Definition of the monitored socket/file descriptor.
Definition socket_poll.h:31