From 1fd39b3a08d345185ebfe892ff174332c6b30e7a Mon Sep 17 00:00:00 2001 From: Thomas Faber Date: Sun, 22 Jun 2014 18:51:11 +0000 Subject: [PATCH] [WS2_32] - Correctly handle port 0 in getaddrinfo - Stub numeric port case of getnameinfo svn path=/trunk/; revision=63632 --- reactos/dll/win32/ws2_32/misc/ns.c | 5 +++-- reactos/dll/win32/ws2_32/misc/stubs.c | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/reactos/dll/win32/ws2_32/misc/ns.c b/reactos/dll/win32/ws2_32/misc/ns.c index 9c37bbcf9ff..1ac0bc83811 100644 --- a/reactos/dll/win32/ws2_32/misc/ns.c +++ b/reactos/dll/win32/ws2_32/misc/ns.c @@ -1596,6 +1596,7 @@ getaddrinfo(const char FAR * nodename, struct addrinfo *ret = NULL, *ai; ULONG addr; USHORT port; + PCHAR pc; struct servent *se; char *proto; LPPROTOENT pent; @@ -1624,9 +1625,9 @@ getaddrinfo(const char FAR * nodename, if (servname) { /* converting port number */ - port = strtoul(servname, NULL, 10); + port = strtoul(servname, &pc, 10); /* service name was specified? */ - if (port == 0) + if (*pc != ANSI_NULL) { /* protocol was specified? */ if (hints && hints->ai_protocol) diff --git a/reactos/dll/win32/ws2_32/misc/stubs.c b/reactos/dll/win32/ws2_32/misc/stubs.c index de16a1c2125..edcfe005095 100644 --- a/reactos/dll/win32/ws2_32/misc/stubs.c +++ b/reactos/dll/win32/ws2_32/misc/stubs.c @@ -11,6 +11,7 @@ #include "ws2_32.h" #include +#include /* * @implemented @@ -895,6 +896,16 @@ getnameinfo(const struct sockaddr FAR * sa, DWORD servlen, INT flags) { + if (!host && serv && flags & NI_NUMERICSERV) + { + const struct sockaddr_in *sa_in = (const struct sockaddr_in *)sa; + if (salen >= sizeof(*sa_in) && sa->sa_family == AF_INET) + { + StringCbPrintfA(serv, servlen, "%u", sa_in->sin_port); + return 0; + } + } + UNIMPLEMENTED WSASetLastError(WSASYSCALLFAILURE);