15#ifndef ZEPHYR_INCLUDE_NET_SOCKET_H_
16#define ZEPHYR_INCLUDE_NET_SOCKET_H_
46#define ZSOCK_POLLPRI 2
48#define ZSOCK_POLLOUT 4
50#define ZSOCK_POLLERR 8
52#define ZSOCK_POLLHUP 0x10
54#define ZSOCK_POLLNVAL 0x20
57#define ZSOCK_MSG_PEEK 0x02
61#define ZSOCK_MSG_TRUNC 0x20
63#define ZSOCK_MSG_DONTWAIT 0x40
65#define ZSOCK_MSG_WAITALL 0x100
72#define ZSOCK_SHUT_RD 0
74#define ZSOCK_SHUT_WR 1
76#define ZSOCK_SHUT_RDWR 2
92#define TLS_SEC_TAG_LIST 1
103#define TLS_CIPHERSUITE_LIST 3
108#define TLS_CIPHERSUITE_USED 4
119#define TLS_PEER_VERIFY 5
128#define TLS_DTLS_ROLE 6
134#define TLS_ALPN_LIST 7
139#define TLS_DTLS_HANDSHAKE_TIMEOUT_MIN 8
140#define TLS_DTLS_HANDSHAKE_TIMEOUT_MAX 9
145#define TLS_PEER_VERIFY_NONE 0
146#define TLS_PEER_VERIFY_OPTIONAL 1
147#define TLS_PEER_VERIFY_REQUIRED 2
150#define TLS_DTLS_ROLE_CLIENT 0
151#define TLS_DTLS_ROLE_SERVER 1
515 char *dst,
size_t size)
535__syscall
int z_zsock_getaddrinfo_internal(
const char *host,
544#define AI_PASSIVE 0x1
546#define AI_CANONNAME 0x2
548#define AI_NUMERICHOST 0x4
550#define AI_V4MAPPED 0x8
554#define AI_ADDRCONFIG 0x20
556#define AI_NUMERICSERV 0x400
603#define NI_NUMERICHOST 1
605#define NI_NUMERICSERV 2
636#if defined(CONFIG_NET_SOCKETS_POSIX_NAMES)
638#define pollfd zsock_pollfd
640static inline int socket(
int family,
int type,
int proto)
645static inline int socketpair(
int family,
int type,
int proto,
int sv[2])
650static inline int close(
int sock)
655static inline int shutdown(
int sock,
int how)
671static inline int listen(
int sock,
int backlog)
695static inline int zsock_fcntl_wrapper(
int sock,
int cmd, ...)
701 flags = va_arg(args,
int);
706#define fcntl zsock_fcntl_wrapper
732static inline int getsockopt(
int sock,
int level,
int optname,
738static inline int setsockopt(
int sock,
int level,
int optname,
750static inline int getaddrinfo(
const char *host,
const char *service,
772 serv, servlen,
flags);
775#define addrinfo zsock_addrinfo
777static inline int gethostname(
char *buf,
size_t len)
793#define POLLIN ZSOCK_POLLIN
794#define POLLOUT ZSOCK_POLLOUT
795#define POLLERR ZSOCK_POLLERR
796#define POLLHUP ZSOCK_POLLHUP
797#define POLLNVAL ZSOCK_POLLNVAL
799#define MSG_PEEK ZSOCK_MSG_PEEK
800#define MSG_TRUNC ZSOCK_MSG_TRUNC
801#define MSG_DONTWAIT ZSOCK_MSG_DONTWAIT
802#define MSG_WAITALL ZSOCK_MSG_WAITALL
804#define SHUT_RD ZSOCK_SHUT_RD
805#define SHUT_WR ZSOCK_SHUT_WR
806#define SHUT_RDWR ZSOCK_SHUT_RDWR
808#define EAI_BADFLAGS DNS_EAI_BADFLAGS
809#define EAI_NONAME DNS_EAI_NONAME
810#define EAI_AGAIN DNS_EAI_AGAIN
811#define EAI_FAIL DNS_EAI_FAIL
812#define EAI_NODATA DNS_EAI_NODATA
813#define EAI_MEMORY DNS_EAI_MEMORY
814#define EAI_SYSTEM DNS_EAI_SYSTEM
815#define EAI_SERVICE DNS_EAI_SERVICE
816#define EAI_SOCKTYPE DNS_EAI_SOCKTYPE
817#define EAI_FAMILY DNS_EAI_FAMILY
820#define IFNAMSIZ Z_DEVICE_MAX_NAME_LEN
832#define SO_REUSEADDR 2
842#define SO_RCVTIMEO 20
844#define SO_SNDTIMEO 21
847#define SO_BINDTODEVICE 25
850#define SO_TIMESTAMPING 37
852#define SO_PROTOCOL 38
860#define IPV6_V6ONLY 26
863#define SO_PRIORITY 12
867#define SCM_TXTIME SO_TXTIME
877struct net_socket_register {
879 bool (*is_supported)(
int family,
int type,
int proto);
880 int (*
handler)(
int family,
int type,
int proto);
883#define NET_SOCKET_GET_NAME(socket_name) \
884 (__net_socket_register_##socket_name)
886#define NET_SOCKET_REGISTER(socket_name, _family, _is_supported, _handler) \
887 static const STRUCT_SECTION_ITERABLE(net_socket_register, \
888 NET_SOCKET_GET_NAME(socket_name)) = { \
890 .is_supported = _is_supported, \
891 .handler = _handler, \
900#include <syscalls/socket.h>
ZTEST_BMEM int timeout
Definition: main.c:31
int zsock_fcntl(int sock, int cmd, int flags)
Control blocking/non-blocking mode of a socket.
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.
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 ssize_t zsock_send(int sock, const void *buf, size_t len, int flags)
Send data to a connected peer.
Definition: socket.h:352
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.
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:401
int zsock_gethostname(char *buf, size_t len)
Get local host name.
int zsock_getsockname(int sock, struct sockaddr *addr, socklen_t *addrlen)
Get socket name.
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_shutdown(int sock, int how)
Shutdown socket send/receive operations.
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
Definition: socket.h:820
int zsock_setsockopt(int sock, int level, int optname, const void *optval, socklen_t optlen)
Set various socket options.
ssize_t zsock_sendmsg(int sock, const struct msghdr *msg, int flags)
Send data to an arbitrary network address.
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:514
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.
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.
#define DNS_MAX_NAME_SIZE
Definition: dns_resolve.h:42
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
Definition: net_ip.h:158
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
Definition: net_ip.h:161
flags
Definition: http_parser.h:131
static int inet_pton(sa_family_t family, const char *src, void *dst)
Definition: inet.h:21
static char * inet_ntop(sa_family_t family, const void *src, char *dst, size_t size)
Definition: inet.h:15
__SIZE_TYPE__ ssize_t
Definition: types.h:28
IPv6 and IPv4 definitions.
static int getaddrinfo(const char *host, const char *service, const struct zsock_addrinfo *hints, struct zsock_addrinfo **res)
Definition: netdb.h:17
static int getnameinfo(const struct sockaddr *addr, socklen_t addrlen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, int flags)
Definition: netdb.h:34
static const char * gai_strerror(int errcode)
Definition: netdb.h:29
static void freeaddrinfo(struct zsock_addrinfo *ai)
Definition: netdb.h:24
static int poll(struct zsock_pollfd *fds, int nfds, int timeout)
Definition: poll.h:23
static ssize_t sendmsg(int sock, const struct msghdr *message, int flags)
Definition: socket.h:78
static ssize_t recvfrom(int sock, void *buf, size_t max_len, int flags, struct sockaddr *src_addr, socklen_t *addrlen)
Definition: socket.h:84
static int getsockopt(int sock, int level, int optname, void *optval, socklen_t *optlen)
Definition: socket.h:90
static int setsockopt(int sock, int level, int optname, const void *optval, socklen_t optlen)
Definition: socket.h:96
static int getsockname(int sock, struct sockaddr *addr, socklen_t *addrlen)
Definition: socket.h:102
static int socketpair(int family, int type, int proto, int sv[2])
Definition: socket.h:21
static int shutdown(int sock, int how)
Definition: socket.h:35
#define bool
Definition: stdbool.h:13
char ifr_name[Z_DEVICE_MAX_NAME_LEN]
Definition: socket.h:824
struct zsock_addrinfo * ai_next
Definition: socket.h:154
int ai_family
Definition: socket.h:156
int ai_flags
Definition: socket.h:155
char * ai_canonname
Definition: socket.h:161
int ai_protocol
Definition: socket.h:158
struct sockaddr * ai_addr
Definition: socket.h:160
int ai_socktype
Definition: socket.h:157
socklen_t ai_addrlen
Definition: socket.h:159
short events
Definition: socket.h:38
int fd
Definition: socket.h:37
short revents
Definition: socket.h:39
static void handler(struct k_timer *timer)
Definition: main.c:19
NMI_API SOCKET socket(uint16 u16Domain, uint8 u8Type, uint8 u8Flags)
NMI_API sint8 close(SOCKET sock)
NMI_API sint8 connect(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen)
NMI_API sint8 listen(SOCKET sock, uint8 backlog)
NMI_API sint16 sendto(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 flags, struct sockaddr *pstrDestAddr, uint8 u8AddrLen)
NMI_API sint16 send(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 u16Flags)
NMI_API sint8 bind(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen)
NMI_API sint8 accept(SOCKET sock, struct sockaddr *addr, uint8 *addrlen)
NMI_API sint16 recv(SOCKET sock, void *pvRecvBuf, uint16 u16BufLen, uint32 u32Timeoutmsec)