summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin
diff options
context:
space:
mode:
Diffstat (limited to 'winsup/cygwin')
-rw-r--r--winsup/cygwin/ChangeLog6
-rw-r--r--winsup/cygwin/net.cc31
2 files changed, 25 insertions, 12 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 3c3b53a02..10cb43e72 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,9 @@
+2009-08-06 Corinna Vinschen <corinna@vinschen.de>
+
+ * net.cc (cygwin_getnameinfo): Force setting NI_NUMERICSERV only
+ on Windows 2003 and earlier, only if the port number doesn't
+ resolve to a well-known service. Change comment accordingly.
+
2009-08-05 Christopher Faylor <me+cygwin@cgf.cx>
* cygheap.h (cygheap_debug::endh): Delete.
diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc
index 85e150738..efc06ad25 100644
--- a/winsup/cygwin/net.cc
+++ b/winsup/cygwin/net.cc
@@ -4458,20 +4458,27 @@ cygwin_getnameinfo (const struct sockaddr *sa, socklen_t salen,
if (!getnameinfo)
return ipv4_getnameinfo (sa, salen, host, hostlen, serv, servlen, flags);
- /* When the incoming port number is set to 0, Winsock's getnameinfo
- returns with error WSANO_DATA instead of simply ignoring the port.
- To avoid this strange behaviour, we check manually, if the port number
- is 0. If so, set the NI_NUMERICSERV flag to avoid this problem. */
- switch (sa->sa_family)
+ /* When the incoming port number does not resolve to a well-known service,
+ Winsock's getnameinfo up to Windows 2003 returns with error WSANO_DATA
+ instead of setting `serv' to the numeric port number string, as required
+ by RFC 3493. This is fixed on Vista and later. To avoid the error on
+ systems up to Windows 2003, we check if the port number resolves
+ to a well-known service. If not, we set the NI_NUMERICSERV flag. */
+ if (!wincap.supports_all_posix_ai_flags ())
{
- case AF_INET:
- if (((struct sockaddr_in *) sa)->sin_port == 0)
- flags |= NI_NUMERICSERV;
- break;
- case AF_INET6:
- if (((struct sockaddr_in6 *) sa)->sin6_port == 0)
+ int port = 0;
+
+ switch (sa->sa_family)
+ {
+ case AF_INET:
+ port = ((struct sockaddr_in *) sa)->sin_port;
+ break;
+ case AF_INET6:
+ port = ((struct sockaddr_in6 *) sa)->sin6_port;
+ break;
+ }
+ if (!port || !getservbyport (port, flags & NI_DGRAM ? "udp" : "tcp"))
flags |= NI_NUMERICSERV;
- break;
}
int ret = w32_to_gai_err (getnameinfo (sa, salen, host, hostlen, serv,
servlen, flags));