https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=7176a85cd48d37bc068312ffa79f254305cf4511

commit 7176a85cd48d37bc068312ffa79f254305cf4511
Author: Corinna Vinschen <cori...@vinschen.de>
Date:   Mon Mar 14 17:57:22 2016 +0100

    cygwin_getaddrinfo: workaround Winsock getaddrinfo issue with broken DNS
    
    Add experimental code to workaround the issue described in the thread
    starting at
    
      https://cygwin.com/ml/cygwin/2015-07/msg00350.html
    
    There's a hint in https://communities.vmware.com/message/2577858#2577858
    that this problem is related to using the AI_ALL flag.
    
    This patch checks if GetAddrInfoW returned with WSANO_RECOVERY and if
    the AI_ALL flag was set, it retries GetAddrInfo without the AI_ALL flag.
    
        * net.cc (cygwin_getaddrinfo): Add experimental code to retry
        GetAddrInfoW without AI_ALL flag if it returned with WSANO_RECOVERY.
    
    Signed-off-by: Corinna Vinschen <cori...@vinschen.de>

Diff:
---
 winsup/cygwin/net.cc | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc
index f046a3b..31bc11d 100644
--- a/winsup/cygwin/net.cc
+++ b/winsup/cygwin/net.cc
@@ -3595,7 +3595,16 @@ cygwin_getaddrinfo (const char *hostname, const char 
*servname,
        }
       /* Disable automatic IDN conversion on W8 and later. */
       whints.ai_flags |= AI_DISABLE_IDN_ENCODING;
-      ret = w32_to_gai_err (GetAddrInfoW (whost, wserv, &whints, &wres));
+      ret = GetAddrInfoW (whost, wserv, &whints, &wres);
+      /* Try to workaround an apparent shortcoming in Winsock's getaddrinfo
+        implementation.  See this link for details:
+        https://communities.vmware.com/message/2577858#2577858 */
+      if (ret == WSANO_RECOVERY && (whints.ai_flags & AI_ALL))
+       {
+         whints.ai_flags &= ~AI_ALL;
+         ret = GetAddrInfoW (whost, wserv, &whints, &wres);
+       }
+      ret = w32_to_gai_err (ret);
       /* Always copy over to self-allocated memory. */
       if (!ret)
        {

Reply via email to