Zephyr Project API 3.7.0
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>
35#include <stdlib.h>
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
45/* ZSOCK_POLL* values are compatible with Linux */
47#define ZSOCK_POLLIN 1
49#define ZSOCK_POLLPRI 2
51#define ZSOCK_POLLOUT 4
53#define ZSOCK_POLLERR 8
55#define ZSOCK_POLLHUP 0x10
57#define ZSOCK_POLLNVAL 0x20
65#define ZSOCK_MSG_PEEK 0x02
68#define ZSOCK_MSG_CTRUNC 0x08
72#define ZSOCK_MSG_TRUNC 0x20
74#define ZSOCK_MSG_DONTWAIT 0x40
76#define ZSOCK_MSG_WAITALL 0x100
83/* Well-known values, e.g. from Linux man 2 shutdown:
84 * "The constants SHUT_RD, SHUT_WR, SHUT_RDWR have the value 0, 1, 2,
85 * respectively". Some software uses numeric values.
86 */
88#define ZSOCK_SHUT_RD 0
90#define ZSOCK_SHUT_WR 1
92#define ZSOCK_SHUT_RDWR 2
107#define SOL_TLS 282
108
113#define TLS_SEC_TAG_LIST 1
118#define TLS_HOSTNAME 2
124#define TLS_CIPHERSUITE_LIST 3
129#define TLS_CIPHERSUITE_USED 4
140#define TLS_PEER_VERIFY 5
149#define TLS_DTLS_ROLE 6
155#define TLS_ALPN_LIST 7
160#define TLS_DTLS_HANDSHAKE_TIMEOUT_MIN 8
161
166#define TLS_DTLS_HANDSHAKE_TIMEOUT_MAX 9
167
172#define TLS_CERT_NOCOPY 10
183#define TLS_NATIVE 11
188#define TLS_SESSION_CACHE 12
192#define TLS_SESSION_CACHE_PURGE 13
204#define TLS_DTLS_CID 14
214#define TLS_DTLS_CID_STATUS 15
219#define TLS_DTLS_CID_VALUE 16
226#define TLS_DTLS_PEER_CID_VALUE 17
234#define TLS_DTLS_HANDSHAKE_ON_CONNECT 18
235
236/* Valid values for @ref TLS_PEER_VERIFY option */
237#define TLS_PEER_VERIFY_NONE 0
238#define TLS_PEER_VERIFY_OPTIONAL 1
239#define TLS_PEER_VERIFY_REQUIRED 2
241/* Valid values for @ref TLS_DTLS_ROLE option */
242#define TLS_DTLS_ROLE_CLIENT 0
243#define TLS_DTLS_ROLE_SERVER 1
245/* Valid values for @ref TLS_CERT_NOCOPY option */
246#define TLS_CERT_NOCOPY_NONE 0
247#define TLS_CERT_NOCOPY_OPTIONAL 1
249/* Valid values for @ref TLS_SESSION_CACHE option */
250#define TLS_SESSION_CACHE_DISABLED 0
251#define TLS_SESSION_CACHE_ENABLED 1
253/* Valid values for @ref TLS_DTLS_CID (Connection ID) option */
254#define TLS_DTLS_CID_DISABLED 0
255#define TLS_DTLS_CID_SUPPORTED 1
256#define TLS_DTLS_CID_ENABLED 2
258/* Valid values for @ref TLS_DTLS_CID_STATUS option */
259#define TLS_DTLS_CID_STATUS_DISABLED 0
260#define TLS_DTLS_CID_STATUS_DOWNLINK 1
261#define TLS_DTLS_CID_STATUS_UPLINK 2
262#define TLS_DTLS_CID_STATUS_BIDIRECTIONAL 3
/* for @name */ /* for @defgroup */
265
284 struct sockaddr _ai_addr;
285 char _ai_canonname[DNS_MAX_NAME_SIZE + 1];
287};
288
325__syscall void *zsock_get_context_object(int sock);
326
344__syscall int zsock_socket(int family, int type, int proto);
345
358__syscall int zsock_socketpair(int family, int type, int proto, int *sv);
359
371__syscall int zsock_close(int sock);
372
386__syscall int zsock_shutdown(int sock, int how);
387
400__syscall int zsock_bind(int sock, const struct sockaddr *addr,
401 socklen_t addrlen);
402
415__syscall int zsock_connect(int sock, const struct sockaddr *addr,
416 socklen_t addrlen);
417
430__syscall int zsock_listen(int sock, int backlog);
431
444__syscall int zsock_accept(int sock, struct sockaddr *addr, socklen_t *addrlen);
445
458__syscall ssize_t zsock_sendto(int sock, const void *buf, size_t len,
459 int flags, const struct sockaddr *dest_addr,
460 socklen_t addrlen);
461
474static inline ssize_t zsock_send(int sock, const void *buf, size_t len,
475 int flags)
476{
477 return zsock_sendto(sock, buf, len, flags, NULL, 0);
478}
479
492__syscall ssize_t zsock_sendmsg(int sock, const struct msghdr *msg,
493 int flags);
494
507__syscall ssize_t zsock_recvfrom(int sock, void *buf, size_t max_len,
508 int flags, struct sockaddr *src_addr,
509 socklen_t *addrlen);
510
523__syscall ssize_t zsock_recvmsg(int sock, struct msghdr *msg, int flags);
524
537static inline ssize_t zsock_recv(int sock, void *buf, size_t max_len,
538 int flags)
539{
540 return zsock_recvfrom(sock, buf, max_len, flags, NULL, NULL);
541}
542
555__syscall int zsock_fcntl_impl(int sock, int cmd, int flags);
556
559/*
560 * Need this wrapper because newer GCC versions got too smart and "typecheck"
561 * even macros.
562 */
563static inline int zsock_fcntl_wrapper(int sock, int cmd, ...)
564{
565 va_list args;
566 int flags;
567
568 va_start(args, cmd);
569 flags = va_arg(args, int);
570 va_end(args);
571 return zsock_fcntl_impl(sock, cmd, flags);
572}
573
574#define zsock_fcntl zsock_fcntl_wrapper
575
595__syscall int zsock_ioctl_impl(int sock, unsigned long request, va_list ap);
596
599static inline int zsock_ioctl_wrapper(int sock, unsigned long request, ...)
600{
601 int ret;
602 va_list args;
603
604 va_start(args, request);
605 ret = zsock_ioctl_impl(sock, request, args);
606 va_end(args);
607
608 return ret;
609}
610
611#define zsock_ioctl zsock_ioctl_wrapper
612
628__syscall int zsock_poll(struct zsock_pollfd *fds, int nfds, int timeout);
629
645__syscall int zsock_getsockopt(int sock, int level, int optname,
646 void *optval, socklen_t *optlen);
647
663__syscall int zsock_setsockopt(int sock, int level, int optname,
664 const void *optval, socklen_t optlen);
665
678__syscall int zsock_getpeername(int sock, struct sockaddr *addr,
679 socklen_t *addrlen);
680
693__syscall int zsock_getsockname(int sock, struct sockaddr *addr,
694 socklen_t *addrlen);
695
708__syscall int zsock_gethostname(char *buf, size_t len);
709
722static inline char *zsock_inet_ntop(sa_family_t family, const void *src,
723 char *dst, size_t size)
724{
725 return net_addr_ntop(family, src, dst, size);
726}
727
740__syscall int zsock_inet_pton(sa_family_t family, const char *src, void *dst);
741
743__syscall int z_zsock_getaddrinfo_internal(const char *host,
744 const char *service,
745 const struct zsock_addrinfo *hints,
746 struct zsock_addrinfo *res);
749/* Flags for getaddrinfo() hints. */
750
756#define AI_PASSIVE 0x1
758#define AI_CANONNAME 0x2
760#define AI_NUMERICHOST 0x4
762#define AI_V4MAPPED 0x8
764#define AI_ALL 0x10
766#define AI_ADDRCONFIG 0x20
768#define AI_NUMERICSERV 0x400
770#define AI_EXTFLAGS 0x800
785int zsock_getaddrinfo(const char *host, const char *service,
786 const struct zsock_addrinfo *hints,
787 struct zsock_addrinfo **res);
788
802
815const char *zsock_gai_strerror(int errcode);
816
822#define NI_NUMERICHOST 1
824#define NI_NUMERICSERV 2
826#define NI_NOFQDN 4
828#define NI_NAMEREQD 8
830#define NI_DGRAM 16
831
832/* POSIX extensions */
833
835#ifndef NI_MAXHOST
836#define NI_MAXHOST 64
837#endif
852int zsock_getnameinfo(const struct sockaddr *addr, socklen_t addrlen,
853 char *host, socklen_t hostlen,
854 char *serv, socklen_t servlen, int flags);
855
856#if defined(CONFIG_NET_SOCKETS_POSIX_NAMES)
857
864#define pollfd zsock_pollfd
865
867static inline int socket(int family, int type, int proto)
868{
869 return zsock_socket(family, type, proto);
870}
871
873static inline int socketpair(int family, int type, int proto, int sv[2])
874{
875 return zsock_socketpair(family, type, proto, sv);
876}
877
879static inline int close(int sock)
880{
881 return zsock_close(sock);
882}
883
885static inline int shutdown(int sock, int how)
886{
887 return zsock_shutdown(sock, how);
888}
889
891static inline int bind(int sock, const struct sockaddr *addr, socklen_t addrlen)
892{
893 return zsock_bind(sock, addr, addrlen);
894}
895
897static inline int connect(int sock, const struct sockaddr *addr,
898 socklen_t addrlen)
899{
900 return zsock_connect(sock, addr, addrlen);
901}
902
904static inline int listen(int sock, int backlog)
905{
906 return zsock_listen(sock, backlog);
907}
908
910static inline int accept(int sock, struct sockaddr *addr, socklen_t *addrlen)
911{
912 return zsock_accept(sock, addr, addrlen);
913}
914
916static inline ssize_t send(int sock, const void *buf, size_t len, int flags)
917{
918 return zsock_send(sock, buf, len, flags);
919}
920
922static inline ssize_t recv(int sock, void *buf, size_t max_len, int flags)
923{
924 return zsock_recv(sock, buf, max_len, flags);
925}
926
928static inline ssize_t sendto(int sock, const void *buf, size_t len, int flags,
929 const struct sockaddr *dest_addr,
930 socklen_t addrlen)
931{
932 return zsock_sendto(sock, buf, len, flags, dest_addr, addrlen);
933}
934
936static inline ssize_t sendmsg(int sock, const struct msghdr *message,
937 int flags)
938{
939 return zsock_sendmsg(sock, message, flags);
940}
941
943static inline ssize_t recvfrom(int sock, void *buf, size_t max_len, int flags,
944 struct sockaddr *src_addr, socklen_t *addrlen)
945{
946 return zsock_recvfrom(sock, buf, max_len, flags, src_addr, addrlen);
947}
948
950static inline ssize_t recvmsg(int sock, struct msghdr *msg, int flags)
951{
952 return zsock_recvmsg(sock, msg, flags);
953}
954
956static inline int poll(struct zsock_pollfd *fds, int nfds, int timeout)
957{
958 return zsock_poll(fds, nfds, timeout);
959}
960
962static inline int getsockopt(int sock, int level, int optname,
963 void *optval, socklen_t *optlen)
964{
965 return zsock_getsockopt(sock, level, optname, optval, optlen);
966}
967
969static inline int setsockopt(int sock, int level, int optname,
970 const void *optval, socklen_t optlen)
971{
972 return zsock_setsockopt(sock, level, optname, optval, optlen);
973}
974
976static inline int getpeername(int sock, struct sockaddr *addr,
977 socklen_t *addrlen)
978{
979 return zsock_getpeername(sock, addr, addrlen);
980}
981
983static inline int getsockname(int sock, struct sockaddr *addr,
984 socklen_t *addrlen)
985{
986 return zsock_getsockname(sock, addr, addrlen);
987}
988
990static inline int getaddrinfo(const char *host, const char *service,
991 const struct zsock_addrinfo *hints,
992 struct zsock_addrinfo **res)
993{
994 return zsock_getaddrinfo(host, service, hints, res);
995}
996
998static inline void freeaddrinfo(struct zsock_addrinfo *ai)
999{
1001}
1002
1004static inline const char *gai_strerror(int errcode)
1005{
1006 return zsock_gai_strerror(errcode);
1007}
1008
1010static inline int getnameinfo(const struct sockaddr *addr, socklen_t addrlen,
1011 char *host, socklen_t hostlen,
1012 char *serv, socklen_t servlen, int flags)
1013{
1014 return zsock_getnameinfo(addr, addrlen, host, hostlen,
1015 serv, servlen, flags);
1016}
1017
1019#define addrinfo zsock_addrinfo
1020
1022static inline int gethostname(char *buf, size_t len)
1023{
1024 return zsock_gethostname(buf, len);
1025}
1026
1028static inline int inet_pton(sa_family_t family, const char *src, void *dst)
1029{
1030 return zsock_inet_pton(family, src, dst);
1031}
1032
1034static inline char *inet_ntop(sa_family_t family, const void *src, char *dst,
1035 size_t size)
1036{
1037 return zsock_inet_ntop(family, src, dst, size);
1038}
1039
1041#define POLLIN ZSOCK_POLLIN
1043#define POLLOUT ZSOCK_POLLOUT
1045#define POLLERR ZSOCK_POLLERR
1047#define POLLHUP ZSOCK_POLLHUP
1049#define POLLNVAL ZSOCK_POLLNVAL
1050
1052#define MSG_PEEK ZSOCK_MSG_PEEK
1054#define MSG_CTRUNC ZSOCK_MSG_CTRUNC
1056#define MSG_TRUNC ZSOCK_MSG_TRUNC
1058#define MSG_DONTWAIT ZSOCK_MSG_DONTWAIT
1060#define MSG_WAITALL ZSOCK_MSG_WAITALL
1061
1063#define SHUT_RD ZSOCK_SHUT_RD
1065#define SHUT_WR ZSOCK_SHUT_WR
1067#define SHUT_RDWR ZSOCK_SHUT_RDWR
1068
1070#define EAI_BADFLAGS DNS_EAI_BADFLAGS
1072#define EAI_NONAME DNS_EAI_NONAME
1074#define EAI_AGAIN DNS_EAI_AGAIN
1076#define EAI_FAIL DNS_EAI_FAIL
1078#define EAI_NODATA DNS_EAI_NODATA
1080#define EAI_MEMORY DNS_EAI_MEMORY
1082#define EAI_SYSTEM DNS_EAI_SYSTEM
1084#define EAI_SERVICE DNS_EAI_SERVICE
1086#define EAI_SOCKTYPE DNS_EAI_SOCKTYPE
1088#define EAI_FAMILY DNS_EAI_FAMILY
1090#endif /* defined(CONFIG_NET_SOCKETS_POSIX_NAMES) */
1091
1097#if defined(CONFIG_NET_INTERFACE_NAME)
1098#define IFNAMSIZ CONFIG_NET_INTERFACE_NAME_LEN
1099#else
1100#define IFNAMSIZ Z_DEVICE_MAX_NAME_LEN
1101#endif
1102
1104struct ifreq {
1106};
1114#define SOL_SOCKET 1
1115
1116/* Socket options for SOL_SOCKET level */
1117
1119#define SO_DEBUG 1
1121#define SO_REUSEADDR 2
1123#define SO_TYPE 3
1125#define SO_ERROR 4
1127#define SO_DONTROUTE 5
1129#define SO_BROADCAST 6
1130
1132#define SO_SNDBUF 7
1134#define SO_RCVBUF 8
1135
1137#define SO_KEEPALIVE 9
1139#define SO_OOBINLINE 10
1141#define SO_PRIORITY 12
1143#define SO_LINGER 13
1145#define SO_REUSEPORT 15
1146
1148#define SO_RCVLOWAT 18
1150#define SO_SNDLOWAT 19
1151
1156#define SO_RCVTIMEO 20
1158#define SO_SNDTIMEO 21
1159
1161#define SO_BINDTODEVICE 25
1162
1164#define SO_ACCEPTCONN 30
1165
1167#define SO_TIMESTAMPING 37
1168
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
1186#define SOF_TIMESTAMPING_RX_HARDWARE BIT(0)
1191#define SOF_TIMESTAMPING_TX_HARDWARE BIT(1)
1192
1201/* Socket options for IPPROTO_TCP level */
1203#define TCP_NODELAY 1
1205#define TCP_KEEPIDLE 2
1207#define TCP_KEEPINTVL 3
1209#define TCP_KEEPCNT 4
1210
1217/* Socket options for IPPROTO_IP level */
1219#define IP_TOS 1
1220
1222#define IP_TTL 2
1223
1228#define IP_PKTINFO 8
1229
1237 unsigned int ipi_ifindex;
1240};
1241
1243#define IP_MULTICAST_TTL 33
1245#define IP_ADD_MEMBERSHIP 35
1247#define IP_DROP_MEMBERSHIP 36
1248
1257
1264/* Socket options for IPPROTO_IPV6 level */
1266#define IPV6_UNICAST_HOPS 16
1267
1269#define IPV6_MULTICAST_HOPS 18
1270
1272#define IPV6_ADD_MEMBERSHIP 20
1273
1275#define IPV6_DROP_MEMBERSHIP 21
1276
1287
1289#define IPV6_V6ONLY 26
1290
1295#define IPV6_RECVPKTINFO 49
1296
1298#define IPV6_ADDR_PREFERENCES 72
1299
1301#define IPV6_PREFER_SRC_TMP 0x0001
1303#define IPV6_PREFER_SRC_PUBLIC 0x0002
1308#define IPV6_PREFER_SRC_PUBTMP_DEFAULT 0x0100
1310#define IPV6_PREFER_SRC_COA 0x0004
1312#define IPV6_PREFER_SRC_HOME 0x0400
1314#define IPV6_PREFER_SRC_CGA 0x0008
1316#define IPV6_PREFER_SRC_NONCGA 0x0800
1317
1326 unsigned int ipi6_ifindex;
1327};
1328
1330#define IPV6_TCLASS 67
1338#define SOMAXCONN 128
1345struct net_socket_register {
1346 int family;
1347 bool is_offloaded;
1348 bool (*is_supported)(int family, int type, int proto);
1349 int (*handler)(int family, int type, int proto);
1350#if defined(CONFIG_NET_SOCKETS_OBJ_CORE)
1351 /* Store also the name of the socket type in order to be able to
1352 * print it later.
1353 */
1354 const char * const name;
1355#endif
1356};
1357
1358#define NET_SOCKET_DEFAULT_PRIO CONFIG_NET_SOCKETS_PRIORITY_DEFAULT
1359
1360#define NET_SOCKET_GET_NAME(socket_name, prio) \
1361 __net_socket_register_##prio##_##socket_name
1362
1363#if defined(CONFIG_NET_SOCKETS_OBJ_CORE)
1364#define K_OBJ_TYPE_SOCK K_OBJ_TYPE_ID_GEN("SOCK")
1365
1366#define NET_SOCKET_REGISTER_NAME(_name) \
1367 .name = STRINGIFY(_name),
1368#else
1369#define NET_SOCKET_REGISTER_NAME(_name)
1370#endif
1371
1372#define _NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler, _is_offloaded) \
1373 static const STRUCT_SECTION_ITERABLE(net_socket_register, \
1374 NET_SOCKET_GET_NAME(socket_name, prio)) = { \
1375 .family = _family, \
1376 .is_offloaded = _is_offloaded, \
1377 .is_supported = _is_supported, \
1378 .handler = _handler, \
1379 NET_SOCKET_REGISTER_NAME(socket_name) \
1380 }
1381
1382#define NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler) \
1383 _NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler, false)
1384
1385#define NET_SOCKET_OFFLOAD_REGISTER(socket_name, prio, _family, _is_supported, _handler) \
1386 _NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler, true)
1387
1390#ifdef __cplusplus
1391}
1392#endif
1393
1394#include <zephyr/syscalls/socket.h>
1395
1400/* Avoid circular loops with POSIX socket headers.
1401 * We have these includes here so that we do not need
1402 * to change the applications that were only including
1403 * zephyr/net/socket.h header file.
1404 *
1405 * Additionally, if non-zephyr-prefixed headers are used here,
1406 * native_sim pulls in those from the host rather than Zephyr's.
1407 *
1408 * This should be removed when CONFIG_NET_SOCKETS_POSIX_NAMES is removed.
1409 */
1410#if defined(CONFIG_POSIX_API)
1411#if !defined(ZEPHYR_INCLUDE_POSIX_ARPA_INET_H_)
1412#include <zephyr/posix/arpa/inet.h>
1413#endif
1414#if !defined(ZEPHYR_INCLUDE_POSIX_NETDB_H_)
1415#include <zephyr/posix/netdb.h>
1416#endif
1417#if !defined(ZEPHYR_INCLUDE_POSIX_UNISTD_H_)
1418#include <zephyr/posix/unistd.h>
1419#endif
1420#if !defined(ZEPHYR_INCLUDE_POSIX_POLL_H_)
1421#include <zephyr/posix/poll.h>
1422#endif
1423#if !defined(ZEPHYR_INCLUDE_POSIX_SYS_SOCKET_H_)
1425#endif
1426#endif /* CONFIG_POSIX_API */
1427
1428#endif /* ZEPHYR_INCLUDE_NET_SOCKET_H_ */
ZTEST_BMEM int timeout
Definition main.c:31
DNS resolving library.
static int socket(int family, int type, int proto)
POSIX wrapper for zsock_socket.
Definition socket.h:867
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:976
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:990
static int bind(int sock, const struct sockaddr *addr, socklen_t addrlen)
POSIX wrapper for zsock_bind.
Definition socket.h:891
static int gethostname(char *buf, size_t len)
POSIX wrapper for zsock_gethostname.
Definition socket.h:1022
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:936
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:1028
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:943
static ssize_t zsock_send(int sock, const void *buf, size_t len, int flags)
Send data to a connected peer.
Definition socket.h:474
static int getsockopt(int sock, int level, int optname, void *optval, socklen_t *optlen)
POSIX wrapper for zsock_getsockopt.
Definition socket.h:962
static int accept(int sock, struct sockaddr *addr, socklen_t *addrlen)
POSIX wrapper for zsock_accept.
Definition socket.h:910
static int listen(int sock, int backlog)
POSIX wrapper for zsock_listen.
Definition socket.h:904
static int close(int sock)
POSIX wrapper for zsock_close.
Definition socket.h:879
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:950
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:1010
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:537
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:969
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:983
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:1004
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:1100
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:928
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:916
static int socketpair(int family, int type, int proto, int sv[2])
POSIX wrapper for zsock_socketpair.
Definition socket.h:873
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:897
static ssize_t recv(int sock, void *buf, size_t max_len, int flags)
POSIX wrapper for zsock_recv.
Definition socket.h:922
static int poll(struct zsock_pollfd *fds, int nfds, int timeout)
POSIX wrapper for zsock_poll.
Definition socket.h:956
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:722
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:1034
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:998
static int shutdown(int sock, int how)
POSIX wrapper for zsock_shutdown.
Definition socket.h:885
#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
static ZTEST_BMEM int ret
Definition main.c:16
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:1104
char ifr_name[Z_DEVICE_MAX_NAME_LEN]
Network interface name.
Definition socket.h:1105
IPv6 address struct.
Definition net_ip.h:139
Incoming IPv6 packet information.
Definition socket.h:1324
struct in6_addr ipi6_addr
Destination IPv6 address.
Definition socket.h:1325
unsigned int ipi6_ifindex
Receive interface index.
Definition socket.h:1326
IPv4 address struct.
Definition net_ip.h:151
Incoming IPv4 packet information.
Definition socket.h:1236
unsigned int ipi_ifindex
Network interface index.
Definition socket.h:1237
struct in_addr ipi_spec_dst
Local address.
Definition socket.h:1238
struct in_addr ipi_addr
Header Destination address.
Definition socket.h:1239
Struct used when joining or leaving a IPv4 multicast group.
Definition socket.h:1252
int imr_ifindex
Network interface index.
Definition socket.h:1255
struct in_addr imr_multiaddr
IP multicast group address.
Definition socket.h:1253
struct in_addr imr_address
IP address of local interface.
Definition socket.h:1254
Struct used when joining or leaving a IPv6 multicast group.
Definition socket.h:1280
struct in6_addr ipv6mr_multiaddr
IPv6 multicast address of group.
Definition socket.h:1282
int ipv6mr_ifindex
Network interface index of the local IPv6 address.
Definition socket.h:1285
Message struct.
Definition net_ip.h:247
Generic sockaddr struct.
Definition net_ip.h:385
Definition used when querying address information.
Definition socket.h:272
struct zsock_addrinfo * ai_next
Pointer to next address entry.
Definition socket.h:273
int ai_family
Address family of the returned addresses.
Definition socket.h:275
int ai_flags
Additional options.
Definition socket.h:274
char * ai_canonname
Optional official name of the host.
Definition socket.h:281
int ai_protocol
Protocol for addresses, 0 means any protocol.
Definition socket.h:277
struct sockaddr * ai_addr
Pointer to the address.
Definition socket.h:280
int ai_socktype
Socket type, for example SOCK_STREAM or SOCK_DGRAM.
Definition socket.h:276
int ai_eflags
Extended flags for special usage.
Definition socket.h:278
socklen_t ai_addrlen
Length of the socket address.
Definition socket.h:279
Definition of the monitored socket/file descriptor.
Definition socket_poll.h:28
static void msg(uint64_t c64)
Definition main.c:17
static void handler(struct k_timer *timer)
Definition main.c:19