From fb29529a52cd4d889173e30d50ed08cc05dee198 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 15 Mar 2002 09:54:30 +0000 Subject: Jun-ichiro itojun Hagino : 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 --- lib/hostip.c | 18 ++++++++++++++++-- 1 file 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); -- cgit v1.2.3