Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
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 <net/socket.h>
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16static inline int socket(int family, int type, int proto)
17{
18 return zsock_socket(family, type, proto);
19}
20
21static 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
35static inline int shutdown(int sock, int how)
36{
37 return zsock_shutdown(sock, how);
38}
39
40static inline int bind(int sock, const struct sockaddr *addr, socklen_t addrlen)
41{
42 return zsock_bind(sock, addr, addrlen);
43}
44
45static inline int connect(int sock, const struct sockaddr *addr,
46 socklen_t addrlen)
47{
48 return zsock_connect(sock, addr, addrlen);
49}
50
51static inline int listen(int sock, int backlog)
52{
53 return zsock_listen(sock, backlog);
54}
55
56static inline int accept(int sock, struct sockaddr *addr, socklen_t *addrlen)
57{
58 return zsock_accept(sock, addr, addrlen);
59}
60
61static 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
66static 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
71static 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
78static inline ssize_t sendmsg(int sock, const struct msghdr *message,
79 int flags)
80{
81 return zsock_sendmsg(sock, message, flags);
82}
83
84static 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
90static 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
96static 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
102static 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_ */
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.
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.
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_getsockname(int sock, struct sockaddr *addr, socklen_t *addrlen)
Get socket name.
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.
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.
int zsock_listen(int sock, int backlog)
Set up a STREAM socket to accept peer connections.
size_t socklen_t
Definition: net_ip.h:161
flags
Definition: http_parser.h:131
__SIZE_TYPE__ ssize_t
Definition: types.h:28
BSD Sockets compatible API definitions.
static int socket(int family, int type, int proto)
Definition: socket.h:16
static int bind(int sock, const struct sockaddr *addr, socklen_t addrlen)
Definition: socket.h:40
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 accept(int sock, struct sockaddr *addr, socklen_t *addrlen)
Definition: socket.h:56
static int listen(int sock, int backlog)
Definition: socket.h:51
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 ssize_t sendto(int sock, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen)
Definition: socket.h:71
static ssize_t send(int sock, const void *buf, size_t len, int flags)
Definition: socket.h:61
static int socketpair(int family, int type, int proto, int sv[2])
Definition: socket.h:21
static int connect(int sock, const struct sockaddr *addr, socklen_t addrlen)
Definition: socket.h:45
static ssize_t recv(int sock, void *buf, size_t max_len, int flags)
Definition: socket.h:66
static int shutdown(int sock, int how)
Definition: socket.h:35
Definition: net_ip.h:229
Definition: net_ip.h:335