--- curl/lib/hostip4.c 2008-03-16 19:03:28.000000000 +0000 +++ curl-7.18.0/lib/hostip4.c 2008-03-16 19:13:08.000000000 +0000 @@ -346,6 +346,7 @@ Curl_addrinfo *prevai = NULL; Curl_addrinfo *firstai = NULL; struct sockaddr_in *addr; + struct sockaddr_in6 *addr6; int i; struct in_addr *curr; @@ -355,7 +356,11 @@ 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); + if (he->h_addrtype == AF_INET6) + ss_size = sizeof (struct sockaddr_in6); + + ai = calloc(1, sizeof(Curl_addrinfo) + ss_size); if(!ai) break; @@ -368,13 +373,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 +389,23 @@ /* 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; + + case AF_INET6: + addr6 = (struct sockaddr_in6 *)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); + 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; + } prevai = ai; } --- curl/lib/hostares.c 2008-03-16 19:03:28.000000000 +0000 +++ curl-7.18.0/lib/hostares.c 2008-03-16 19:02:27.000000000 +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,23 @@ return Curl_ip2addr(in, hostname, port); } +#ifdef CURLRES_IPV6 + struct addrinfo *ai = NULL; + struct addrinfo hints; + char ports[16]; + sprintf (ports, "%d", port); + memset (&hints, 0, sizeof (hints)); + hints.ai_flags = AI_NUMERICHOST; + hints.ai_family = AF_INET6; + hints.ai_socktype = SOCK_STREAM; + if (getaddrinfo (hostname, ports, &hints, &ai) == 0) { + /* This must be an IPv6 address literal. */ + return ai; + } + + family = PF_INET6; +#endif + bufp = strdup(hostname); if(bufp) { @@ -332,7 +350,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 */