Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2009-08-06 18:55:49 +0400
committerCorinna Vinschen <corinna@vinschen.de>2009-08-06 18:55:49 +0400
commit19753e1dbf4c775e89fdbef7f032dbb348d22540 (patch)
tree5d6b32ef7b22e5e2fe295f6a7899a5a5a477ff4f /winsup/cygwin/net.cc
parenta99345591f51350eee9f52fab5163412edef1804 (diff)
* 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.
Diffstat (limited to 'winsup/cygwin/net.cc')
-rw-r--r--winsup/cygwin/net.cc31
1 files changed, 19 insertions, 12 deletions
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));