Commit fb29529a authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

Jun-ichiro itojun Hagino <itojun@itojun.org>:

Now first check if IPv6 is supported, then use PF_UNSPEC. If not, use PF_INET.
It'll solve both the "slow name lookup" problem on IPv4 and still work fine on
IPv6 hosts.

Bug report #530204 has more details:
http://sourceforge.net/tracker/?func=detail&atid=100976&aid=530204&group_id=976
parent 3cd26730
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -291,9 +291,23 @@ Curl_addrinfo *Curl_getaddrinfo(struct SessionHandle *data,
  struct addrinfo hints, *res;
  int error;
  char sbuf[NI_MAXSERV];
  int s, pf = PF_UNSPEC;

  /* see if we have an IPv6 stack */
  s = socket(PF_INET6, SOCK_DGRAM, 0);
  if (s < 0)
    /* Some non-IPv6 stacks have been found to make very slow name resolves
     * when PF_UNSPEC is used, so thus we switch to a mere PF_INET lookup if
     * the stack seems to be a non-ipv6 one. */
    pf = PF_INET;
  else
    /* This seems to be an IPv6-capable stack, use PF_UNSPEC for the widest
     * possible checks. And close the socket again.
     */
    close(s);
 
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = PF_UNSPEC;
  hints.ai_family = pf;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = AI_CANONNAME;
  snprintf(sbuf, sizeof(sbuf), "%d", port);