1 /*
2  * Copyright (c) 2019 Linaro Limited
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #ifndef ZEPHYR_INCLUDE_POSIX_SYS_SOCKET_H_
7 #define ZEPHYR_INCLUDE_POSIX_SYS_SOCKET_H_
8 
9 #include <sys/types.h>
10 #include <net/socket.h>
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
socket(int family,int type,int proto)16 static inline int socket(int family, int type, int proto)
17 {
18 	return zsock_socket(family, type, proto);
19 }
20 
socketpair(int family,int type,int proto,int sv[2])21 static inline int socketpair(int family, int type, int proto, int sv[2])
22 {
23 	return zsock_socketpair(family, type, proto, sv);
24 }
25 
26 #define SHUT_RD ZSOCK_SHUT_RD
27 #define SHUT_WR ZSOCK_SHUT_WR
28 #define SHUT_RDWR ZSOCK_SHUT_RDWR
29 
30 #define MSG_PEEK ZSOCK_MSG_PEEK
31 #define MSG_TRUNC ZSOCK_MSG_TRUNC
32 #define MSG_DONTWAIT ZSOCK_MSG_DONTWAIT
33 #define MSG_WAITALL ZSOCK_MSG_WAITALL
34 
shutdown(int sock,int how)35 static inline int shutdown(int sock, int how)
36 {
37 	return zsock_shutdown(sock, how);
38 }
39 
bind(int sock,const struct sockaddr * addr,socklen_t addrlen)40 static inline int bind(int sock, const struct sockaddr *addr, socklen_t addrlen)
41 {
42 	return zsock_bind(sock, addr, addrlen);
43 }
44 
connect(int sock,const struct sockaddr * addr,socklen_t addrlen)45 static inline int connect(int sock, const struct sockaddr *addr,
46 			  socklen_t addrlen)
47 {
48 	return zsock_connect(sock, addr, addrlen);
49 }
50 
listen(int sock,int backlog)51 static inline int listen(int sock, int backlog)
52 {
53 	return zsock_listen(sock, backlog);
54 }
55 
accept(int sock,struct sockaddr * addr,socklen_t * addrlen)56 static inline int accept(int sock, struct sockaddr *addr, socklen_t *addrlen)
57 {
58 	return zsock_accept(sock, addr, addrlen);
59 }
60 
send(int sock,const void * buf,size_t len,int flags)61 static inline ssize_t send(int sock, const void *buf, size_t len, int flags)
62 {
63 	return zsock_send(sock, buf, len, flags);
64 }
65 
recv(int sock,void * buf,size_t max_len,int flags)66 static inline ssize_t recv(int sock, void *buf, size_t max_len, int flags)
67 {
68 	return zsock_recv(sock, buf, max_len, flags);
69 }
70 
sendto(int sock,const void * buf,size_t len,int flags,const struct sockaddr * dest_addr,socklen_t addrlen)71 static inline ssize_t sendto(int sock, const void *buf, size_t len, int flags,
72 			     const struct sockaddr *dest_addr,
73 			     socklen_t addrlen)
74 {
75 	return zsock_sendto(sock, buf, len, flags, dest_addr, addrlen);
76 }
77 
sendmsg(int sock,const struct msghdr * message,int flags)78 static inline ssize_t sendmsg(int sock, const struct msghdr *message,
79 			      int flags)
80 {
81 	return zsock_sendmsg(sock, message, flags);
82 }
83 
recvfrom(int sock,void * buf,size_t max_len,int flags,struct sockaddr * src_addr,socklen_t * addrlen)84 static inline ssize_t recvfrom(int sock, void *buf, size_t max_len, int flags,
85 			       struct sockaddr *src_addr, socklen_t *addrlen)
86 {
87 	return zsock_recvfrom(sock, buf, max_len, flags, src_addr, addrlen);
88 }
89 
getsockopt(int sock,int level,int optname,void * optval,socklen_t * optlen)90 static inline int getsockopt(int sock, int level, int optname,
91 			     void *optval, socklen_t *optlen)
92 {
93 	return zsock_getsockopt(sock, level, optname, optval, optlen);
94 }
95 
setsockopt(int sock,int level,int optname,const void * optval,socklen_t optlen)96 static inline int setsockopt(int sock, int level, int optname,
97 			     const void *optval, socklen_t optlen)
98 {
99 	return zsock_setsockopt(sock, level, optname, optval, optlen);
100 }
101 
getsockname(int sock,struct sockaddr * addr,socklen_t * addrlen)102 static inline int getsockname(int sock, struct sockaddr *addr,
103 			      socklen_t *addrlen)
104 {
105 	return zsock_getsockname(sock, addr, addrlen);
106 }
107 
108 #ifdef __cplusplus
109 }
110 #endif
111 
112 #endif	/* ZEPHYR_INCLUDE_POSIX_SYS_SOCKET_H_ */
113