-
Notifications
You must be signed in to change notification settings - Fork 8k
posix: Add headers related to BSD Sockets API #16621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2019 Linaro Limited | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#ifndef ZEPHYR_INCLUDE_POSIX_ARPA_INET_H_ | ||
#define ZEPHYR_INCLUDE_POSIX_ARPA_INET_H_ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <net/socket.h> | ||
|
||
static inline char *inet_ntop(sa_family_t family, const void *src, char *dst, | ||
size_t size) | ||
{ | ||
return zsock_inet_ntop(family, src, dst, size); | ||
} | ||
|
||
static inline int inet_pton(sa_family_t family, const char *src, void *dst) | ||
{ | ||
return zsock_inet_pton(family, src, dst); | ||
} | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* ZEPHYR_INCLUDE_POSIX_ARPA_INET_H_ */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright (c) 2019 Linaro Limited | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#ifndef ZEPHYR_INCLUDE_POSIX_NET_IF_H_ | ||
|
||
#define ZEPHYR_INCLUDE_POSIX_NET_IF_H_ | ||
|
||
#include <net/socket.h> | ||
|
||
#endif /* ZEPHYR_INCLUDE_POSIX_NET_IF_H_ */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (c) 2019 Linaro Limited | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#ifndef ZEPHYR_INCLUDE_POSIX_NETDB_H_ | ||
#define ZEPHYR_INCLUDE_POSIX_NETDB_H_ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <net/socket.h> | ||
|
||
#define addrinfo zsock_addrinfo | ||
|
||
static inline int getaddrinfo(const char *host, const char *service, | ||
const struct zsock_addrinfo *hints, | ||
struct zsock_addrinfo **res) | ||
{ | ||
return zsock_getaddrinfo(host, service, hints, res); | ||
} | ||
|
||
static inline void freeaddrinfo(struct zsock_addrinfo *ai) | ||
{ | ||
zsock_freeaddrinfo(ai); | ||
} | ||
|
||
static inline const char *gai_strerror(int errcode) | ||
{ | ||
return zsock_gai_strerror(errcode); | ||
} | ||
|
||
static inline int getnameinfo(const struct sockaddr *addr, socklen_t addrlen, | ||
char *host, socklen_t hostlen, | ||
char *serv, socklen_t servlen, int flags) | ||
{ | ||
return zsock_getnameinfo(addr, addrlen, host, hostlen, | ||
serv, servlen, flags); | ||
} | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* ZEPHYR_INCLUDE_POSIX_NETDB_H_ */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright (c) 2019 Linaro Limited | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#ifndef ZEPHYR_INCLUDE_POSIX_NETINET_IN_H_ | ||
#define ZEPHYR_INCLUDE_POSIX_NETINET_IN_H_ | ||
|
||
#include <net/socket.h> | ||
|
||
#endif /* ZEPHYR_INCLUDE_POSIX_NETINET_IN_H_ */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright (c) 2019 Linaro Limited | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#ifndef ZEPHYR_INCLUDE_POSIX_NETINET_TCP_H_ | ||
#define ZEPHYR_INCLUDE_POSIX_NETINET_TCP_H_ | ||
|
||
#include <net/socket.h> | ||
|
||
#endif /* ZEPHYR_INCLUDE_POSIX_NETINET_TCP_H_ */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright (c) 2019 Linaro Limited | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#ifndef ZEPHYR_INCLUDE_POSIX_SYS_IOCTL_H_ | ||
#define ZEPHYR_INCLUDE_POSIX_SYS_IOCTL_H_ | ||
|
||
#define FIONBIO 0x5421 | ||
|
||
#endif /* ZEPHYR_INCLUDE_POSIX_SYS_IOCTL_H_ */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright (c) 2019 Linaro Limited | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#ifndef ZEPHYR_INCLUDE_POSIX_SYS_SOCKET_H_ | ||
#define ZEPHYR_INCLUDE_POSIX_SYS_SOCKET_H_ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <sys/types.h> | ||
#include <net/socket.h> | ||
|
||
static inline int socket(int family, int type, int proto) | ||
{ | ||
return zsock_socket(family, type, proto); | ||
} | ||
|
||
#define SHUT_RD ZSOCK_SHUT_RD | ||
#define SHUT_WR ZSOCK_SHUT_WR | ||
#define SHUT_RDWR ZSOCK_SHUT_RDWR | ||
|
||
static inline int shutdown(int sock, int how) | ||
{ | ||
return zsock_shutdown(sock, how); | ||
} | ||
|
||
static inline int bind(int sock, const struct sockaddr *addr, socklen_t addrlen) | ||
{ | ||
return zsock_bind(sock, addr, addrlen); | ||
} | ||
|
||
static inline int connect(int sock, const struct sockaddr *addr, | ||
socklen_t addrlen) | ||
{ | ||
return zsock_connect(sock, addr, addrlen); | ||
} | ||
|
||
static inline int listen(int sock, int backlog) | ||
{ | ||
return zsock_listen(sock, backlog); | ||
} | ||
|
||
static inline int accept(int sock, struct sockaddr *addr, socklen_t *addrlen) | ||
{ | ||
return zsock_accept(sock, addr, addrlen); | ||
} | ||
|
||
static inline ssize_t send(int sock, const void *buf, size_t len, int flags) | ||
{ | ||
return zsock_send(sock, buf, len, flags); | ||
} | ||
|
||
static inline ssize_t recv(int sock, void *buf, size_t max_len, int flags) | ||
{ | ||
return zsock_recv(sock, buf, max_len, flags); | ||
} | ||
|
||
static inline ssize_t sendto(int sock, const void *buf, size_t len, int flags, | ||
const struct sockaddr *dest_addr, | ||
socklen_t addrlen) | ||
{ | ||
return zsock_sendto(sock, buf, len, flags, dest_addr, addrlen); | ||
} | ||
|
||
static inline ssize_t recvfrom(int sock, void *buf, size_t max_len, int flags, | ||
struct sockaddr *src_addr, socklen_t *addrlen) | ||
{ | ||
return zsock_recvfrom(sock, buf, max_len, flags, src_addr, addrlen); | ||
} | ||
|
||
static inline int getsockopt(int sock, int level, int optname, | ||
void *optval, socklen_t *optlen) | ||
{ | ||
return zsock_getsockopt(sock, level, optname, optval, optlen); | ||
} | ||
|
||
static inline int setsockopt(int sock, int level, int optname, | ||
const void *optval, socklen_t optlen) | ||
{ | ||
return zsock_setsockopt(sock, level, optname, optval, optlen); | ||
} | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* ZEPHYR_INCLUDE_POSIX_SYS_SOCKET_H_ */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure about this? These two functions don't seem to belong in this file: http://pubs.opengroup.org/onlinepubs/007908799/xns/arpainet.h.html
What SUS version are you targeting here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Targeting latest publicly available POSIX version: http://pubs.opengroup.org/onlinepubs/9699919799/
http://pubs.opengroup.org/onlinepubs/9699919799/functions/inet_ntop.html
Quick check: "man inet_ntop"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't been following the posix compatibility work carefully, but this PR makes me wonder if it's just piecemeal efforts to support individual applications, or a disciplined approach that's enabling functionality in a staged way.
I'm not asking for the entire POSIX API to be implemented in one go. That's a ridiculous strawman.
I am asking what the structure of the approach is, given that this PR seems to have problems in that regard.