diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/hostip.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/hostip.c b/lib/hostip.c index 412844c3b..fe18e1d40 100644 --- a/lib/hostip.c +++ b/lib/hostip.c @@ -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); |