diff options
author | Daniel Stenberg <daniel@haxx.se> | 2002-03-15 09:54:30 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2002-03-15 09:54:30 +0000 |
commit | fb29529a52cd4d889173e30d50ed08cc05dee198 (patch) | |
tree | 909093fd2afdcc6d71455db4d775b36b40531c59 /lib | |
parent | 3cd267307764a979df61618540e067d147a63feb (diff) |
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
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); |