diff --git a/include/zephyr/posix/unistd.h b/include/zephyr/posix/unistd.h index 233b17a7b7c..10d44bfd4a8 100644 --- a/include/zephyr/posix/unistd.h +++ b/include/zephyr/posix/unistd.h @@ -11,6 +11,11 @@ #ifdef CONFIG_POSIX_API #include #endif +#ifdef CONFIG_NETWORKING +/* For zsock_gethostname() */ +#include +#include +#endif #include #include #include @@ -44,7 +49,10 @@ int rmdir(const char *path); FUNC_NORETURN void _exit(int status); #ifdef CONFIG_NETWORKING -int gethostname(char *buf, size_t len); +static inline int gethostname(char *buf, size_t len) +{ + return zsock_gethostname(buf, len); +} #endif /* CONFIG_NETWORKING */ #endif /* CONFIG_POSIX_API */ diff --git a/lib/posix/options/net.c b/lib/posix/options/net.c index 828bfb93f38..883bb9145ac 100644 --- a/lib/posix/options/net.c +++ b/lib/posix/options/net.c @@ -10,7 +10,6 @@ #include #include -#include #include #include #include @@ -217,11 +216,6 @@ struct hostent *gethostent(void) return NULL; } -int gethostname(char *buf, size_t len) -{ - return zsock_gethostname(buf, len); -} - int getnameinfo(const struct sockaddr *addr, socklen_t addrlen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, int flags) {