Index: hostares.c =================================================================== RCS file: /cvsroot/curl/curl/lib/hostares.c,v retrieving revision 1.36 diff -u -r1.36 hostares.c --- hostares.c 7 Nov 2007 09:21:35 -0000 1.36 +++ hostares.c 17 Mar 2008 20:17:09 -0000 @@ -313,6 +313,7 @@ char *bufp; struct SessionHandle *data = conn->data; in_addr_t in = inet_addr(hostname); + int family = PF_INET; *waitp = FALSE; @@ -321,6 +322,16 @@ return Curl_ip2addr(in, hostname, port); } +#ifdef CURLRES_IPV6 + struct in6_addr in6; + if (inet_pton (AF_INET6, hostname, &in6) > 0) { + /* This must be an IPv6 address literal. */ + return Curl_ip2addr6(&in6, hostname, port); + } + + family = PF_INET6; +#endif + bufp = strdup(hostname); if(bufp) { @@ -332,7 +343,7 @@ conn->async.dns = NULL; /* clear */ /* areschannel is already setup in the Curl_open() function */ - ares_gethostbyname(data->state.areschannel, hostname, PF_INET, + ares_gethostbyname(data->state.areschannel, hostname, family, (ares_host_callback)Curl_addrinfo4_callback, conn); *waitp = TRUE; /* please wait for the response */ Index: hostip4.c =================================================================== RCS file: /cvsroot/curl/curl/lib/hostip4.c,v retrieving revision 1.42 diff -u -r1.42 hostip4.c --- hostip4.c 7 Nov 2007 09:21:35 -0000 1.42 +++ hostip4.c 17 Mar 2008 20:17:09 -0000 @@ -346,6 +346,9 @@ Curl_addrinfo *prevai = NULL; Curl_addrinfo *firstai = NULL; struct sockaddr_in *addr; +#ifdef CURLRES_IPV6 + struct sockaddr_in6 *addr6; +#endif int i; struct in_addr *curr; @@ -355,7 +358,13 @@ for(i=0; (curr = (struct in_addr *)he->h_addr_list[i]) != NULL; i++) { - ai = calloc(1, sizeof(Curl_addrinfo) + sizeof(struct sockaddr_in)); + int ss_size = sizeof (struct sockaddr_in); +#ifdef CURLRES_IPV6 + if (he->h_addrtype == AF_INET6) + ss_size = sizeof (struct sockaddr_in6); +#endif + + ai = calloc(1, sizeof(Curl_addrinfo) + ss_size); if(!ai) break; @@ -368,13 +377,13 @@ /* make the previous entry point to this */ prevai->ai_next = ai; - ai->ai_family = AF_INET; /* we only support this */ + ai->ai_family = he->h_addrtype; /* we return all names as STREAM, so when using this address for TFTP the type must be ignored and conn->socktype be used instead! */ ai->ai_socktype = SOCK_STREAM; - ai->ai_addrlen = sizeof(struct sockaddr_in); + ai->ai_addrlen = ss_size; /* make the ai_addr point to the address immediately following this struct and use that area to store the address */ ai->ai_addr = (struct sockaddr *) ((char*)ai + sizeof(Curl_addrinfo)); @@ -384,11 +393,25 @@ /* leave the rest of the struct filled with zero */ - addr = (struct sockaddr_in *)ai->ai_addr; /* storage area for this info */ + switch (ai->ai_family) { + case AF_INET: + addr = (struct sockaddr_in *)ai->ai_addr; /* storage area for this info */ + + memcpy((char *)&(addr->sin_addr), curr, sizeof(struct in_addr)); + addr->sin_family = (unsigned short)(he->h_addrtype); + addr->sin_port = htons((unsigned short)port); + break; - memcpy((char *)&(addr->sin_addr), curr, sizeof(struct in_addr)); - addr->sin_family = (unsigned short)(he->h_addrtype); - addr->sin_port = htons((unsigned short)port); +#ifdef CURLRES_IPV6 + case AF_INET6: + addr6 = (struct sockaddr_in6 *)ai->ai_addr; /* storage area for this info */ + + memcpy((char *)&(addr6->sin6_addr), curr, sizeof(struct in6_addr)); + addr6->sin6_family = (unsigned short)(he->h_addrtype); + addr6->sin6_port = htons((unsigned short)port); + break; +#endif + } prevai = ai; }