Skip to content

Commit 2fd1490

Browse files
jukkarnashif
authored andcommitted
lib: posix: net: Add support for namespaced network symbols
Use namespaced network symbols in order to avoid circular dependency between Posix and network subsystems. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 6c18fd3 commit 2fd1490

File tree

5 files changed

+33
-12
lines changed

5 files changed

+33
-12
lines changed

include/zephyr/posix/arpa/inet.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ char *inet_ntoa(struct in_addr in);
2424
char *inet_ntop(sa_family_t family, const void *src, char *dst, size_t size);
2525
int inet_pton(sa_family_t family, const char *src, void *dst);
2626

27+
#define ntohs(x) net_ntohs(x)
28+
#define ntohl(x) net_ntohl(x)
29+
#define ntohll(x) net_ntohll(x)
30+
#define htons(x) net_htons(x)
31+
#define htonl(x) net_htonl(x)
32+
#define htonll(x) net_htonll(x)
33+
2734
#ifdef __cplusplus
2835
}
2936
#endif

include/zephyr/posix/net/if.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
#define IF_NAMESIZE 1
1313
#endif
1414

15+
#if !defined(IFNAMSIZ)
16+
#define IFNAMSIZ IF_NAMESIZE
17+
#endif
18+
1519
#ifdef __cplusplus
1620
extern "C" {
1721
#endif

include/zephyr/posix/netdb.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ void endhostent(void);
6363
void endnetent(void);
6464
void endprotoent(void);
6565
void endservent(void);
66-
void freeaddrinfo(struct zsock_addrinfo *ai);
66+
void freeaddrinfo(struct addrinfo *ai);
6767
const char *gai_strerror(int errcode);
68-
int getaddrinfo(const char *host, const char *service, const struct zsock_addrinfo *hints,
69-
struct zsock_addrinfo **res);
68+
int getaddrinfo(const char *host, const char *service, const struct addrinfo *hints,
69+
struct addrinfo **res);
7070
struct hostent *gethostent(void);
7171
int getnameinfo(const struct sockaddr *addr, socklen_t addrlen, char *host, socklen_t hostlen,
7272
char *serv, socklen_t servlen, int flags);

include/zephyr/posix/netinet/in.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ extern "C" {
1717
typedef uint16_t in_port_t;
1818
typedef uint32_t in_addr_t;
1919

20+
#define in_addr net_in_addr
21+
#define in6_addr net_in6_addr
22+
23+
#define INET_ADDRSTRLEN NET_INET_ADDRSTRLEN
24+
#define INET6_ADDRSTRLEN NET_INET6_ADDRSTRLEN
25+
2026
#ifdef __cplusplus
2127
}
2228
#endif

include/zephyr/posix/sys/socket.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,11 @@
77
#define ZEPHYR_INCLUDE_POSIX_SYS_SOCKET_H_
88

99
#include <sys/types.h>
10-
#include <zephyr/net/socket.h>
11-
12-
#define SHUT_RD ZSOCK_SHUT_RD
13-
#define SHUT_WR ZSOCK_SHUT_WR
14-
#define SHUT_RDWR ZSOCK_SHUT_RDWR
1510

16-
#define MSG_PEEK ZSOCK_MSG_PEEK
17-
#define MSG_TRUNC ZSOCK_MSG_TRUNC
18-
#define MSG_DONTWAIT ZSOCK_MSG_DONTWAIT
19-
#define MSG_WAITALL ZSOCK_MSG_WAITALL
11+
#undef ZEPHYR_INCLUDE_NET_COMPAT_MODE_SYMBOLS
12+
#define ZEPHYR_INCLUDE_NET_COMPAT_MODE_SYMBOLS
13+
#include <zephyr/net/socket.h>
14+
#undef ZEPHYR_INCLUDE_NET_COMPAT_MODE_SYMBOLS
2015

2116
#ifdef __cplusplus
2217
extern "C" {
@@ -31,6 +26,15 @@ struct linger {
3126
typedef uint32_t socklen_t;
3227
struct msghdr;
3328
struct sockaddr;
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+
35+
#define SHUT_RD ZSOCK_SHUT_RD
36+
#define SHUT_WR ZSOCK_SHUT_WR
37+
#define SHUT_RDWR ZSOCK_SHUT_RDWR
3438
#endif
3539

3640
int accept(int sock, struct sockaddr *addr, socklen_t *addrlen);

0 commit comments

Comments
 (0)