Zephyr API Documentation 3.7.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
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>
37#include <stdlib.h>
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
47/* ZSOCK_POLL* values are compatible with Linux */
49#define ZSOCK_POLLIN 1
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
85/* Well-known values, e.g. from Linux man 2 shutdown:
86 * "The constants SHUT_RD, SHUT_WR, SHUT_RDWR have the value 0, 1, 2,
87 * respectively". Some software uses numeric values.
88 */
90#define ZSOCK_SHUT_RD 0
92#define ZSOCK_SHUT_WR 1
94#define ZSOCK_SHUT_RDWR 2
111#define SOL_TLS 282
112
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
165
170#define TLS_DTLS_HANDSHAKE_TIMEOUT_MAX 9
171
176#define TLS_CERT_NOCOPY 10
187#define TLS_NATIVE 11
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
239
240/* Valid values for @ref TLS_PEER_VERIFY option */
241#define TLS_PEER_VERIFY_NONE 0
242#define TLS_PEER_VERIFY_OPTIONAL 1
243#define TLS_PEER_VERIFY_REQUIRED 2
245/* Valid values for @ref TLS_DTLS_ROLE option */
246#define TLS_DTLS_ROLE_CLIENT 0
247#define TLS_DTLS_ROLE_SERVER 1
249/* Valid values for @ref TLS_CERT_NOCOPY option */
250#define TLS_CERT_NOCOPY_NONE 0
251#define TLS_CERT_NOCOPY_OPTIONAL 1
253/* Valid values for @ref TLS_SESSION_CACHE option */
254#define TLS_SESSION_CACHE_DISABLED 0
255#define TLS_SESSION_CACHE_ENABLED 1
257/* Valid values for @ref TLS_DTLS_CID (Connection ID) option */
258#define TLS_DTLS_CID_DISABLED 0
259#define TLS_DTLS_CID_SUPPORTED 1
260#define TLS_DTLS_CID_ENABLED 2
262/* Valid values for @ref TLS_DTLS_CID_STATUS option */
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
267 /* for @name */
268 /* for @defgroup */
269
288 struct sockaddr _ai_addr;
289 char _ai_canonname[DNS_MAX_NAME_SIZE + 1];
291};
292
329__syscall void *zsock_get_context_object(int sock);
330
348__syscall int zsock_socket(int family, int type, int proto);
349
362__syscall int zsock_socketpair(int family, int type, int proto, int *sv);
363
375__syscall int zsock_close(int sock);
376
390__syscall int zsock_shutdown(int sock, int how);
391
404__syscall int zsock_bind(int sock, const struct sockaddr *addr,
405 socklen_t addrlen);
406
419__syscall int zsock_connect(int sock, const struct sockaddr *addr,
420 socklen_t addrlen);
421
434__syscall int zsock_listen(int sock, int backlog);
435
448__syscall int zsock_accept(int sock, struct sockaddr *addr, socklen_t *addrlen);
449
462__syscall ssize_t zsock_sendto(int sock, const void *buf, size_t len,
463 int flags, const struct sockaddr *dest_addr,
464 socklen_t addrlen);
465
478static inline ssize_t zsock_send(int sock, const void *buf, size_t len,
479 int flags)
480{
481 return zsock_sendto(sock, buf, len, flags, NULL, 0);
482}
483
496__syscall ssize_t zsock_sendmsg(int sock, const struct msghdr *msg,
497 int flags);
498
511__syscall ssize_t zsock_recvfrom(int sock, void *buf, size_t max_len,
512 int flags, struct sockaddr *src_addr,
513 socklen_t *addrlen);
514
527__syscall ssize_t zsock_recvmsg(int sock, struct msghdr *msg, int flags);
528
541static inline ssize_t zsock_recv(int sock, void *buf, size_t max_len,
542 int flags)
543{
544 return zsock_recvfrom(sock, buf, max_len, flags, NULL, NULL);
545}
546
559__syscall int zsock_fcntl_impl(int sock, int cmd, int flags);
560
563/*
564 * Need this wrapper because newer GCC versions got too smart and "typecheck"
565 * even macros.
566 */
567static inline int zsock_fcntl_wrapper(int sock, int cmd, ...)
568{
569 va_list args;
570 int flags;
571
572 va_start(args, cmd);
573 flags = va_arg(args, int);
574 va_end(args);
575 return zsock_fcntl_impl(sock, cmd, flags);
576}
577
578#define zsock_fcntl zsock_fcntl_wrapper
579
599__syscall int zsock_ioctl_impl(int sock, unsigned long request, va_list ap);
600
603static inline int zsock_ioctl_wrapper(int sock, unsigned long request, ...)
604{
605 int ret;
606 va_list args;
607
608 va_start(args, request);
609 ret = zsock_ioctl_impl(sock, request, args);
610 va_end(args);
611
612 return ret;
613}
614
615#define zsock_ioctl zsock_ioctl_wrapper
616
632__syscall int zsock_poll(struct zsock_pollfd *fds, int nfds, int timeout);
633
649__syscall int zsock_getsockopt(int sock, int level, int optname,
650 void *optval, socklen_t *optlen);
651
667__syscall int zsock_setsockopt(int sock, int level, int optname,
668 const void *optval, socklen_t optlen);
669
682__syscall int zsock_getpeername(int sock, struct sockaddr *addr,
683 socklen_t *addrlen);
684
697__syscall int zsock_getsockname(int sock, struct sockaddr *addr,
698 socklen_t *addrlen);
699
712__syscall int zsock_gethostname(char *buf, size_t len);
713
726static inline char *zsock_inet_ntop(sa_family_t family, const void *src,
727 char *dst, size_t size)
728{
729 return net_addr_ntop(family, src, dst, size);
730}
731
744__syscall int zsock_inet_pton(sa_family_t family, const char *src, void *dst);
745
747__syscall int z_zsock_getaddrinfo_internal(const char *host,
748 const char *service,
749 const struct zsock_addrinfo *hints,
750 struct zsock_addrinfo *res);
753/* Flags for getaddrinfo() hints. */
754
760#define AI_PASSIVE 0x1
762#define AI_CANONNAME 0x2
764#define AI_NUMERICHOST 0x4
766#define AI_V4MAPPED 0x8
768#define AI_ALL 0x10
770#define AI_ADDRCONFIG 0x20
772#define AI_NUMERICSERV 0x400
774#define AI_EXTFLAGS 0x800
789int zsock_getaddrinfo(const char *host, const char *service,
790 const struct zsock_addrinfo *hints,
791 struct zsock_addrinfo **res);
792
806
819const char *zsock_gai_strerror(int errcode);
820
826#define NI_NUMERICHOST 1
828#define NI_NUMERICSERV 2
830#define NI_NOFQDN 4
832#define NI_NAMEREQD 8
834#define NI_DGRAM 16
835
836/* POSIX extensions */
837
839#ifndef NI_MAXHOST
840#define NI_MAXHOST 64
841#endif
856int zsock_getnameinfo(const struct sockaddr *addr, socklen_t addrlen,
857 char *host, socklen_t hostlen,
858 char *serv, socklen_t servlen, int flags);
859
860#if defined(CONFIG_NET_SOCKETS_POSIX_NAMES)
861
868#define pollfd zsock_pollfd
869
871static inline int socket(int family, int type, int proto)
872{
873 return zsock_socket(family, type, proto);
874}
875
877static inline int socketpair(int family, int type, int proto, int sv[2])
878{
879 return zsock_socketpair(family, type, proto, sv);
880}
881
883static inline int close(int sock)
884{
885 return zsock_close(sock);
886}
887
889static inline int shutdown(int sock, int how)
890{
891 return zsock_shutdown(sock, how);
892}
893
895static inline int bind(int sock, const struct sockaddr *addr, socklen_t addrlen)
896{
897 return zsock_bind(sock, addr, addrlen);
898}
899
901static inline int connect(int sock, const struct sockaddr *addr,
902 socklen_t addrlen)
903{
904 return zsock_connect(sock, addr, addrlen);
905}
906
908static inline int listen(int sock, int backlog)
909{
910 return zsock_listen(sock, backlog);
911}
912
914static inline int accept(int sock, struct sockaddr *addr, socklen_t *addrlen)
915{
916 return zsock_accept(sock, addr, addrlen);
917}
918
920static inline ssize_t send(int sock, const void *buf, size_t len, int flags)
921{
922 return zsock_send(sock, buf, len, flags);
923}
924
926static inline ssize_t recv(int sock, void *buf, size_t max_len, int flags)
927{
928 return zsock_recv(sock, buf, max_len, flags);
929}
930
932static inline ssize_t sendto(int sock, const void *buf, size_t len, int flags,
933 const struct sockaddr *dest_addr,
934 socklen_t addrlen)
935{
936 return zsock_sendto(sock, buf, len, flags, dest_addr, addrlen);
937}
938
940static inline ssize_t sendmsg(int sock, const struct msghdr *message,
941 int flags)
942{
943 return zsock_sendmsg(sock, message, flags);
944}
945
947static inline ssize_t recvfrom(int sock, void *buf, size_t max_len, int flags,
948 struct sockaddr *src_addr, socklen_t *addrlen)
949{
950 return zsock_recvfrom(sock, buf, max_len, flags, src_addr, addrlen);
951}
952
954static inline ssize_t recvmsg(int sock, struct msghdr *msg, int flags)
955{
956 return zsock_recvmsg(sock, msg, flags);
957}
958
960static inline int poll(struct zsock_pollfd *fds, int nfds, int timeout)
961{
962 return zsock_poll(fds, nfds, timeout);
963}
964
966static inline int getsockopt(int sock, int level, int optname,
967 void *optval, socklen_t *optlen)
968{
969 return zsock_getsockopt(sock, level, optname, optval, optlen);
970}
971
973static inline int setsockopt(int sock, int level, int optname,
974 const void *optval, socklen_t optlen)
975{
976 return zsock_setsockopt(sock, level, optname, optval, optlen);
977}
978
980static inline int getpeername(int sock, struct sockaddr *addr,
981 socklen_t *addrlen)
982{
983 return zsock_getpeername(sock, addr, addrlen);
984}
985
987static inline int getsockname(int sock, struct sockaddr *addr,
988 socklen_t *addrlen)
989{
990 return zsock_getsockname(sock, addr, addrlen);
991}
992
994static inline int getaddrinfo(const char *host, const char *service,
995 const struct zsock_addrinfo *hints,
996 struct zsock_addrinfo **res)
997{
998 return zsock_getaddrinfo(host, service, hints, res);
999}
1000
1002static inline void freeaddrinfo(struct zsock_addrinfo *ai)
1003{
1005}
1006
1008static inline const char *gai_strerror(int errcode)
1009{
1010 return zsock_gai_strerror(errcode);
1011}
1012
1014static inline int getnameinfo(const struct sockaddr *addr, socklen_t addrlen,
1015 char *host, socklen_t hostlen,
1016 char *serv, socklen_t servlen, int flags)
1017{
1018 return zsock_getnameinfo(addr, addrlen, host, hostlen,
1019 serv, servlen, flags);
1020}
1021
1023#define addrinfo zsock_addrinfo
1024
1026static inline int gethostname(char *buf, size_t len)
1027{
1028 return zsock_gethostname(buf, len);
1029}
1030
1032static inline int inet_pton(sa_family_t family, const char *src, void *dst)
1033{
1034 return zsock_inet_pton(family, src, dst);
1035}
1036
1038static inline char *inet_ntop(sa_family_t family, const void *src, char *dst,
1039 size_t size)
1040{
1041 return zsock_inet_ntop(family, src, dst, size);
1042}
1043
1045#define POLLIN ZSOCK_POLLIN
1047#define POLLOUT ZSOCK_POLLOUT
1049#define POLLERR ZSOCK_POLLERR
1051#define POLLHUP ZSOCK_POLLHUP
1053#define POLLNVAL ZSOCK_POLLNVAL
1054
1056#define MSG_PEEK ZSOCK_MSG_PEEK
1058#define MSG_CTRUNC ZSOCK_MSG_CTRUNC
1060#define MSG_TRUNC ZSOCK_MSG_TRUNC
1062#define MSG_DONTWAIT ZSOCK_MSG_DONTWAIT
1064#define MSG_WAITALL ZSOCK_MSG_WAITALL
1065
1067#define SHUT_RD ZSOCK_SHUT_RD
1069#define SHUT_WR ZSOCK_SHUT_WR
1071#define SHUT_RDWR ZSOCK_SHUT_RDWR
1072
1074#define EAI_BADFLAGS DNS_EAI_BADFLAGS
1076#define EAI_NONAME DNS_EAI_NONAME
1078#define EAI_AGAIN DNS_EAI_AGAIN
1080#define EAI_FAIL DNS_EAI_FAIL
1082#define EAI_NODATA DNS_EAI_NODATA
1084#define EAI_MEMORY DNS_EAI_MEMORY
1086#define EAI_SYSTEM DNS_EAI_SYSTEM
1088#define EAI_SERVICE DNS_EAI_SERVICE
1090#define EAI_SOCKTYPE DNS_EAI_SOCKTYPE
1092#define EAI_FAMILY DNS_EAI_FAMILY
1094#endif /* defined(CONFIG_NET_SOCKETS_POSIX_NAMES) */
1095
1101#if defined(CONFIG_NET_INTERFACE_NAME)
1102#define IFNAMSIZ CONFIG_NET_INTERFACE_NAME_LEN
1103#else
1104#define IFNAMSIZ Z_DEVICE_MAX_NAME_LEN
1105#endif
1106
1108struct ifreq {
1110};
1118#define SOL_SOCKET 1
1119
1120/* Socket options for SOL_SOCKET level */
1121
1123#define SO_DEBUG 1
1125#define SO_REUSEADDR 2
1127#define SO_TYPE 3
1129#define SO_ERROR 4
1131#define SO_DONTROUTE 5
1133#define SO_BROADCAST 6
1134
1136#define SO_SNDBUF 7
1138#define SO_RCVBUF 8
1139
1141#define SO_KEEPALIVE 9
1143#define SO_OOBINLINE 10
1145#define SO_PRIORITY 12
1147#define SO_LINGER 13
1149#define SO_REUSEPORT 15
1150
1152#define SO_RCVLOWAT 18
1154#define SO_SNDLOWAT 19
1155
1160#define SO_RCVTIMEO 20
1162#define SO_SNDTIMEO 21
1163
1165#define SO_BINDTODEVICE 25
1166
1168#define SO_ACCEPTCONN 30
1169
1171#define SO_TIMESTAMPING 37
1172
1174#define SO_PROTOCOL 38
1175
1177#define SO_DOMAIN 39
1178
1180#define SO_SOCKS5 60
1181
1183#define SO_TXTIME 61
1185#define SCM_TXTIME SO_TXTIME
1186
1190#define SOF_TIMESTAMPING_RX_HARDWARE BIT(0)
1195#define SOF_TIMESTAMPING_TX_HARDWARE BIT(1)
1196
1205/* Socket options for IPPROTO_TCP level */
1207#define TCP_NODELAY 1
1209#define TCP_KEEPIDLE 2
1211#define TCP_KEEPINTVL 3
1213#define TCP_KEEPCNT 4
1214
1221/* Socket options for IPPROTO_IP level */
1223#define IP_TOS 1
1224
1226#define IP_TTL 2
1227
1232#define IP_PKTINFO 8
1233
1241 unsigned int ipi_ifindex;
1244};
1245
1247#define IP_MULTICAST_TTL 33
1249#define IP_ADD_MEMBERSHIP 35
1251#define IP_DROP_MEMBERSHIP 36
1252
1261
1268/* Socket options for IPPROTO_IPV6 level */
1270#define IPV6_UNICAST_HOPS 16
1271
1273#define IPV6_MULTICAST_HOPS 18
1274
1276#define IPV6_ADD_MEMBERSHIP 20
1277
1279#define IPV6_DROP_MEMBERSHIP 21
1280
1291
1293#define IPV6_V6ONLY 26
1294
1299#define IPV6_RECVPKTINFO 49
1300
1302#define IPV6_ADDR_PREFERENCES 72
1303
1305#define IPV6_PREFER_SRC_TMP 0x0001
1307#define IPV6_PREFER_SRC_PUBLIC 0x0002
1312#define IPV6_PREFER_SRC_PUBTMP_DEFAULT 0x0100
1314#define IPV6_PREFER_SRC_COA 0x0004
1316#define IPV6_PREFER_SRC_HOME 0x0400
1318#define IPV6_PREFER_SRC_CGA 0x0008
1320#define IPV6_PREFER_SRC_NONCGA 0x0800
1321
1330 unsigned int ipi6_ifindex;
1331};
1332
1334#define IPV6_TCLASS 67
1342#define SOMAXCONN 128
1349struct net_socket_register {
1350 int family;
1351 bool is_offloaded;
1352 bool (*is_supported)(int family, int type, int proto);
1353 int (*handler)(int family, int type, int proto);
1354#if defined(CONFIG_NET_SOCKETS_OBJ_CORE)
1355 /* Store also the name of the socket type in order to be able to
1356 * print it later.
1357 */
1358 const char * const name;
1359#endif
1360};
1361
1362#define NET_SOCKET_DEFAULT_PRIO CONFIG_NET_SOCKETS_PRIORITY_DEFAULT
1363
1364#define NET_SOCKET_GET_NAME(socket_name, prio) \
1365 __net_socket_register_##prio##_##socket_name
1366
1367#if defined(CONFIG_NET_SOCKETS_OBJ_CORE)
1368#define K_OBJ_TYPE_SOCK K_OBJ_TYPE_ID_GEN("SOCK")
1369
1370#define NET_SOCKET_REGISTER_NAME(_name) \
1371 .name = STRINGIFY(_name),
1372#else
1373#define NET_SOCKET_REGISTER_NAME(_name)
1374#endif
1375
1376#define _NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler, _is_offloaded) \
1377 static const STRUCT_SECTION_ITERABLE(net_socket_register, \
1378 NET_SOCKET_GET_NAME(socket_name, prio)) = { \
1379 .family = _family, \
1380 .is_offloaded = _is_offloaded, \
1381 .is_supported = _is_supported, \
1382 .handler = _handler, \
1383 NET_SOCKET_REGISTER_NAME(socket_name) \
1384 }
1385
1386#define NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler) \
1387 _NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler, false)
1388
1389#define NET_SOCKET_OFFLOAD_REGISTER(socket_name, prio, _family, _is_supported, _handler) \
1390 _NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler, true)
1391
1394#ifdef __cplusplus
1395}
1396#endif
1397
1398#include <zephyr/syscalls/socket.h>
1399
1404/* Avoid circular loops with POSIX socket headers.
1405 * We have these includes here so that we do not need
1406 * to change the applications that were only including
1407 * zephyr/net/socket.h header file.
1408 *
1409 * Additionally, if non-zephyr-prefixed headers are used here,
1410 * native_sim pulls in those from the host rather than Zephyr's.
1411 *
1412 * This should be removed when CONFIG_NET_SOCKETS_POSIX_NAMES is removed.
1413 */
1414#if defined(CONFIG_POSIX_API)
1415#if !defined(ZEPHYR_INCLUDE_POSIX_ARPA_INET_H_)
1416#include <zephyr/posix/arpa/inet.h>
1417#endif
1418#if !defined(ZEPHYR_INCLUDE_POSIX_NETDB_H_)
1419#include <zephyr/posix/netdb.h>
1420#endif
1421#if !defined(ZEPHYR_INCLUDE_POSIX_UNISTD_H_)
1422#include <zephyr/posix/unistd.h>
1423#endif
1424#if !defined(ZEPHYR_INCLUDE_POSIX_POLL_H_)
1425#include <zephyr/posix/poll.h>
1426#endif
1427#if !defined(ZEPHYR_INCLUDE_POSIX_SYS_SOCKET_H_)
1429#endif
1430#endif /* CONFIG_POSIX_API */
1431
1432#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:871
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:980
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:994
static int bind(int sock, const struct sockaddr *addr, socklen_t addrlen)
POSIX wrapper for zsock_bind.
Definition socket.h:895
static int gethostname(char *buf, size_t len)
POSIX wrapper for zsock_gethostname.
Definition socket.h:1026
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:940
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:1032
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:947
static ssize_t zsock_send(int sock, const void *buf, size_t len, int flags)
Send data to a connected peer.
Definition socket.h:478
static int getsockopt(int sock, int level, int optname, void *optval, socklen_t *optlen)
POSIX wrapper for zsock_getsockopt.
Definition socket.h:966
static int accept(int sock, struct sockaddr *addr, socklen_t *addrlen)
POSIX wrapper for zsock_accept.
Definition socket.h:914
static int listen(int sock, int backlog)
POSIX wrapper for zsock_listen.
Definition socket.h:908
static int close(int sock)
POSIX wrapper for zsock_close.
Definition socket.h:883
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:954
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:1014
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:541
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:973
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:987
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:1008
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:1104
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:932
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:920
static int socketpair(int family, int type, int proto, int sv[2])
POSIX wrapper for zsock_socketpair.
Definition socket.h:877
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:901
static ssize_t recv(int sock, void *buf, size_t max_len, int flags)
POSIX wrapper for zsock_recv.
Definition socket.h:926
static int poll(struct zsock_pollfd *fds, int nfds, int timeout)
POSIX wrapper for zsock_poll.
Definition socket.h:960
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:726
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:1038
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:1002
static int shutdown(int sock, int how)
POSIX wrapper for zsock_shutdown.
Definition socket.h:889
#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
BSD select support functions.
#define bool
Definition stdbool.h:13
Interface description structure.
Definition socket.h:1108
char ifr_name[Z_DEVICE_MAX_NAME_LEN]
Network interface name.
Definition socket.h:1109
IPv6 address struct.
Definition net_ip.h:142
Incoming IPv6 packet information.
Definition socket.h:1328
struct in6_addr ipi6_addr
Destination IPv6 address.
Definition socket.h:1329
unsigned int ipi6_ifindex
Receive interface index.
Definition socket.h:1330
IPv4 address struct.
Definition net_ip.h:154
Incoming IPv4 packet information.
Definition socket.h:1240
unsigned int ipi_ifindex
Network interface index.
Definition socket.h:1241
struct in_addr ipi_spec_dst
Local address.
Definition socket.h:1242
struct in_addr ipi_addr
Header Destination address.
Definition socket.h:1243
Struct used when joining or leaving a IPv4 multicast group.
Definition socket.h:1256
int imr_ifindex
Network interface index.
Definition socket.h:1259
struct in_addr imr_multiaddr
IP multicast group address.
Definition socket.h:1257
struct in_addr imr_address
IP address of local interface.
Definition socket.h:1258
Struct used when joining or leaving a IPv6 multicast group.
Definition socket.h:1284
struct in6_addr ipv6mr_multiaddr
IPv6 multicast address of group.
Definition socket.h:1286
int ipv6mr_ifindex
Network interface index of the local IPv6 address.
Definition socket.h:1289
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:28