cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: [ curl-Bugs-530204 ] curl 7.9.5 does not support IPv6

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Fri, 15 Mar 2002 10:51:46 +0100 (MET)

On Fri, 15 Mar 2002, Daniel Stenberg wrote:

(/me talks to himself again)

> Anyone with a nice and clean solution to this dilemma? We can hardly be the
> first to face this.

Jun-ichiro itojun Hagino provided one that is neat enough and that I am just
about to commit. It'll make use of the PF_INET on non-IPv6 hosts and
PF_UNSPEC on IPv6 hosts.

Patch follows:

diff -u -r1.54 hostip.c
--- hostip.c 15 Mar 2002 08:45:09 -0000 1.54
+++ hostip.c 15 Mar 2002 09:49:47 -0000
@@ -291,9 +291,23 @@
   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);

-- 
    Daniel Stenberg -- curl groks URLs -- http://curl.haxx.se/
Received on 2002-03-15