From c1c3691bed231380b3b632a038f7f3cb8d7f5929 Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Wed, 4 Aug 2021 21:20:43 -0500 Subject: [PATCH] ws2_32: Move gethostname() to the Unix library. Signed-off-by: Zebediah Figura Signed-off-by: Alexandre Julliard --- dlls/ws2_32/protocol.c | 16 +++++++++------- dlls/ws2_32/unixlib.c | 10 ++++++++++ dlls/ws2_32/ws2_32_private.h | 1 + 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/dlls/ws2_32/protocol.c b/dlls/ws2_32/protocol.c index c65e6b9674e..48e7e062d7f 100644 --- a/dlls/ws2_32/protocol.c +++ b/dlls/ws2_32/protocol.c @@ -913,6 +913,7 @@ struct WS_hostent * WINAPI WS_gethostbyname( const char *name ) { struct WS_hostent *host = NULL; char hostname[100]; + int ret; TRACE( "%s\n", debugstr_a(name) ); @@ -922,9 +923,9 @@ struct WS_hostent * WINAPI WS_gethostbyname( const char *name ) return NULL; } - if (gethostname( hostname, 100 ) == -1) + if ((ret = unix_funcs->gethostname( hostname, 100 ))) { - SetLastError( WSAENOBUFS ); + SetLastError( ret ); return NULL; } @@ -973,7 +974,7 @@ struct WS_hostent * WINAPI WS_gethostbyname( const char *name ) int WINAPI WS_gethostname( char *name, int namelen ) { char buf[256]; - int len; + int len, ret; TRACE( "name %p, len %d\n", name, namelen ); @@ -983,9 +984,9 @@ int WINAPI WS_gethostname( char *name, int namelen ) return -1; } - if (gethostname( buf, sizeof(buf) ) != 0) + if ((ret = unix_funcs->gethostname( buf, sizeof(buf) ))) { - SetLastError( sock_get_error( errno ) ); + SetLastError( ret ); return -1; } @@ -1009,6 +1010,7 @@ int WINAPI WS_gethostname( char *name, int namelen ) int WINAPI GetHostNameW( WCHAR *name, int namelen ) { char buf[256]; + int ret; TRACE( "name %p, len %d\n", name, namelen ); @@ -1018,9 +1020,9 @@ int WINAPI GetHostNameW( WCHAR *name, int namelen ) return -1; } - if (gethostname( buf, sizeof(buf) )) + if ((ret = unix_funcs->gethostname( buf, sizeof(buf) ))) { - SetLastError( sock_get_error( errno ) ); + SetLastError( ret ); return -1; } diff --git a/dlls/ws2_32/unixlib.c b/dlls/ws2_32/unixlib.c index 2a5fcd1b60d..cde73198c16 100644 --- a/dlls/ws2_32/unixlib.c +++ b/dlls/ws2_32/unixlib.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #ifdef HAVE_SYS_SOCKET_H # include @@ -789,11 +790,20 @@ static int CDECL unix_gethostbyname( const char *name, struct WS_hostent *const #endif +static int CDECL unix_gethostname( char *name, int len ) +{ + if (!gethostname( name, len )) + return 0; + return errno_from_unix( errno ); +} + + static const struct unix_funcs funcs = { unix_getaddrinfo, unix_gethostbyaddr, unix_gethostbyname, + unix_gethostname, }; NTSTATUS CDECL __wine_init_unix_lib( HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out ) diff --git a/dlls/ws2_32/ws2_32_private.h b/dlls/ws2_32/ws2_32_private.h index 38454e1a9ba..973f24a10a9 100644 --- a/dlls/ws2_32/ws2_32_private.h +++ b/dlls/ws2_32/ws2_32_private.h @@ -203,6 +203,7 @@ struct unix_funcs int (CDECL *gethostbyaddr)( const void *addr, int len, int family, struct WS(hostent) *host, unsigned int *size ); int (CDECL *gethostbyname)( const char *name, struct WS(hostent) *host, unsigned int *size ); + int (CDECL *gethostname)( char *name, int len ); }; extern const struct unix_funcs *unix_funcs;