Zephyr API 3.6.99
Loading...
Searching...
No Matches
socket.h
Go to the documentation of this file.
1
8/*
9 * Copyright (c) 2017-2018 Linaro Limited
10 * Copyright (c) 2021 Nordic Semiconductor
11 *
12 * SPDX-License-Identifier: Apache-2.0
13 */
14
15#ifndef ZEPHYR_INCLUDE_NET_SOCKET_H_
16#define ZEPHYR_INCLUDE_NET_SOCKET_H_
17
27#include <zephyr/kernel.h>
28#include <sys/types.h>
29#include <zephyr/types.h>
30#include <zephyr/device.h>
31#include <zephyr/net/net_ip.h>
35#include <zephyr/sys/fdtable.h>
38#include <stdlib.h>
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
48/* ZSOCK_POLL* values are compatible with Linux */
50#define ZSOCK_POLLIN 1
52#define ZSOCK_POLLPRI 2
54#define ZSOCK_POLLOUT 4
56#define ZSOCK_POLLERR 8
58#define ZSOCK_POLLHUP 0x10
60#define ZSOCK_POLLNVAL 0x20
68#define ZSOCK_MSG_PEEK 0x02
71#define ZSOCK_MSG_CTRUNC 0x08
75#define ZSOCK_MSG_TRUNC 0x20
77#define ZSOCK_MSG_DONTWAIT 0x40
79#define ZSOCK_MSG_WAITALL 0x100
86/* Well-known values, e.g. from Linux man 2 shutdown:
87 * "The constants SHUT_RD, SHUT_WR, SHUT_RDWR have the value 0, 1, 2,
88 * respectively". Some software uses numeric values.
89 */
91#define ZSOCK_SHUT_RD 0
93#define ZSOCK_SHUT_WR 1
95#define ZSOCK_SHUT_RDWR 2
112#define SOL_TLS 282
113
118#define TLS_SEC_TAG_LIST 1
123#define TLS_HOSTNAME 2
129#define TLS_CIPHERSUITE_LIST 3
134#define TLS_CIPHERSUITE_USED 4
145#define TLS_PEER_VERIFY 5
154#define TLS_DTLS_ROLE 6
160#define TLS_ALPN_LIST 7
165#define TLS_DTLS_HANDSHAKE_TIMEOUT_MIN 8
166
171#define TLS_DTLS_HANDSHAKE_TIMEOUT_MAX 9
172
177#define TLS_CERT_NOCOPY 10
188#define TLS_NATIVE 11
193#define TLS_SESSION_CACHE 12
197#define TLS_SESSION_CACHE_PURGE 13
209#define TLS_DTLS_CID 14
219#define TLS_DTLS_CID_STATUS 15
224#define TLS_DTLS_CID_VALUE 16
231#define TLS_DTLS_PEER_CID_VALUE 17
239#define TLS_DTLS_HANDSHAKE_ON_CONNECT 18
240
241/* Valid values for @ref TLS_PEER_VERIFY option */
242#define TLS_PEER_VERIFY_NONE 0
243#define TLS_PEER_VERIFY_OPTIONAL 1
244#define TLS_PEER_VERIFY_REQUIRED 2
246/* Valid values for @ref TLS_DTLS_ROLE option */
247#define TLS_DTLS_ROLE_CLIENT 0
248#define TLS_DTLS_ROLE_SERVER 1
250/* Valid values for @ref TLS_CERT_NOCOPY option */
251#define TLS_CERT_NOCOPY_NONE 0
252#define TLS_CERT_NOCOPY_OPTIONAL 1
254/* Valid values for @ref TLS_SESSION_CACHE option */
255#define TLS_SESSION_CACHE_DISABLED 0
256#define TLS_SESSION_CACHE_ENABLED 1
258/* Valid values for @ref TLS_DTLS_CID (Connection ID) option */
259#define TLS_DTLS_CID_DISABLED 0
260#define TLS_DTLS_CID_SUPPORTED 1
261#define TLS_DTLS_CID_ENABLED 2
263/* Valid values for @ref TLS_DTLS_CID_STATUS option */
264#define TLS_DTLS_CID_STATUS_DISABLED 0
265#define TLS_DTLS_CID_STATUS_DOWNLINK 1
266#define TLS_DTLS_CID_STATUS_UPLINK 2
267#define TLS_DTLS_CID_STATUS_BIDIRECTIONAL 3
268 /* for @name */
269 /* for @defgroup */
270
289 struct sockaddr _ai_addr;
290 char _ai_canonname[DNS_MAX_NAME_SIZE + 1];
292};
293
330__syscall void *zsock_get_context_object(int sock);
331
347__syscall int zsock_socket(int family, int type, int proto);
348
359__syscall int zsock_socketpair(int family, int type, int proto, int *sv);
360
370__syscall int zsock_close(int sock);
371
383__syscall int zsock_shutdown(int sock, int how);
384
395__syscall int zsock_bind(int sock, const struct sockaddr *addr,
396 socklen_t addrlen);
397
408__syscall int zsock_connect(int sock, const struct sockaddr *addr,
409 socklen_t addrlen);
410
421__syscall int zsock_listen(int sock, int backlog);
422
433__syscall int zsock_accept(int sock, struct sockaddr *addr, socklen_t *addrlen);
434
445__syscall ssize_t zsock_sendto(int sock, const void *buf, size_t len,
446 int flags, const struct sockaddr *dest_addr,
447 socklen_t addrlen);
448
459static inline ssize_t zsock_send(int sock, const void *buf, size_t len,
460 int flags)
461{
462 return zsock_sendto(sock, buf, len, flags, NULL, 0);
463}
464
475__syscall ssize_t zsock_sendmsg(int sock, const struct msghdr *msg,
476 int flags);
477
488__syscall ssize_t zsock_recvfrom(int sock, void *buf, size_t max_len,
489 int flags, struct sockaddr *src_addr,
490 socklen_t *addrlen);
491
502__syscall ssize_t zsock_recvmsg(int sock, struct msghdr *msg, int flags);
503
514static inline ssize_t zsock_recv(int sock, void *buf, size_t max_len,
515 int flags)
516{
517 return zsock_recvfrom(sock, buf, max_len, flags, NULL, NULL);
518}
519
530__syscall int zsock_fcntl_impl(int sock, int cmd, int flags);
531
534/*
535 * Need this wrapper because newer GCC versions got too smart and "typecheck"
536 * even macros.
537 */
538static inline int zsock_fcntl_wrapper(int sock, int cmd, ...)
539{
540 va_list args;
541 int flags;
542
543 va_start(args, cmd);
544 flags = va_arg(args, int);
545 va_end(args);
546 return zsock_fcntl_impl(sock, cmd, flags);
547}
548
549#define zsock_fcntl zsock_fcntl_wrapper
550
568__syscall int zsock_ioctl_impl(int sock, unsigned long request, va_list ap);
569
572static inline int zsock_ioctl_wrapper(int sock, unsigned long request, ...)
573{
574 int ret;
575 va_list args;
576
577 va_start(args, request);
578 ret = zsock_ioctl_impl(sock, request, args);
579 va_end(args);
580
581 return ret;
582}
583
584#define zsock_ioctl zsock_ioctl_wrapper
585
599__syscall int zsock_poll(struct zsock_pollfd *fds, int nfds, int timeout);
600
614__syscall int zsock_getsockopt(int sock, int level, int optname,
615 void *optval, socklen_t *optlen);
616
630__syscall int zsock_setsockopt(int sock, int level, int optname,
631 const void *optval, socklen_t optlen);
632
643__syscall int zsock_getpeername(int sock, struct sockaddr *addr,
644 socklen_t *addrlen);
645
656__syscall int zsock_getsockname(int sock, struct sockaddr *addr,
657 socklen_t *addrlen);
658
669__syscall int zsock_gethostname(char *buf, size_t len);
670
681static inline char *zsock_inet_ntop(sa_family_t family, const void *src,
682 char *dst, size_t size)
683{
684 return net_addr_ntop(family, src, dst, size);
685}
686
697__syscall int zsock_inet_pton(sa_family_t family, const char *src, void *dst);
698
700__syscall int z_zsock_getaddrinfo_internal(const char *host,
701 const char *service,
702 const struct zsock_addrinfo *hints,
703 struct zsock_addrinfo *res);
706/* Flags for getaddrinfo() hints. */
707
713#define AI_PASSIVE 0x1
715#define AI_CANONNAME 0x2
717#define AI_NUMERICHOST 0x4
719#define AI_V4MAPPED 0x8
721#define AI_ALL 0x10
723#define AI_ADDRCONFIG 0x20
725#define AI_NUMERICSERV 0x400
727#define AI_EXTFLAGS 0x800
740int zsock_getaddrinfo(const char *host, const char *service,
741 const struct zsock_addrinfo *hints,
742 struct zsock_addrinfo **res);
743
755
766const char *zsock_gai_strerror(int errcode);
767
773#define NI_NUMERICHOST 1
775#define NI_NUMERICSERV 2
777#define NI_NOFQDN 4
779#define NI_NAMEREQD 8
781#define NI_DGRAM 16
782
783/* POSIX extensions */
784
786#ifndef NI_MAXHOST
787#define NI_MAXHOST 64
788#endif
801int zsock_getnameinfo(const struct sockaddr *addr, socklen_t addrlen,
802 char *host, socklen_t hostlen,
803 char *serv, socklen_t servlen, int flags);
804
805#if defined(CONFIG_NET_SOCKETS_POSIX_NAMES)
806
813#define pollfd zsock_pollfd
814
816static inline int socket(int family, int type, int proto)
817{
818 return zsock_socket(family, type, proto);
819}
820
822static inline int socketpair(int family, int type, int proto, int sv[2])
823{
824 return zsock_socketpair(family, type, proto, sv);
825}
826
828static inline int close(int sock)
829{
830 return zsock_close(sock);
831}
832
834static inline int shutdown(int sock, int how)
835{
836 return zsock_shutdown(sock, how);
837}
838
840static inline int bind(int sock, const struct sockaddr *addr, socklen_t addrlen)
841{
842 return zsock_bind(sock, addr, addrlen);
843}
844
846static inline int connect(int sock, const struct sockaddr *addr,
847 socklen_t addrlen)
848{
849 return zsock_connect(sock, addr, addrlen);
850}
851
853static inline int listen(int sock, int backlog)
854{
855 return zsock_listen(sock, backlog);
856}
857
859static inline int accept(int sock, struct sockaddr *addr, socklen_t *addrlen)
860{
861 return zsock_accept(sock, addr, addrlen);
862}
863
865static inline ssize_t send(int sock, const void *buf, size_t len, int flags)
866{
867 return zsock_send(sock, buf, len, flags);
868}
869
871static inline ssize_t recv(int sock, void *buf, size_t max_len, int flags)
872{
873 return zsock_recv(sock, buf, max_len, flags);
874}
875
877static inline ssize_t sendto(int sock, const void *buf, size_t len, int flags,
878 const struct sockaddr *dest_addr,
879 socklen_t addrlen)
880{
881 return zsock_sendto(sock, buf, len, flags, dest_addr, addrlen);
882}
883
885static inline ssize_t sendmsg(int sock, const struct msghdr *message,
886 int flags)
887{
888 return zsock_sendmsg(sock, message, flags);
889}
890
892static inline ssize_t recvfrom(int sock, void *buf, size_t max_len, int flags,
893 struct sockaddr *src_addr, socklen_t *addrlen)
894{
895 return zsock_recvfrom(sock, buf, max_len, flags, src_addr, addrlen);
896}
897
899static inline ssize_t recvmsg(int sock, struct msghdr *msg, int flags)
900{
901 return zsock_recvmsg(sock, msg, flags);
902}
903
905static inline int poll(struct zsock_pollfd *fds, int nfds, int timeout)
906{
907 return zsock_poll(fds, nfds, timeout);
908}
909
911static inline int getsockopt(int sock, int level, int optname,
912 void *optval, socklen_t *optlen)
913{
914 return zsock_getsockopt(sock, level, optname, optval, optlen);
915}
916
918static inline int setsockopt(int sock, int level, int optname,
919 const void *optval, socklen_t optlen)
920{
921 return zsock_setsockopt(sock, level, optname, optval, optlen);
922}
923
925static inline int getpeername(int sock, struct sockaddr *addr,
926 socklen_t *addrlen)
927{
928 return zsock_getpeername(sock, addr, addrlen);
929}
930
932static inline int getsockname(int sock, struct sockaddr *addr,
933 socklen_t *addrlen)
934{
935 return zsock_getsockname(sock, addr, addrlen);
936}
937
939static inline int getaddrinfo(const char *host, const char *service,
940 const struct zsock_addrinfo *hints,
941 struct zsock_addrinfo **res)
942{
943 return zsock_getaddrinfo(host, service, hints, res);
944}
945
947static inline void freeaddrinfo(struct zsock_addrinfo *ai)
948{
950}
951
953static inline const char *gai_strerror(int errcode)
954{
955 return zsock_gai_strerror(errcode);
956}
957
959static inline int getnameinfo(const struct sockaddr *addr, socklen_t addrlen,
960 char *host, socklen_t hostlen,
961 char *serv, socklen_t servlen, int flags)
962{
963 return zsock_getnameinfo(addr, addrlen, host, hostlen,
964 serv, servlen, flags);
965}
966
968#define addrinfo zsock_addrinfo
969
971static inline int gethostname(char *buf, size_t len)
972{
973 return zsock_gethostname(buf, len);
974}
975
977static inline int inet_pton(sa_family_t family, const char *src, void *dst)
978{
979 return zsock_inet_pton(family, src, dst);
980}
981
983static inline char *inet_ntop(sa_family_t family, const void *src, char *dst,
984 size_t size)
985{
986 return zsock_inet_ntop(family, src, dst, size);
987}
988
990#define POLLIN ZSOCK_POLLIN
992#define POLLOUT ZSOCK_POLLOUT
994#define POLLERR ZSOCK_POLLERR
996#define POLLHUP ZSOCK_POLLHUP
998#define POLLNVAL ZSOCK_POLLNVAL
999
1001#define MSG_PEEK ZSOCK_MSG_PEEK
1003#define MSG_CTRUNC ZSOCK_MSG_CTRUNC
1005#define MSG_TRUNC ZSOCK_MSG_TRUNC
1007#define MSG_DONTWAIT ZSOCK_MSG_DONTWAIT
1009#define MSG_WAITALL ZSOCK_MSG_WAITALL
1010
1012#define SHUT_RD ZSOCK_SHUT_RD
1014#define SHUT_WR ZSOCK_SHUT_WR
1016#define SHUT_RDWR ZSOCK_SHUT_RDWR
1017
1019#define EAI_BADFLAGS DNS_EAI_BADFLAGS
1021#define EAI_NONAME DNS_EAI_NONAME
1023#define EAI_AGAIN DNS_EAI_AGAIN
1025#define EAI_FAIL DNS_EAI_FAIL
1027#define EAI_NODATA DNS_EAI_NODATA
1029#define EAI_MEMORY DNS_EAI_MEMORY
1031#define EAI_SYSTEM DNS_EAI_SYSTEM
1033#define EAI_SERVICE DNS_EAI_SERVICE
1035#define EAI_SOCKTYPE DNS_EAI_SOCKTYPE
1037#define EAI_FAMILY DNS_EAI_FAMILY
1039#endif /* defined(CONFIG_NET_SOCKETS_POSIX_NAMES) */
1040
1046#if defined(CONFIG_NET_INTERFACE_NAME)
1047#define IFNAMSIZ CONFIG_NET_INTERFACE_NAME_LEN
1048#else
1049#define IFNAMSIZ Z_DEVICE_MAX_NAME_LEN
1050#endif
1051
1053struct ifreq {
1055};
1063#define SOL_SOCKET 1
1064
1065/* Socket options for SOL_SOCKET level */
1066
1068#define SO_DEBUG 1
1070#define SO_REUSEADDR 2
1072#define SO_TYPE 3
1074#define SO_ERROR 4
1076#define SO_DONTROUTE 5
1078#define SO_BROADCAST 6
1079
1081#define SO_SNDBUF 7
1083#define SO_RCVBUF 8
1084
1086#define SO_KEEPALIVE 9
1088#define SO_OOBINLINE 10
1090#define SO_PRIORITY 12
1092#define SO_LINGER 13
1094#define SO_REUSEPORT 15
1095
1097#define SO_RCVLOWAT 18
1099#define SO_SNDLOWAT 19
1100
1105#define SO_RCVTIMEO 20
1107#define SO_SNDTIMEO 21
1108
1110#define SO_BINDTODEVICE 25
1111
1113#define SO_ACCEPTCONN 30
1114
1116#define SO_TIMESTAMPING 37
1117
1119#define SO_PROTOCOL 38
1120
1122#define SO_DOMAIN 39
1123
1125#define SO_SOCKS5 60
1126
1128#define SO_TXTIME 61
1130#define SCM_TXTIME SO_TXTIME
1131
1135#define SOF_TIMESTAMPING_RX_HARDWARE BIT(0)
1140#define SOF_TIMESTAMPING_TX_HARDWARE BIT(1)
1141
1150/* Socket options for IPPROTO_TCP level */
1152#define TCP_NODELAY 1
1154#define TCP_KEEPIDLE 2
1156#define TCP_KEEPINTVL 3
1158#define TCP_KEEPCNT 4
1159
1166/* Socket options for IPPROTO_IP level */
1168#define IP_TOS 1
1169
1171#define IP_TTL 2
1172
1177#define IP_PKTINFO 8
1178
1186 unsigned int ipi_ifindex;
1189};
1190
1192#define IP_MULTICAST_TTL 33
1194#define IP_ADD_MEMBERSHIP 35
1196#define IP_DROP_MEMBERSHIP 36
1197
1206
1213/* Socket options for IPPROTO_IPV6 level */
1215#define IPV6_UNICAST_HOPS 16
1216
1218#define IPV6_MULTICAST_HOPS 18
1219
1221#define IPV6_ADD_MEMBERSHIP 20
1222
1224#define IPV6_DROP_MEMBERSHIP 21
1225
1236
1238#define IPV6_V6ONLY 26
1239
1244#define IPV6_RECVPKTINFO 49
1245
1247#define IPV6_ADDR_PREFERENCES 72
1248
1250#define IPV6_PREFER_SRC_TMP 0x0001
1252#define IPV6_PREFER_SRC_PUBLIC 0x0002
1257#define IPV6_PREFER_SRC_PUBTMP_DEFAULT 0x0100
1259#define IPV6_PREFER_SRC_COA 0x0004
1261#define IPV6_PREFER_SRC_HOME 0x0400
1263#define IPV6_PREFER_SRC_CGA 0x0008
1265#define IPV6_PREFER_SRC_NONCGA 0x0800
1266
1275 unsigned int ipi6_ifindex;
1276};
1277
1279#define IPV6_TCLASS 67
1287#define SOMAXCONN 128
1294struct net_socket_register {
1295 int family;
1296 bool is_offloaded;
1297 bool (*is_supported)(int family, int type, int proto);
1298 int (*handler)(int family, int type, int proto);
1299#if defined(CONFIG_NET_SOCKETS_OBJ_CORE)
1300 /* Store also the name of the socket type in order to be able to
1301 * print it later.
1302 */
1303 const char * const name;
1304#endif
1305};
1306
1307#define NET_SOCKET_DEFAULT_PRIO CONFIG_NET_SOCKETS_PRIORITY_DEFAULT
1308
1309#define NET_SOCKET_GET_NAME(socket_name, prio) \
1310 __net_socket_register_##prio##_##socket_name
1311
1312#if defined(CONFIG_NET_SOCKETS_OBJ_CORE)
1313#define K_OBJ_TYPE_SOCK K_OBJ_TYPE_ID_GEN("SOCK")
1314
1315#define NET_SOCKET_REGISTER_NAME(_name) \
1316 .name = STRINGIFY(_name),
1317#else
1318#define NET_SOCKET_REGISTER_NAME(_name)
1319#endif
1320
1321#define _NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler, _is_offloaded) \
1322 static const STRUCT_SECTION_ITERABLE(net_socket_register, \
1323 NET_SOCKET_GET_NAME(socket_name, prio)) = { \
1324 .family = _family, \
1325 .is_offloaded = _is_offloaded, \
1326 .is_supported = _is_supported, \
1327 .handler = _handler, \
1328 NET_SOCKET_REGISTER_NAME(socket_name) \
1329 }
1330
1331#define NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler) \
1332 _NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler, false)
1333
1334#define NET_SOCKET_OFFLOAD_REGISTER(socket_name, prio, _family, _is_supported, _handler) \
1335 _NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler, true)
1336
1339#ifdef __cplusplus
1340}
1341#endif
1342
1343#include <zephyr/syscalls/socket.h>
1344
1349/* Avoid circular loops with POSIX socket headers.
1350 * We have these includes here so that we do not need
1351 * to change the applications that were only including
1352 * zephyr/net/socket.h header file.
1353 *
1354 * Additionally, if non-zephyr-prefixed headers are used here,
1355 * native_sim pulls in those from the host rather than Zephyr's.
1356 *
1357 * This should be removed when CONFIG_NET_SOCKETS_POSIX_NAMES is removed.
1358 */
1359#if defined(CONFIG_POSIX_API)
1360#if !defined(ZEPHYR_INCLUDE_POSIX_ARPA_INET_H_)
1361#include <zephyr/posix/arpa/inet.h>
1362#endif
1363#if !defined(ZEPHYR_INCLUDE_POSIX_NETDB_H_)
1364#include <zephyr/posix/netdb.h>
1365#endif
1366#if !defined(ZEPHYR_INCLUDE_POSIX_UNISTD_H_)
1367#include <zephyr/posix/unistd.h>
1368#endif
1369#if !defined(ZEPHYR_INCLUDE_POSIX_POLL_H_)
1370#include <zephyr/posix/poll.h>
1371#endif
1372#if !defined(ZEPHYR_INCLUDE_POSIX_SYS_SOCKET_H_)
1374#endif
1375#endif /* CONFIG_POSIX_API */
1376
1377#endif /* ZEPHYR_INCLUDE_NET_SOCKET_H_ */
DNS resolving library.
static int socket(int family, int type, int proto)
POSIX wrapper for zsock_socket.
Definition socket.h:816
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:925
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:939
static int bind(int sock, const struct sockaddr *addr, socklen_t addrlen)
POSIX wrapper for zsock_bind.
Definition socket.h:840
static int gethostname(char *buf, size_t len)
POSIX wrapper for zsock_gethostname.
Definition socket.h:971
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:885
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:977
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:892
static ssize_t zsock_send(int sock, const void *buf, size_t len, int flags)
Send data to a connected peer.
Definition socket.h:459
static int getsockopt(int sock, int level, int optname, void *optval, socklen_t *optlen)
POSIX wrapper for zsock_getsockopt.
Definition socket.h:911
static int accept(int sock, struct sockaddr *addr, socklen_t *addrlen)
POSIX wrapper for zsock_accept.
Definition socket.h:859
static int listen(int sock, int backlog)
POSIX wrapper for zsock_listen.
Definition socket.h:853
static int close(int sock)
POSIX wrapper for zsock_close.
Definition socket.h:828
int zsock_bind(int sock, const struct sockaddr *addr, socklen_t addrlen)
Bind a socket to a local network address.
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:899
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:959
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:514
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:918
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:932
int zsock_poll(struct zsock_pollfd *fds, int nfds, int timeout)
Efficiently poll multiple sockets for events.
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:953
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:1049
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:877
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:865
static int socketpair(int family, int type, int proto, int sv[2])
POSIX wrapper for zsock_socketpair.
Definition socket.h:822
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:846
static ssize_t recv(int sock, void *buf, size_t max_len, int flags)
POSIX wrapper for zsock_recv.
Definition socket.h:871
static int poll(struct zsock_pollfd *fds, int nfds, int timeout)
POSIX wrapper for zsock_poll.
Definition socket.h:905
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:681
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:983
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:947
static int shutdown(int sock, int how)
POSIX wrapper for zsock_shutdown.
Definition socket.h:834
#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
Public kernel APIs.
__SIZE_TYPE__ ssize_t
Definition types.h:28
IPv6 and IPv4 definitions.
flags
Definition parser.h:96
NCS specific additions to the BSD sockets API definitions.
BSD select support functions.
#define bool
Definition stdbool.h:13
Interface description structure.
Definition socket.h:1053
char ifr_name[Z_DEVICE_MAX_NAME_LEN]
Network interface name.
Definition socket.h:1054
IPv6 address struct.
Definition net_ip.h:142
Incoming IPv6 packet information.
Definition socket.h:1273
struct in6_addr ipi6_addr
Destination IPv6 address.
Definition socket.h:1274
unsigned int ipi6_ifindex
Receive interface index.
Definition socket.h:1275
IPv4 address struct.
Definition net_ip.h:154
Incoming IPv4 packet information.
Definition socket.h:1185
unsigned int ipi_ifindex
Network interface index.
Definition socket.h:1186
struct in_addr ipi_spec_dst
Local address.
Definition socket.h:1187
struct in_addr ipi_addr
Header Destination address.
Definition socket.h:1188
Struct used when joining or leaving a IPv4 multicast group.
Definition socket.h:1201
int imr_ifindex
Network interface index.
Definition socket.h:1204
struct in_addr imr_multiaddr
IP multicast group address.
Definition socket.h:1202
struct in_addr imr_address
IP address of local interface.
Definition socket.h:1203
Struct used when joining or leaving a IPv6 multicast group.
Definition socket.h:1229
struct in6_addr ipv6mr_multiaddr
IPv6 multicast address of group.
Definition socket.h:1231
int ipv6mr_ifindex
Network interface index of the local IPv6 address.
Definition socket.h:1234
Message struct.
Definition net_ip.h:250
Generic sockaddr struct.
Definition net_ip.h:388
Definition used when querying address information.
Definition socket.h:277
struct zsock_addrinfo * ai_next
Pointer to next address entry.
Definition socket.h:278
int ai_family
Address family of the returned addresses.
Definition socket.h:280
int ai_flags
Additional options.
Definition socket.h:279
char * ai_canonname
Optional official name of the host.
Definition socket.h:286
int ai_protocol
Protocol for addresses, 0 means any protocol.
Definition socket.h:282
struct sockaddr * ai_addr
Pointer to the address.
Definition socket.h:285
int ai_socktype
Socket type, for example SOCK_STREAM or SOCK_DGRAM.
Definition socket.h:281
int ai_eflags
Extended flags for special usage.
Definition socket.h:283
socklen_t ai_addrlen
Length of the socket address.
Definition socket.h:284
Definition of the monitored socket/file descriptor.
Definition socket_poll.h:28