diff --git a/include/net/socket.h b/include/net/socket.h index 64d7059a05d..d570b4b87e9 100644 --- a/include/net/socket.h +++ b/include/net/socket.h @@ -7,6 +7,9 @@ #ifndef __NET_SOCKET_H #define __NET_SOCKET_H +#include +#include + #ifdef __cplusplus extern "C" { #endif @@ -14,6 +17,11 @@ extern "C" { int zsock_socket(int family, int type, int proto); int zsock_close(int sock); +#if defined(CONFIG_NET_SOCKETS_POSIX_NAMES) +#define socket zsock_socket +#define close zsock_close +#endif + #ifdef __cplusplus } #endif diff --git a/subsys/net/lib/sockets/Kconfig b/subsys/net/lib/sockets/Kconfig index 57054fae7e3..9579c5d7b41 100644 --- a/subsys/net/lib/sockets/Kconfig +++ b/subsys/net/lib/sockets/Kconfig @@ -14,6 +14,17 @@ menuconfig NET_SOCKETS if NET_SOCKETS +config NET_SOCKETS_POSIX_NAMES + bool "Standard POSIX names for Sockets API" + default n + help + By default, Sockets API function are prefixed with `zsock_` to avoid + namespacing issues. If this option is enabled, they will be provided + with standard POSIX names like socket(), recv(), and close(), to help + with porting existing code. Note that close() may require a special + attention, as in POSIX it closes any file descriptor, while with this + option enaled, it will still apply only to sockets. + config NET_DEBUG_SOCKETS bool "Debug BSD Sockets like API calls" default n