Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
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
25#include <zephyr/kernel.h>
26#include <sys/types.h>
27#include <zephyr/types.h>
28#include <zephyr/device.h>
29#include <zephyr/net/net_ip.h>
33#include <zephyr/sys/fdtable.h>
36#include <stdlib.h>
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
46/* ZSOCK_POLL* values are compatible with Linux */
48#define ZSOCK_POLLIN 1
50#define ZSOCK_POLLPRI 2
52#define ZSOCK_POLLOUT 4
54#define ZSOCK_POLLERR 8
56#define ZSOCK_POLLHUP 0x10
58#define ZSOCK_POLLNVAL 0x20
66#define ZSOCK_MSG_PEEK 0x02
69#define ZSOCK_MSG_CTRUNC 0x08
73#define ZSOCK_MSG_TRUNC 0x20
75#define ZSOCK_MSG_DONTWAIT 0x40
77#define ZSOCK_MSG_WAITALL 0x100
84/* Well-known values, e.g. from Linux man 2 shutdown:
85 * "The constants SHUT_RD, SHUT_WR, SHUT_RDWR have the value 0, 1, 2,
86 * respectively". Some software uses numeric values.
87 */
89#define ZSOCK_SHUT_RD 0
91#define ZSOCK_SHUT_WR 1
93#define ZSOCK_SHUT_RDWR 2
108#define SOL_TLS 282
109
114#define TLS_SEC_TAG_LIST 1
119#define TLS_HOSTNAME 2
125#define TLS_CIPHERSUITE_LIST 3
130#define TLS_CIPHERSUITE_USED 4
141#define TLS_PEER_VERIFY 5
150#define TLS_DTLS_ROLE 6
156#define TLS_ALPN_LIST 7
161#define TLS_DTLS_HANDSHAKE_TIMEOUT_MIN 8
162
167#define TLS_DTLS_HANDSHAKE_TIMEOUT_MAX 9
168
173#define TLS_CERT_NOCOPY 10
184#define TLS_NATIVE 11
189#define TLS_SESSION_CACHE 12
193#define TLS_SESSION_CACHE_PURGE 13
205#define TLS_DTLS_CID 14
215#define TLS_DTLS_CID_STATUS 15
220#define TLS_DTLS_CID_VALUE 16
227#define TLS_DTLS_PEER_CID_VALUE 17
235#define TLS_DTLS_HANDSHAKE_ON_CONNECT 18
236
237/* Valid values for @ref TLS_PEER_VERIFY option */
238#define TLS_PEER_VERIFY_NONE 0
239#define TLS_PEER_VERIFY_OPTIONAL 1
240#define TLS_PEER_VERIFY_REQUIRED 2
242/* Valid values for @ref TLS_DTLS_ROLE option */
243#define TLS_DTLS_ROLE_CLIENT 0
244#define TLS_DTLS_ROLE_SERVER 1
246/* Valid values for @ref TLS_CERT_NOCOPY option */
247#define TLS_CERT_NOCOPY_NONE 0
248#define TLS_CERT_NOCOPY_OPTIONAL 1
250/* Valid values for @ref TLS_SESSION_CACHE option */
251#define TLS_SESSION_CACHE_DISABLED 0
252#define TLS_SESSION_CACHE_ENABLED 1
254/* Valid values for @ref TLS_DTLS_CID (Connection ID) option */
255#define TLS_DTLS_CID_DISABLED 0
256#define TLS_DTLS_CID_SUPPORTED 1
257#define TLS_DTLS_CID_ENABLED 2
259/* Valid values for @ref TLS_DTLS_CID_STATUS option */
260#define TLS_DTLS_CID_STATUS_DISABLED 0
261#define TLS_DTLS_CID_STATUS_DOWNLINK 1
262#define TLS_DTLS_CID_STATUS_UPLINK 2
263#define TLS_DTLS_CID_STATUS_BIDIRECTIONAL 3 /* for @name */ /* for @defgroup */
266
285 struct sockaddr _ai_addr;
286 char _ai_canonname[DNS_MAX_NAME_SIZE + 1];
288};
289
326__syscall void *zsock_get_context_object(int sock);
327
345__syscall int zsock_socket(int family, int type, int proto);
346
359__syscall int zsock_socketpair(int family, int type, int proto, int *sv);
360
372__syscall int zsock_close(int sock);
373
387__syscall int zsock_shutdown(int sock, int how);
388
401__syscall int zsock_bind(int sock, const struct sockaddr *addr,
402 socklen_t addrlen);
403
416__syscall int zsock_connect(int sock, const struct sockaddr *addr,
417 socklen_t addrlen);
418
431__syscall int zsock_listen(int sock, int backlog);
432
445__syscall int zsock_accept(int sock, struct sockaddr *addr, socklen_t *addrlen);
446
459__syscall ssize_t zsock_sendto(int sock, const void *buf, size_t len,
460 int flags, const struct sockaddr *dest_addr,
461 socklen_t addrlen);
462
475static inline ssize_t zsock_send(int sock, const void *buf, size_t len,
476 int flags)
477{
478 return zsock_sendto(sock, buf, len, flags, NULL, 0);
479}
480
493__syscall ssize_t zsock_sendmsg(int sock, const struct msghdr *msg,
494 int flags);
495
508__syscall ssize_t zsock_recvfrom(int sock, void *buf, size_t max_len,
509 int flags, struct sockaddr *src_addr,
510 socklen_t *addrlen);
511
524__syscall ssize_t zsock_recvmsg(int sock, struct msghdr *msg, int flags);
525
538static inline ssize_t zsock_recv(int sock, void *buf, size_t max_len,
539 int flags)
540{
541 return zsock_recvfrom(sock, buf, max_len, flags, NULL, NULL);
542}
543
556__syscall int zsock_fcntl_impl(int sock, int cmd, int flags);
557
560/*
561 * Need this wrapper because newer GCC versions got too smart and "typecheck"
562 * even macros.
563 */
564static inline int zsock_fcntl_wrapper(int sock, int cmd, ...)
565{
566 va_list args;
567 int flags;
568
569 va_start(args, cmd);
570 flags = va_arg(args, int);
571 va_end(args);
572 return zsock_fcntl_impl(sock, cmd, flags);
573}
574
575#define zsock_fcntl zsock_fcntl_wrapper
576
596__syscall int zsock_ioctl_impl(int sock, unsigned long request, va_list ap);
597
600static inline int zsock_ioctl_wrapper(int sock, unsigned long request, ...)
601{
602 int ret;
603 va_list args;
604
605 va_start(args, request);
606 ret = zsock_ioctl_impl(sock, request, args);
607 va_end(args);
608
609 return ret;
610}
611
612#define zsock_ioctl zsock_ioctl_wrapper
613
629__syscall int zsock_poll(struct zsock_pollfd *fds, int nfds, int timeout);
630
646__syscall int zsock_getsockopt(int sock, int level, int optname,
647 void *optval, socklen_t *optlen);
648
664__syscall int zsock_setsockopt(int sock, int level, int optname,
665 const void *optval, socklen_t optlen);
666
679__syscall int zsock_getpeername(int sock, struct sockaddr *addr,
680 socklen_t *addrlen);
681
694__syscall int zsock_getsockname(int sock, struct sockaddr *addr,
695 socklen_t *addrlen);
696
709__syscall int zsock_gethostname(char *buf, size_t len);
710
723static inline char *zsock_inet_ntop(sa_family_t family, const void *src,
724 char *dst, size_t size)
725{
726 return net_addr_ntop(family, src, dst, size);
727}
728
741__syscall int zsock_inet_pton(sa_family_t family, const char *src, void *dst);
742
744__syscall int z_zsock_getaddrinfo_internal(const char *host,
745 const char *service,
746 const struct zsock_addrinfo *hints,
747 struct zsock_addrinfo *res);
750/* Flags for getaddrinfo() hints. */
751
757#define AI_PASSIVE 0x1
759#define AI_CANONNAME 0x2
761#define AI_NUMERICHOST 0x4
763#define AI_V4MAPPED 0x8
765#define AI_ALL 0x10
767#define AI_ADDRCONFIG 0x20
769#define AI_NUMERICSERV 0x400
771#define AI_EXTFLAGS 0x800
786int zsock_getaddrinfo(const char *host, const char *service,
787 const struct zsock_addrinfo *hints,
788 struct zsock_addrinfo **res);
789
803
816const char *zsock_gai_strerror(int errcode);
817
823#define NI_NUMERICHOST 1
825#define NI_NUMERICSERV 2
827#define NI_NOFQDN 4
829#define NI_NAMEREQD 8
831#define NI_DGRAM 16
832
833/* POSIX extensions */
834
836#ifndef NI_MAXHOST
837#define NI_MAXHOST 64
838#endif
853int zsock_getnameinfo(const struct sockaddr *addr, socklen_t addrlen,
854 char *host, socklen_t hostlen,
855 char *serv, socklen_t servlen, int flags);
856
857#if defined(CONFIG_NET_SOCKETS_POSIX_NAMES)
858
865#define pollfd zsock_pollfd
866
868static inline int socket(int family, int type, int proto)
869{
870 return zsock_socket(family, type, proto);
871}
872
874static inline int socketpair(int family, int type, int proto, int sv[2])
875{
876 return zsock_socketpair(family, type, proto, sv);
877}
878
880static inline int close(int sock)
881{
882 return zsock_close(sock);
883}
884
886static inline int shutdown(int sock, int how)
887{
888 return zsock_shutdown(sock, how);
889}
890
892static inline int bind(int sock, const struct sockaddr *addr, socklen_t addrlen)
893{
894 return zsock_bind(sock, addr, addrlen);
895}
896
898static inline int connect(int sock, const struct sockaddr *addr,
899 socklen_t addrlen)
900{
901 return zsock_connect(sock, addr, addrlen);
902}
903
905static inline int listen(int sock, int backlog)
906{
907 return zsock_listen(sock, backlog);
908}
909
911static inline int accept(int sock, struct sockaddr *addr, socklen_t *addrlen)
912{
913 return zsock_accept(sock, addr, addrlen);
914}
915
917static inline ssize_t send(int sock, const void *buf, size_t len, int flags)
918{
919 return zsock_send(sock, buf, len, flags);
920}
921
923static inline ssize_t recv(int sock, void *buf, size_t max_len, int flags)
924{
925 return zsock_recv(sock, buf, max_len, flags);
926}
927
929static inline ssize_t sendto(int sock, const void *buf, size_t len, int flags,
930 const struct sockaddr *dest_addr,
931 socklen_t addrlen)
932{
933 return zsock_sendto(sock, buf, len, flags, dest_addr, addrlen);
934}
935
937static inline ssize_t sendmsg(int sock, const struct msghdr *message,
938 int flags)
939{
940 return zsock_sendmsg(sock, message, flags);
941}
942
944static inline ssize_t recvfrom(int sock, void *buf, size_t max_len, int flags,
945 struct sockaddr *src_addr, socklen_t *addrlen)
946{
947 return zsock_recvfrom(sock, buf, max_len, flags, src_addr, addrlen);
948}
949
951static inline ssize_t recvmsg(int sock, struct msghdr *msg, int flags)
952{
953 return zsock_recvmsg(sock, msg, flags);
954}
955
957static inline int poll(struct zsock_pollfd *fds, int nfds, int timeout)
958{
959 return zsock_poll(fds, nfds, timeout);
960}
961
963static inline int getsockopt(int sock, int level, int optname,
964 void *optval, socklen_t *optlen)
965{
966 return zsock_getsockopt(sock, level, optname, optval, optlen);
967}
968
970static inline int setsockopt(int sock, int level, int optname,
971 const void *optval, socklen_t optlen)
972{
973 return zsock_setsockopt(sock, level, optname, optval, optlen);
974}
975
977static inline int getpeername(int sock, struct sockaddr *addr,
978 socklen_t *addrlen)
979{
980 return zsock_getpeername(sock, addr, addrlen);
981}
982
984static inline int getsockname(int sock, struct sockaddr *addr,
985 socklen_t *addrlen)
986{
987 return zsock_getsockname(sock, addr, addrlen);
988}
989
991static inline int getaddrinfo(const char *host, const char *service,
992 const struct zsock_addrinfo *hints,
993 struct zsock_addrinfo **res)
994{
995 return zsock_getaddrinfo(host, service, hints, res);
996}
997
999static inline void freeaddrinfo(struct zsock_addrinfo *ai)
1000{
1002}
1003
1005static inline const char *gai_strerror(int errcode)
1006{
1007 return zsock_gai_strerror(errcode);
1008}
1009
1011static inline int getnameinfo(const struct sockaddr *addr, socklen_t addrlen,
1012 char *host, socklen_t hostlen,
1013 char *serv, socklen_t servlen, int flags)
1014{
1015 return zsock_getnameinfo(addr, addrlen, host, hostlen,
1016 serv, servlen, flags);
1017}
1018
1020#define addrinfo zsock_addrinfo
1021
1023static inline int gethostname(char *buf, size_t len)
1024{
1025 return zsock_gethostname(buf, len);
1026}
1027
1029static inline int inet_pton(sa_family_t family, const char *src, void *dst)
1030{
1031 return zsock_inet_pton(family, src, dst);
1032}
1033
1035static inline char *inet_ntop(sa_family_t family, const void *src, char *dst,
1036 size_t size)
1037{
1038 return zsock_inet_ntop(family, src, dst, size);
1039}
1040
1042#define POLLIN ZSOCK_POLLIN
1044#define POLLOUT ZSOCK_POLLOUT
1046#define POLLERR ZSOCK_POLLERR
1048#define POLLHUP ZSOCK_POLLHUP
1050#define POLLNVAL ZSOCK_POLLNVAL
1051
1053#define MSG_PEEK ZSOCK_MSG_PEEK
1055#define MSG_CTRUNC ZSOCK_MSG_CTRUNC
1057#define MSG_TRUNC ZSOCK_MSG_TRUNC
1059#define MSG_DONTWAIT ZSOCK_MSG_DONTWAIT
1061#define MSG_WAITALL ZSOCK_MSG_WAITALL
1062
1064#define SHUT_RD ZSOCK_SHUT_RD
1066#define SHUT_WR ZSOCK_SHUT_WR
1068#define SHUT_RDWR ZSOCK_SHUT_RDWR
1069
1071#define EAI_BADFLAGS DNS_EAI_BADFLAGS
1073#define EAI_NONAME DNS_EAI_NONAME
1075#define EAI_AGAIN DNS_EAI_AGAIN
1077#define EAI_FAIL DNS_EAI_FAIL
1079#define EAI_NODATA DNS_EAI_NODATA
1081#define EAI_MEMORY DNS_EAI_MEMORY
1083#define EAI_SYSTEM DNS_EAI_SYSTEM
1085#define EAI_SERVICE DNS_EAI_SERVICE
1087#define EAI_SOCKTYPE DNS_EAI_SOCKTYPE
1089#define EAI_FAMILY DNS_EAI_FAMILY
1091#endif /* defined(CONFIG_NET_SOCKETS_POSIX_NAMES) */
1092
1098#if defined(CONFIG_NET_INTERFACE_NAME)
1099#define IFNAMSIZ CONFIG_NET_INTERFACE_NAME_LEN
1100#else
1101#define IFNAMSIZ Z_DEVICE_MAX_NAME_LEN
1102#endif
1103
1105struct ifreq {
1107};
1115#define SOL_SOCKET 1
1116
1117/* Socket options for SOL_SOCKET level */
1118
1120#define SO_DEBUG 1
1122#define SO_REUSEADDR 2
1124#define SO_TYPE 3
1126#define SO_ERROR 4
1128#define SO_DONTROUTE 5
1130#define SO_BROADCAST 6
1131
1133#define SO_SNDBUF 7
1135#define SO_RCVBUF 8
1136
1138#define SO_KEEPALIVE 9
1140#define SO_OOBINLINE 10
1142#define SO_PRIORITY 12
1144#define SO_LINGER 13
1146#define SO_REUSEPORT 15
1147
1149#define SO_RCVLOWAT 18
1151#define SO_SNDLOWAT 19
1152
1157#define SO_RCVTIMEO 20
1159#define SO_SNDTIMEO 21
1160
1162#define SO_BINDTODEVICE 25
1163
1165#define SO_ACCEPTCONN 30
1166
1168#define SO_TIMESTAMPING 37
1170#define SO_PROTOCOL 38
1171
1173#define SO_DOMAIN 39
1174
1176#define SO_SOCKS5 60
1177
1179#define SO_TXTIME 61
1181#define SCM_TXTIME SO_TXTIME
1182
1189/* Socket options for IPPROTO_TCP level */
1191#define TCP_NODELAY 1
1193#define TCP_KEEPIDLE 2
1195#define TCP_KEEPINTVL 3
1197#define TCP_KEEPCNT 4
1198
1205/* Socket options for IPPROTO_IP level */
1207#define IP_TOS 1
1208
1210#define IP_TTL 2
1211
1216#define IP_PKTINFO 8
1217
1225 unsigned int ipi_ifindex;
1228};
1229
1231#define IP_MULTICAST_TTL 33
1233#define IP_ADD_MEMBERSHIP 35
1235#define IP_DROP_MEMBERSHIP 36
1236
1240struct ip_mreqn {
1244};
1245
1252/* Socket options for IPPROTO_IPV6 level */
1254#define IPV6_UNICAST_HOPS 16
1255
1257#define IPV6_MULTICAST_HOPS 18
1258
1260#define IPV6_ADD_MEMBERSHIP 20
1261
1263#define IPV6_DROP_MEMBERSHIP 21
1264
1271
1274};
1275
1277#define IPV6_V6ONLY 26
1278
1283#define IPV6_RECVPKTINFO 49
1284
1286#define IPV6_ADDR_PREFERENCES 72
1287
1289#define IPV6_PREFER_SRC_TMP 0x0001
1291#define IPV6_PREFER_SRC_PUBLIC 0x0002
1296#define IPV6_PREFER_SRC_PUBTMP_DEFAULT 0x0100
1298#define IPV6_PREFER_SRC_COA 0x0004
1300#define IPV6_PREFER_SRC_HOME 0x0400
1302#define IPV6_PREFER_SRC_CGA 0x0008
1304#define IPV6_PREFER_SRC_NONCGA 0x0800
1305
1314 unsigned int ipi6_ifindex;
1315};
1316
1318#define IPV6_TCLASS 67
1326#define SOMAXCONN 128
1333struct net_socket_register {
1334 int family;
1335 bool is_offloaded;
1336 bool (*is_supported)(int family, int type, int proto);
1337 int (*handler)(int family, int type, int proto);
1338#if defined(CONFIG_NET_SOCKETS_OBJ_CORE)
1339 /* Store also the name of the socket type in order to be able to
1340 * print it later.
1341 */
1342 const char * const name;
1343#endif
1344};
1345
1346#define NET_SOCKET_DEFAULT_PRIO CONFIG_NET_SOCKETS_PRIORITY_DEFAULT
1347
1348#define NET_SOCKET_GET_NAME(socket_name, prio) \
1349 __net_socket_register_##prio##_##socket_name
1350
1351#if defined(CONFIG_NET_SOCKETS_OBJ_CORE)
1352#define K_OBJ_TYPE_SOCK K_OBJ_TYPE_ID_GEN("SOCK")
1353
1354#define NET_SOCKET_REGISTER_NAME(_name) \
1355 .name = STRINGIFY(_name),
1356#else
1357#define NET_SOCKET_REGISTER_NAME(_name)
1358#endif
1359
1360#define _NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler, _is_offloaded) \
1361 static const STRUCT_SECTION_ITERABLE(net_socket_register, \
1362 NET_SOCKET_GET_NAME(socket_name, prio)) = { \
1363 .family = _family, \
1364 .is_offloaded = _is_offloaded, \
1365 .is_supported = _is_supported, \
1366 .handler = _handler, \
1367 NET_SOCKET_REGISTER_NAME(socket_name) \
1368 }
1369
1370#define NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler) \
1371 _NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler, false)
1372
1373#define NET_SOCKET_OFFLOAD_REGISTER(socket_name, prio, _family, _is_supported, _handler) \
1374 _NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler, true)
1375
1378#ifdef __cplusplus
1379}
1380#endif
1381
1382#include <syscalls/socket.h>
1383
1388/* Avoid circular loops with POSIX socket headers.
1389 * We have these includes here so that we do not need
1390 * to change the applications that were only including
1391 * zephyr/net/socket.h header file.
1392 */
1393#if defined(CONFIG_POSIX_API)
1394#if !defined(ZEPHYR_INCLUDE_POSIX_ARPA_INET_H_)
1395#include <zephyr/posix/arpa/inet.h>
1396#endif
1397#if !defined(ZEPHYR_INCLUDE_POSIX_NETDB_H_)
1398#include <zephyr/posix/netdb.h>
1399#endif
1400#if !defined(ZEPHYR_INCLUDE_POSIX_UNISTD_H_)
1401#include <zephyr/posix/unistd.h>
1402#endif
1403#if !defined(ZEPHYR_INCLUDE_POSIX_POLL_H_)
1404#include <zephyr/posix/poll.h>
1405#endif
1406#if !defined(ZEPHYR_INCLUDE_POSIX_SYS_SOCKET_H_)
1408#endif
1409#endif /* CONFIG_POSIX_API */
1410
1411#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:868
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:977
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:991
static int bind(int sock, const struct sockaddr *addr, socklen_t addrlen)
POSIX wrapper for zsock_bind.
Definition: socket.h:892
static int gethostname(char *buf, size_t len)
POSIX wrapper for zsock_gethostname.
Definition: socket.h:1023
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:937
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:1029
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:944
static ssize_t zsock_send(int sock, const void *buf, size_t len, int flags)
Send data to a connected peer.
Definition: socket.h:475
static int getsockopt(int sock, int level, int optname, void *optval, socklen_t *optlen)
POSIX wrapper for zsock_getsockopt.
Definition: socket.h:963
static int accept(int sock, struct sockaddr *addr, socklen_t *addrlen)
POSIX wrapper for zsock_accept.
Definition: socket.h:911
static int listen(int sock, int backlog)
POSIX wrapper for zsock_listen.
Definition: socket.h:905
static int close(int sock)
POSIX wrapper for zsock_close.
Definition: socket.h:880
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:951
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:1011
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:538
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:970
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:984
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:1005
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:1101
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:929
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:917
static int socketpair(int family, int type, int proto, int sv[2])
POSIX wrapper for zsock_socketpair.
Definition: socket.h:874
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:898
static ssize_t recv(int sock, void *buf, size_t max_len, int flags)
POSIX wrapper for zsock_recv.
Definition: socket.h:923
static int poll(struct zsock_pollfd *fds, int nfds, int timeout)
POSIX wrapper for zsock_poll.
Definition: socket.h:957
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:723
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:1035
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:999
static int shutdown(int sock, int how)
POSIX wrapper for zsock_shutdown.
Definition: socket.h:886
#define DNS_MAX_NAME_SIZE
Max size of the resolved name.
Definition: dns_resolve.h:44
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:164
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:168
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:1105
char ifr_name[Z_DEVICE_MAX_NAME_LEN]
Network interface name.
Definition: socket.h:1106
IPv6 address struct.
Definition: net_ip.h:139
Incoming IPv6 packet information.
Definition: socket.h:1312
struct in6_addr ipi6_addr
Destination IPv6 address.
Definition: socket.h:1313
unsigned int ipi6_ifindex
Receive interface index.
Definition: socket.h:1314
IPv4 address struct.
Definition: net_ip.h:151
Incoming IPv4 packet information.
Definition: socket.h:1224
unsigned int ipi_ifindex
Network interface index.
Definition: socket.h:1225
struct in_addr ipi_spec_dst
Local address.
Definition: socket.h:1226
struct in_addr ipi_addr
Header Destination address.
Definition: socket.h:1227
Struct used when joining or leaving a IPv4 multicast group.
Definition: socket.h:1240
int imr_ifindex
Network interface index.
Definition: socket.h:1243
struct in_addr imr_multiaddr
IP multicast group address.
Definition: socket.h:1241
struct in_addr imr_address
IP address of local interface.
Definition: socket.h:1242
Struct used when joining or leaving a IPv6 multicast group.
Definition: socket.h:1268
struct in6_addr ipv6mr_multiaddr
IPv6 multicast address of group.
Definition: socket.h:1270
int ipv6mr_ifindex
Network interface index of the local IPv6 address.
Definition: socket.h:1273
Message struct.
Definition: net_ip.h:247
Generic sockaddr struct.
Definition: net_ip.h:385
Definition used when querying address information.
Definition: socket.h:273
struct zsock_addrinfo * ai_next
Pointer to next address entry.
Definition: socket.h:274
int ai_family
Address family of the returned addresses.
Definition: socket.h:276
int ai_flags
Additional options.
Definition: socket.h:275
char * ai_canonname
Optional official name of the host.
Definition: socket.h:282
int ai_protocol
Protocol for addresses, 0 means any protocol.
Definition: socket.h:278
struct sockaddr * ai_addr
Pointer to the address.
Definition: socket.h:281
int ai_socktype
Socket type, for example SOCK_STREAM or SOCK_DGRAM.
Definition: socket.h:277
int ai_eflags
Extended flags for special usage.
Definition: socket.h:279
socklen_t ai_addrlen
Length of the socket address.
Definition: socket.h:280
Definition of the monitored socket/file descriptor.
Definition: socket_poll.h:28