From 0732e52c41ea6c49f786c0d6178cd17b26faf136 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Tue, 19 Nov 2013 18:07:46 +0000 Subject: [PATCH] * net.cc (cygwin_getaddrinfo): Fix a comment. Only memset whints if hints is NULL. Add a comment and set whints.ai_family explicitely to AF_UNSPEC to follow glibc man page closely. Check flags against whints for locality. --- winsup/cygwin/ChangeLog | 7 +++++++ winsup/cygwin/net.cc | 17 ++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index a92e0c6d7..5dd469362 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,10 @@ +2013-11-19 Corinna Vinschen + + * net.cc (cygwin_getaddrinfo): Fix a comment. Only memset whints if + hints is NULL. Add a comment and set whints.ai_family explicitely to + AF_UNSPEC to follow glibc man page closely. Check flags against whints + for locality. + 2013-11-19 Corinna Vinschen * wincap.cc (wincapc::init): Fix dwMinorVersion for Windows 8.1 and diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index 141fa284e..bde6695cd 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -3294,9 +3294,8 @@ cygwin_getaddrinfo (const char *hostname, const char *servname, | AI_NUMERICSERV | AI_ADDRCONFIG | AI_V4MAPPED | AI_IDN_MASK))) return EAI_BADFLAGS; - /* AI_NUMERICSERV is not supported in our replacement getaddrinfo, nor - is it supported by WinSock prior to Vista. We just check the servname - parameter by ourselves here. */ + /* AI_NUMERICSERV is not supported prior to Windows Vista. We just check + the servname parameter by ourselves here. */ if (hints && (hints->ai_flags & AI_NUMERICSERV)) { char *p; @@ -3341,9 +3340,13 @@ cygwin_getaddrinfo (const char *hostname, const char *servname, return EAI_MEMORY; } - memset (&whints, 0, sizeof whints); if (!hints) - whints.ai_flags = AI_V4MAPPED | AI_ADDRCONFIG; + { + /* Default settings per glibc man page. */ + memset (&whints, 0, sizeof whints); + whints.ai_family = PF_UNSPEC; + whints.ai_flags = AI_V4MAPPED | AI_ADDRCONFIG; + } else { /* sizeof addrinfo == sizeof addrinfoW */ @@ -3355,8 +3358,8 @@ cygwin_getaddrinfo (const char *hostname, const char *servname, apparently for performance reasons. To get the POSIX default behaviour, the AI_ALL flag has to be set. */ if (wincap.supports_all_posix_ai_flags () - && hints->ai_family == PF_UNSPEC - && !(hints->ai_flags & AI_ADDRCONFIG)) + && whints.ai_family == PF_UNSPEC + && !(whints.ai_flags & AI_ADDRCONFIG)) whints.ai_flags |= AI_ALL; } /* Disable automatic IDN conversion on W8 and later. */