Skip to content

Commit fb7b940

Browse files
committed
posix: Add headers related to BSD Sockets API
A few of these headers are currently empty and provided to avoid compiler errors when building existing software. This set of headers is what is required to build https://github.com/open62541/open62541 with Zephyr. Signed-off-by: Paul Sokolovsky <[email protected]>
1 parent 4c21b0f commit fb7b940

File tree

7 files changed

+210
-0
lines changed

7 files changed

+210
-0
lines changed

include/posix/arpa/inet.h

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2019 Linaro Limited
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#ifndef ZEPHYR_INCLUDE_POSIX_ARPA_INET_H_
7+
#define ZEPHYR_INCLUDE_POSIX_ARPA_INET_H_
8+
9+
#ifdef __cplusplus
10+
extern "C" {
11+
#endif
12+
13+
#include <net/socket.h>
14+
15+
static inline char *inet_ntop(sa_family_t family, const void *src, char *dst,
16+
size_t size)
17+
{
18+
return zsock_inet_ntop(family, src, dst, size);
19+
}
20+
21+
static inline int inet_pton(sa_family_t family, const char *src, void *dst)
22+
{
23+
return zsock_inet_pton(family, src, dst);
24+
}
25+
26+
#ifdef __cplusplus
27+
}
28+
#endif
29+
30+
#endif /* ZEPHYR_INCLUDE_POSIX_ARPA_INET_H_ */

include/posix/net/if.h

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright (c) 2019 Linaro Limited
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#ifndef ZEPHYR_INCLUDE_POSIX_NET_IF_H_
7+
#define ZEPHYR_INCLUDE_POSIX_NET_IF_H_
8+
9+
#include <net/socket.h>
10+
11+
#endif /* ZEPHYR_INCLUDE_POSIX_NET_IF_H_ */

include/posix/netdb.h

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2019 Linaro Limited
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#ifndef ZEPHYR_INCLUDE_POSIX_NETDB_H_
7+
#define ZEPHYR_INCLUDE_POSIX_NETDB_H_
8+
9+
#ifdef __cplusplus
10+
extern "C" {
11+
#endif
12+
13+
#include <net/socket.h>
14+
15+
#define addrinfo zsock_addrinfo
16+
17+
static inline int getaddrinfo(const char *host, const char *service,
18+
const struct zsock_addrinfo *hints,
19+
struct zsock_addrinfo **res)
20+
{
21+
return zsock_getaddrinfo(host, service, hints, res);
22+
}
23+
24+
static inline void freeaddrinfo(struct zsock_addrinfo *ai)
25+
{
26+
zsock_freeaddrinfo(ai);
27+
}
28+
29+
static inline const char *gai_strerror(int errcode)
30+
{
31+
return zsock_gai_strerror(errcode);
32+
}
33+
34+
static inline int getnameinfo(const struct sockaddr *addr, socklen_t addrlen,
35+
char *host, socklen_t hostlen,
36+
char *serv, socklen_t servlen, int flags)
37+
{
38+
return zsock_getnameinfo(addr, addrlen, host, hostlen,
39+
serv, servlen, flags);
40+
}
41+
42+
#ifdef __cplusplus
43+
}
44+
#endif
45+
46+
#endif /* ZEPHYR_INCLUDE_POSIX_NETDB_H_ */

include/posix/netinet/in.h

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright (c) 2019 Linaro Limited
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#ifndef ZEPHYR_INCLUDE_POSIX_NETINET_IN_H_
7+
#define ZEPHYR_INCLUDE_POSIX_NETINET_IN_H_
8+
9+
#include <net/socket.h>
10+
11+
#endif /* ZEPHYR_INCLUDE_POSIX_NETINET_IN_H_ */

include/posix/netinet/tcp.h

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright (c) 2019 Linaro Limited
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#ifndef ZEPHYR_INCLUDE_POSIX_NETINET_TCP_H_
7+
#define ZEPHYR_INCLUDE_POSIX_NETINET_TCP_H_
8+
9+
#include <net/socket.h>
10+
11+
#endif /* ZEPHYR_INCLUDE_POSIX_NETINET_TCP_H_ */

include/posix/sys/ioctl.h

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright (c) 2019 Linaro Limited
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#ifndef ZEPHYR_INCLUDE_POSIX_SYS_IOCTL_H_
7+
#define ZEPHYR_INCLUDE_POSIX_SYS_IOCTL_H_
8+
9+
#define FIONBIO 0x5421
10+
11+
#endif /* ZEPHYR_INCLUDE_POSIX_SYS_IOCTL_H_ */

include/posix/sys/socket.h

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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+
#ifdef __cplusplus
10+
extern "C" {
11+
#endif
12+
13+
#include <sys/types.h>
14+
#include <net/socket.h>
15+
16+
static inline int socket(int family, int type, int proto)
17+
{
18+
return zsock_socket(family, type, proto);
19+
}
20+
21+
#define SHUT_RD ZSOCK_SHUT_RD
22+
#define SHUT_WR ZSOCK_SHUT_WR
23+
#define SHUT_RDWR ZSOCK_SHUT_RDWR
24+
25+
static inline int shutdown(int sock, int how)
26+
{
27+
return zsock_shutdown(sock, how);
28+
}
29+
30+
static inline int bind(int sock, const struct sockaddr *addr, socklen_t addrlen)
31+
{
32+
return zsock_bind(sock, addr, addrlen);
33+
}
34+
35+
static inline int connect(int sock, const struct sockaddr *addr,
36+
socklen_t addrlen)
37+
{
38+
return zsock_connect(sock, addr, addrlen);
39+
}
40+
41+
static inline int listen(int sock, int backlog)
42+
{
43+
return zsock_listen(sock, backlog);
44+
}
45+
46+
static inline int accept(int sock, struct sockaddr *addr, socklen_t *addrlen)
47+
{
48+
return zsock_accept(sock, addr, addrlen);
49+
}
50+
51+
static inline ssize_t send(int sock, const void *buf, size_t len, int flags)
52+
{
53+
return zsock_send(sock, buf, len, flags);
54+
}
55+
56+
static inline ssize_t recv(int sock, void *buf, size_t max_len, int flags)
57+
{
58+
return zsock_recv(sock, buf, max_len, flags);
59+
}
60+
61+
static inline ssize_t sendto(int sock, const void *buf, size_t len, int flags,
62+
const struct sockaddr *dest_addr,
63+
socklen_t addrlen)
64+
{
65+
return zsock_sendto(sock, buf, len, flags, dest_addr, addrlen);
66+
}
67+
68+
static inline ssize_t recvfrom(int sock, void *buf, size_t max_len, int flags,
69+
struct sockaddr *src_addr, socklen_t *addrlen)
70+
{
71+
return zsock_recvfrom(sock, buf, max_len, flags, src_addr, addrlen);
72+
}
73+
74+
static inline int getsockopt(int sock, int level, int optname,
75+
void *optval, socklen_t *optlen)
76+
{
77+
return zsock_getsockopt(sock, level, optname, optval, optlen);
78+
}
79+
80+
static inline int setsockopt(int sock, int level, int optname,
81+
const void *optval, socklen_t optlen)
82+
{
83+
return zsock_setsockopt(sock, level, optname, optval, optlen);
84+
}
85+
86+
#ifdef __cplusplus
87+
}
88+
#endif
89+
90+
#endif /* ZEPHYR_INCLUDE_POSIX_SYS_SOCKET_H_ */

0 commit comments

Comments
 (0)