Skip to content
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

posix: add networking apis #70635

Merged
merged 13 commits into from Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/services/portability/posix/aep/index.rst
Expand Up @@ -139,7 +139,7 @@ Dedicated Realtime System Profile (PSE53)
POSIX_FILE_LOCKING,,
POSIX_FILE_SYSTEM,,
POSIX_MULTI_PROCESS,, :ref:`†<posix_undefined_behaviour>`
POSIX_NETWORKING, yes, :ref:`†<posix_undefined_behaviour>`
POSIX_NETWORKING, yes, :ref:`POSIX_NETWORKING <posix_option_group_networking>`
POSIX_PIPE,, :ref:`†<posix_undefined_behaviour>`
POSIX_SIGNALS,, :ref:`†<posix_undefined_behaviour>`
POSIX_SIGNAL_JUMP,, :ref:`†<posix_undefined_behaviour>`
Expand Down
64 changes: 64 additions & 0 deletions doc/services/portability/posix/option_groups/index.rst
Expand Up @@ -289,6 +289,70 @@ POSIX_CLOCK_SELECTION
pthread_condattr_setclock(),yes
clock_nanosleep(),yes

.. _posix_option_group_networking:

POSIX_NETWORKING
================

.. csv-table:: POSIX_NETWORKING
:header: API, Supported
:widths: 50,10

accept(),yes
bind(),yes
connect(),yes
endhostent(),yes
endnetent(),yes
endprotoent(),yes
endservent(),yes
freeaddrinfo(),yes
gai_strerror(),yes
getaddrinfo(),yes
gethostent(),yes
gethostname(),yes
getnameinfo(),yes
getnetbyaddr(),yes
getnetbyname(),yes
getnetent(),yes
getpeername(),yes
getprotobyname(),yes
getprotobynumber(),yes
getprotoent(),yes
getservbyname(),yes
getservbyport(),yes
getservent(),yes
getsockname(),yes
getsockopt(),yes
htonl(),yes
htons(),yes
if_freenameindex(),yes
if_indextoname(),yes
if_nameindex(),yes
if_nametoindex(),yes
inet_addr(),yes
inet_ntoa(),yes
inet_ntop(),yes
inet_pton(),yes
listen(),yes
ntohl(),yes
ntohs(),yes
recv(),yes
recvfrom(),yes
recvmsg(),yes
send(),yes
sendmsg(),yes
sendto(),yes
sethostent(),yes
setnetent(),yes
setprotoent(),yes
setservent(),yes
setsockopt(),yes
shutdown(),yes
socket(),yes
sockatmark(),yes (will fail with ``ENOSYS``:ref:`†<posix_undefined_behaviour>`)
socketpair(),yes


.. _posix_option_group_semaphores:

POSIX_SEMAPHORES
Expand Down
3 changes: 3 additions & 0 deletions include/zephyr/posix/arpa/inet.h
Expand Up @@ -32,6 +32,9 @@ static inline int inet_pton(sa_family_t family, const char *src, void *dst)

#endif /* CONFIG_NET_SOCKETS_POSIX_NAMES */

in_addr_t inet_addr(const char *cp);
char *inet_ntoa(struct in_addr in);

#ifdef __cplusplus
}
#endif
Expand Down
16 changes: 15 additions & 1 deletion include/zephyr/posix/net/if.h
Expand Up @@ -6,12 +6,26 @@
#ifndef ZEPHYR_INCLUDE_POSIX_NET_IF_H_
#define ZEPHYR_INCLUDE_POSIX_NET_IF_H_

#include <zephyr/net/socket.h>
#ifdef CONFIG_NET_INTERFACE_NAME_LEN
#define IF_NAMESIZE CONFIG_NET_INTERFACE_NAME_LEN
#else
#define IF_NAMESIZE 1
#endif

#ifdef __cplusplus
extern "C" {
#endif

struct if_nameindex {
unsigned int if_index;
char *if_name;
};

char *if_indextoname(unsigned int ifindex, char *ifname);
void if_freenameindex(struct if_nameindex *ptr);
struct if_nameindex *if_nameindex(void);
unsigned int if_nametoindex(const char *ifname);

#ifdef __cplusplus
}
#endif
Expand Down
47 changes: 47 additions & 0 deletions include/zephyr/posix/netdb.h
Expand Up @@ -29,6 +29,34 @@
extern "C" {
#endif

struct hostent {
char *h_name;
char **h_aliases;
int h_addrtype;
int h_length;
char **h_addr_list;
};

struct netent {
char *n_name;
char **n_aliases;
int n_addrtype;
uint32_t n_net;
};

struct protoent {
char *p_name;
char **p_aliases;
int p_proto;
};

struct servent {
char *s_name;
char **s_aliases;
int s_port;
char *s_proto;
};

#ifndef CONFIG_NET_SOCKETS_POSIX_NAMES

#define addrinfo zsock_addrinfo
Expand Down Expand Up @@ -60,6 +88,25 @@ static inline int getnameinfo(const struct sockaddr *addr, socklen_t addrlen,

#endif /* CONFIG_NET_SOCKETS_POSIX_NAMES */

void endhostent(void);
void endnetent(void);
void endprotoent(void);
void endservent(void);
struct hostent *gethostent(void);
struct netent *getnetbyaddr(uint32_t net, int type);
struct netent *getnetbyname(const char *name);
struct netent *getnetent(void);
struct protoent *getprotobyname(const char *name);
struct protoent *getprotobynumber(int proto);
struct protoent *getprotoent(void);
struct servent *getservbyname(const char *name, const char *proto);
struct servent *getservbyport(int port, const char *proto);
struct servent *getservent(void);
void sethostent(int stayopen);
void setnetent(int stayopen);
void setprotoent(int stayopen);
void setservent(int stayopen);

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions include/zephyr/posix/sys/socket.h
Expand Up @@ -125,6 +125,8 @@ static inline int getsockname(int sock, struct sockaddr *addr,

#endif /* CONFIG_NET_SOCKETS_POSIX_NAMES */

int sockatmark(int s);

#ifdef __cplusplus
}
#endif
Expand Down
1 change: 1 addition & 0 deletions lib/posix/options/CMakeLists.txt
Expand Up @@ -44,6 +44,7 @@ zephyr_library_sources_ifdef(CONFIG_POSIX_CONFSTR confstr.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_ENV env.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_FS fs.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_MQUEUE mqueue.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_NETWORKING net.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_PUTMSG stropts.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_SIGNAL signal.c ${STRSIGNAL_TABLE_H})
zephyr_library_sources_ifdef(CONFIG_POSIX_SYSCONF_IMPL_FULL sysconf.c)
Expand Down
1 change: 1 addition & 0 deletions lib/posix/options/Kconfig
Expand Up @@ -37,6 +37,7 @@ rsource "Kconfig.getopt"
rsource "Kconfig.key"
rsource "Kconfig.mqueue"
rsource "Kconfig.mutex"
rsource "Kconfig.net"
rsource "Kconfig.pthread"
rsource "Kconfig.rwlock"
rsource "Kconfig.sched"
Expand Down
11 changes: 11 additions & 0 deletions lib/posix/options/Kconfig.net
@@ -0,0 +1,11 @@
# Copyright (c) 2024, Friedt Professional Engineering Services, Inc
#
# SPDX-License-Identifier: Apache-2.0

config POSIX_NETWORKING
bool "POSIX Networking API"
default y if POSIX_API
depends on NETWORKING
help
Enable this option to support the POSIX networking API. This includes
support for BSD Sockets.