Zephyr API Documentation  3.5.0
A Scalable Open Source RTOS
3.5.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
socket.h
Go to the documentation of this file.
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 <zephyr/net/socket.h>
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16struct linger {
19};
20
21#ifndef CONFIG_NET_SOCKETS_POSIX_NAMES
22
23static inline int socket(int family, int type, int proto)
24{
25 return zsock_socket(family, type, proto);
26}
27
28static inline int socketpair(int family, int type, int proto, int sv[2])
29{
30 return zsock_socketpair(family, type, proto, sv);
31}
32
33#define SHUT_RD ZSOCK_SHUT_RD
34#define SHUT_WR ZSOCK_SHUT_WR
35#define SHUT_RDWR ZSOCK_SHUT_RDWR
36
37#define MSG_PEEK ZSOCK_MSG_PEEK
38#define MSG_TRUNC ZSOCK_MSG_TRUNC
39#define MSG_DONTWAIT ZSOCK_MSG_DONTWAIT
40#define MSG_WAITALL ZSOCK_MSG_WAITALL
41
42static inline int shutdown(int sock, int how)
43{
44 return zsock_shutdown(sock, how);
45}
46
47static inline int bind(int sock, const struct sockaddr *addr, socklen_t addrlen)
48{
49 return zsock_bind(sock, addr, addrlen);
50}
51
52static inline int connect(int sock, const struct sockaddr *addr,
53 socklen_t addrlen)
54{
55 return zsock_connect(sock, addr, addrlen);
56}
57
58static inline int listen(int sock, int backlog)
59{
60 return zsock_listen(sock, backlog);
61}
62
63static inline int accept(int sock, struct sockaddr *addr, socklen_t *addrlen)
64{
65 return zsock_accept(sock, addr, addrlen);
66}
67
68static inline ssize_t send(int sock, const void *buf, size_t len, int flags)
69{
70 return zsock_send(sock, buf, len, flags);
71}
72
73static inline ssize_t recv(int sock, void *buf, size_t max_len, int flags)
74{
75 return zsock_recv(sock, buf, max_len, flags);
76}
77
78static inline ssize_t sendto(int sock, const void *buf, size_t len, int flags,
79 const struct sockaddr *dest_addr,
80 socklen_t addrlen)
81{
82 return zsock_sendto(sock, buf, len, flags, dest_addr, addrlen);
83}
84
85static inline ssize_t sendmsg(int sock, const struct msghdr *message,
86 int flags)
87{
88 return zsock_sendmsg(sock, message, flags);
89}
90
91static inline ssize_t recvfrom(int sock, void *buf, size_t max_len, int flags,
92 struct sockaddr *src_addr, socklen_t *addrlen)
93{
94 return zsock_recvfrom(sock, buf, max_len, flags, src_addr, addrlen);
95}
96
97static inline int getsockopt(int sock, int level, int optname,
98 void *optval, socklen_t *optlen)
99{
100 return zsock_getsockopt(sock, level, optname, optval, optlen);
101}
102
103static inline int setsockopt(int sock, int level, int optname,
104 const void *optval, socklen_t optlen)
105{
106 return zsock_setsockopt(sock, level, optname, optval, optlen);
107}
108
109static inline int getpeername(int sock, struct sockaddr *addr,
110 socklen_t *addrlen)
111{
112 return zsock_getpeername(sock, addr, addrlen);
113}
114
115static inline int getsockname(int sock, struct sockaddr *addr,
116 socklen_t *addrlen)
117{
118 return zsock_getsockname(sock, addr, addrlen);
119}
120
121#endif /* CONFIG_NET_SOCKETS_POSIX_NAMES */
122
123#ifdef __cplusplus
124}
125#endif
126
127#endif /* ZEPHYR_INCLUDE_POSIX_SYS_SOCKET_H_ */
static int socket(int family, int type, int proto)
POSIX wrapper for zsock_socket.
Definition: socket.h:754
static int getpeername(int sock, struct sockaddr *addr, socklen_t *addrlen)
POSIX wrapper for zsock_getpeername.
Definition: socket.h:886
int zsock_getpeername(int sock, struct sockaddr *addr, socklen_t *addrlen)
Get peer name.
static int bind(int sock, const struct sockaddr *addr, socklen_t addrlen)
POSIX wrapper for zsock_bind.
Definition: socket.h:778
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:852
int zsock_socketpair(int family, int type, int proto, int *sv)
Create an unnamed pair of connected sockets.
int zsock_accept(int sock, struct sockaddr *addr, socklen_t *addrlen)
Accept a connection on listening socket.
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:859
static ssize_t zsock_send(int sock, const void *buf, size_t len, int flags)
Send data to a connected peer.
Definition: socket.h:432
static int getsockopt(int sock, int level, int optname, void *optval, socklen_t *optlen)
POSIX wrapper for zsock_getsockopt.
Definition: socket.h:872
static int accept(int sock, struct sockaddr *addr, socklen_t *addrlen)
POSIX wrapper for zsock_accept.
Definition: socket.h:797
static int listen(int sock, int backlog)
POSIX wrapper for zsock_listen.
Definition: socket.h:791
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 zsock_recv(int sock, void *buf, size_t max_len, int flags)
Receive data from a connected peer.
Definition: socket.h:481
static int setsockopt(int sock, int level, int optname, const void *optval, socklen_t optlen)
POSIX wrapper for zsock_setsockopt.
Definition: socket.h:879
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:893
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.
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:844
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:803
static int socketpair(int family, int type, int proto, int sv[2])
POSIX wrapper for zsock_socketpair.
Definition: socket.h:760
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:784
static ssize_t recv(int sock, void *buf, size_t max_len, int flags)
POSIX wrapper for zsock_recv.
Definition: socket.h:809
int zsock_listen(int sock, int backlog)
Set up a STREAM socket to accept peer connections.
static int shutdown(int sock, int how)
POSIX wrapper for zsock_shutdown.
Definition: socket.h:772
size_t socklen_t
Length of a socket address.
Definition: net_ip.h:168
__SIZE_TYPE__ ssize_t
Definition: types.h:28
BSD Sockets compatible API definitions.
flags
Definition: parser.h:96
Definition: socket.h:16
int l_linger
Definition: socket.h:18
int l_onoff
Definition: socket.h:17
Definition: net_ip.h:238
Generic sockaddr struct.
Definition: net_ip.h:347