Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/ws2_32/protocol.c | 87 ++++++++++++++++++++++++++++++++++++ dlls/ws2_32/socket.c | 83 +--------------------------------- dlls/ws2_32/ws2_32_private.h | 8 ++++ 3 files changed, 97 insertions(+), 81 deletions(-)
diff --git a/dlls/ws2_32/protocol.c b/dlls/ws2_32/protocol.c index 5bbcdee3e0c..ecd564788d7 100644 --- a/dlls/ws2_32/protocol.c +++ b/dlls/ws2_32/protocol.c @@ -854,6 +854,93 @@ void WINAPI FreeAddrInfoExW( ADDRINFOEXW *ai ) }
+static const int ws_niflag_map[][2] = +{ + MAP_OPTION( NI_NOFQDN ), + MAP_OPTION( NI_NUMERICHOST ), + MAP_OPTION( NI_NAMEREQD ), + MAP_OPTION( NI_NUMERICSERV ), + MAP_OPTION( NI_DGRAM ), +}; + +static int convert_niflag_w2u( int winflags ) +{ + unsigned int i; + int unixflags = 0; + + for (i = 0; i < ARRAY_SIZE(ws_niflag_map); i++) + { + if (ws_niflag_map[i][0] & winflags) + { + unixflags |= ws_niflag_map[i][1]; + winflags &= ~ws_niflag_map[i][0]; + } + } + if (winflags) + FIXME("Unhandled windows NI_xxx flags 0x%x\n", winflags); + return unixflags; +} + + +/*********************************************************************** + * getnameinfo (ws2_32.@) + */ +int WINAPI WS_getnameinfo( const SOCKADDR *addr, WS_socklen_t addr_len, char *host, + DWORD host_len, char *serv, DWORD serv_len, int flags ) +{ +#ifdef HAVE_GETNAMEINFO + int ret; + union generic_unix_sockaddr uaddr; + unsigned int uaddr_len; + + TRACE( "addr %s, addr_len %d, host %p, host_len %u, serv %p, serv_len %d, flags %#x\n", + debugstr_sockaddr(addr), addr_len, host, host_len, serv, serv_len, flags ); + + uaddr_len = ws_sockaddr_ws2u( addr, addr_len, &uaddr ); + if (!uaddr_len) + { + SetLastError( WSAEFAULT ); + return WSA_NOT_ENOUGH_MEMORY; + } + ret = getnameinfo( &uaddr.addr, uaddr_len, host, host_len, serv, serv_len, convert_niflag_w2u(flags) ); + return convert_eai_u2w( ret ); +#else + FIXME( "getnameinfo() failed, not found during buildtime.\n" ); + return EAI_FAIL; +#endif +} + + +/*********************************************************************** + * GetNameInfoW (ws2_32.@) + */ +int WINAPI GetNameInfoW( const SOCKADDR *addr, WS_socklen_t addr_len, WCHAR *host, + DWORD host_len, WCHAR *serv, DWORD serv_len, int flags ) +{ + int ret; + char *hostA = NULL, *servA = NULL; + + if (host && (!(hostA = HeapAlloc( GetProcessHeap(), 0, host_len )))) + return EAI_MEMORY; + if (serv && (!(servA = HeapAlloc( GetProcessHeap(), 0, serv_len )))) + { + HeapFree( GetProcessHeap(), 0, hostA ); + return EAI_MEMORY; + } + + ret = WS_getnameinfo( addr, addr_len, hostA, host_len, servA, serv_len, flags ); + if (!ret) + { + if (host) MultiByteToWideChar( CP_ACP, 0, hostA, -1, host, host_len ); + if (serv) MultiByteToWideChar( CP_ACP, 0, servA, -1, serv, serv_len ); + } + + HeapFree( GetProcessHeap(), 0, hostA ); + HeapFree( GetProcessHeap(), 0, servA ); + return ret; +} + + static UINT host_errno_from_unix( int err ) { WARN( "%d\n", err ); diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index 7313741e4b1..5ced4720558 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -235,12 +235,6 @@ static unsigned int if_addr_cache_size; static SOCKET *socket_list; static unsigned int socket_list_size;
-union generic_unix_sockaddr -{ - struct sockaddr addr; - char data[128]; /* should be big enough for all families */ -}; - const char *debugstr_sockaddr( const struct WS_sockaddr *a ) { if (!a) return "(nil)"; @@ -717,15 +711,6 @@ static const int ws_socktype_map[][2] = {FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO}, };
-static const int ws_niflag_map[][2] = -{ - MAP_OPTION( NI_NOFQDN ), - MAP_OPTION( NI_NUMERICHOST ), - MAP_OPTION( NI_NAMEREQD ), - MAP_OPTION( NI_NUMERICSERV ), - MAP_OPTION( NI_DGRAM ), -}; - static const int ws_poll_map[][2] = { MAP_OPTION( POLLERR ), @@ -1633,8 +1618,8 @@ static inline BOOL supported_pf(int pf) /* Returns the length of the converted address if successful, 0 if it was too * small to start with or unknown family or invalid address buffer. */ -static unsigned int ws_sockaddr_ws2u(const struct WS_sockaddr* wsaddr, int wsaddrlen, - union generic_unix_sockaddr *uaddr) +unsigned int ws_sockaddr_ws2u( const struct WS_sockaddr *wsaddr, int wsaddrlen, + union generic_unix_sockaddr *uaddr ) { unsigned int uaddrlen = 0;
@@ -5860,70 +5845,6 @@ struct WS_servent* WINAPI WS_getservbyname(const char *name, const char *proto) return retval; }
-static int convert_niflag_w2u(int winflags) { - unsigned int i; - int unixflags = 0; - - for (i = 0; i < ARRAY_SIZE(ws_niflag_map); i++) - if (ws_niflag_map[i][0] & winflags) { - unixflags |= ws_niflag_map[i][1]; - winflags &= ~ws_niflag_map[i][0]; - } - if (winflags) - FIXME("Unhandled windows NI_xxx flags 0x%x\n", winflags); - return unixflags; -} - -int WINAPI WS_getnameinfo(const SOCKADDR *sa, WS_socklen_t salen, PCHAR host, - DWORD hostlen, PCHAR serv, DWORD servlen, INT flags) -{ -#ifdef HAVE_GETNAMEINFO - int ret; - union generic_unix_sockaddr sa_u; - unsigned int size; - - TRACE("%s %d %p %d %p %d %d\n", debugstr_sockaddr(sa), salen, host, hostlen, - serv, servlen, flags); - - size = ws_sockaddr_ws2u(sa, salen, &sa_u); - if (!size) - { - SetLastError(WSAEFAULT); - return WSA_NOT_ENOUGH_MEMORY; - } - ret = getnameinfo(&sa_u.addr, size, host, hostlen, serv, servlen, convert_niflag_w2u(flags)); - return convert_eai_u2w(ret); -#else - FIXME("getnameinfo() failed, not found during buildtime.\n"); - return EAI_FAIL; -#endif -} - -int WINAPI GetNameInfoW(const SOCKADDR *sa, WS_socklen_t salen, PWCHAR host, - DWORD hostlen, PWCHAR serv, DWORD servlen, INT flags) -{ - int ret; - char *hostA = NULL, *servA = NULL; - - if (host && (!(hostA = HeapAlloc(GetProcessHeap(), 0, hostlen)))) return EAI_MEMORY; - if (serv && (!(servA = HeapAlloc(GetProcessHeap(), 0, servlen)))) - { - HeapFree(GetProcessHeap(), 0, hostA); - return EAI_MEMORY; - } - - ret = WS_getnameinfo(sa, salen, hostA, hostlen, servA, servlen, flags); - if (!ret) - { - if (host) MultiByteToWideChar(CP_ACP, 0, hostA, -1, host, hostlen); - if (serv) MultiByteToWideChar(CP_ACP, 0, servA, -1, serv, servlen); - } - - HeapFree(GetProcessHeap(), 0, hostA); - HeapFree(GetProcessHeap(), 0, servA); - return ret; -} - /*********************************************************************** * getservbyport (WS2_32.56) */ diff --git a/dlls/ws2_32/ws2_32_private.h b/dlls/ws2_32/ws2_32_private.h index 121ce25ad1d..e86a3569510 100644 --- a/dlls/ws2_32/ws2_32_private.h +++ b/dlls/ws2_32/ws2_32_private.h @@ -161,11 +161,19 @@
static const char magic_loopback_addr[] = {127, 12, 34, 56};
+union generic_unix_sockaddr +{ + struct sockaddr addr; + char data[128]; /* should be big enough for all families */ +}; + int convert_eai_u2w( int ret ) DECLSPEC_HIDDEN; int convert_socktype_u2w( int type ) DECLSPEC_HIDDEN; int convert_socktype_w2u( int type ) DECLSPEC_HIDDEN; int ws_sockaddr_u2ws( const struct sockaddr *unix_addr, struct WS_sockaddr *win_addr, int *win_addr_len ) DECLSPEC_HIDDEN; +unsigned int ws_sockaddr_ws2u( const struct WS_sockaddr *win_addr, int win_addr_len, + union generic_unix_sockaddr *unix_addr ) DECLSPEC_HIDDEN;
const char *debugstr_sockaddr( const struct WS_sockaddr *addr ) DECLSPEC_HIDDEN;