--- curl-7.12-hostip3/lib/hostip.h	Thu Apr 22 15:18:25 2004
+++ hostip.h	Thu Apr 22 17:42:40 2004
@@ -129,11 +129,6 @@
 /* copy a Curl_addrinfo struct, currently this only supports copying
    a hostent (ipv4-style) struct */
 Curl_addrinfo *Curl_addrinfo_copy(Curl_addrinfo *orig);
-
-/* This function is used to init a threaded resolve when that is built */
-bool Curl_init_resolve_thread(struct connectdata *conn,
-                              const char *hostname, int port,
-                              const Curl_addrinfo *hints);

 /*
  * Curl_cache_addr() stores a 'Curl_addrinfo' struct in the DNS cache.
--- curl-7.12-hostip3/lib/hostthre.c	Thu Apr 22 15:20:59 2004
+++ hostthre.c	Thu Apr 22 17:54:44 2004
@@ -97,6 +97,15 @@
  **********************************************************************/
 #ifdef CURLRES_THREADED

+#if defined(CURLRES_IPV4) && defined(CURLRES_IPV6)
+#error Problem! Both CURLRES_IPV4 and CURLRES_IPV6 defined
+#endif
+
+/* This function is used to init a threaded resolve when that is built */
+static bool init_resolve_thread(struct connectdata *conn,
+                                const char *hostname, int port,
+                                const Curl_addrinfo *hints);
+
 #ifdef CURLRES_IPV4
   #define THREAD_FUNC  gethostbyname_thread
   #define THREAD_NAME "gethostbyname_thread"
@@ -289,12 +298,12 @@
 }

 /*
- * Curl_init_resolve_thread() starts a new thread that performs the actual
+ * init_resolve_thread() starts a new thread that performs the actual
  * resolve. This function returns before the resolve is done.
  *
  * Returns FALSE in case of failure, otherwise TRUE.
  */
-bool Curl_init_resolve_thread(struct connectdata *conn,
+static bool init_resolve_thread (struct connectdata *conn,
                                const char *hostname, int port,
                                const Curl_addrinfo *hints)
 {
@@ -459,31 +469,119 @@
   return CURLE_OK;
 }

+#ifdef CURLRES_IPV4
 /*
- * Curl_getaddrinfo() - for Windows threading.
+ * Curl_getaddrinfo() - for Windows threading without ENABLE_IPV6.
  */
 Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
                                 char *hostname,
                                 int port,
                                 int *waitp)
 {
-  in_addr_t in = inet_addr(hostname);
+  struct hostent *h = NULL;
+  struct SessionHandle *data = conn->data;
+  in_addr_t in;

-  *waitp = FALSE; /* default to synch response */
+  *waitp = 0; /* don't wait, we act synchronously */

+  in = inet_addr(hostname);
   if (in != CURL_INADDR_NONE)
     /* This is a dotted IP address 123.123.123.123-style */
     return Curl_ip2addr(in, hostname);

   /* fire up a new resolver thread! */
-  if (Curl_init_resolve_thread(conn, hostname, port)) {
+  if (init_resolve_thread(conn, hostname, port, NULL)) {
     *waitp = TRUE;  /* please wait for the response */
     return NULL;
   }
-  infof(data, "Curl_init_resolve_thread() failed for %s; code %lu\n",
+
+  /* fall-back to blocking version */
+  infof(data, "init_resolve_thread() failed for %s; code %lu\n",
         hostname, GetLastError());

+  h = gethostbyname(hostname);
+  if (!h) {
+    infof(data, "gethostbyname(2) failed for %s:%d; %s\n",
+          hostname, port, Curl_strerror(conn,WSAGetLastError()));
+    return NULL;
+  }
+  return h;
+}
+#endif /* CURLRES_IPV4 */
+
+
+#ifdef CURLRES_IPV6
+/*
+ * Curl_getaddrinfo() - for Windows threading with ENABLE_IPV6.
+ */
+Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
+                                char *hostname,
+                                int port,
+                                int *waitp)
+{
+  struct addrinfo hints, *res;
+  int error;
+  char sbuf[NI_MAXSERV];
+  curl_socket_t s;
+  int pf;
+  struct SessionHandle *data = conn->data;
+
+  *waitp = FALSE; /* default to synch response */
+
+  /* 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.
+     */
+    sclose(s);
+
+    /*
+     * Check if a more limited name resolve has been requested.
+     */
+    switch(data->set.ip_version) {
+    case CURL_IPRESOLVE_V4:
+      pf = PF_INET;
+      break;
+    case CURL_IPRESOLVE_V6:
+      pf = PF_INET6;
+      break;
+    default:
+      pf = PF_UNSPEC;
+      break;
+    }
+  }
+
+  memset(&hints, 0, sizeof(hints));
+  hints.ai_family = pf;
+  hints.ai_socktype = SOCK_STREAM;
+  hints.ai_flags = AI_CANONNAME;
+  itoa(port, sbuf, 10);
+
+  /* fire up a new resolver thread! */
+  if (init_resolve_thread(conn, hostname, port, &hints)) {
+    *waitp = TRUE;  /* please wait for the response */
   return NULL;
 }

+  /* fall-back to blocking version */
+  infof(data, "init_resolve_thread() failed for %s; code %lu\n",
+        hostname, GetLastError());
+
+  error = getaddrinfo(hostname, sbuf, &hints, &res);
+  if (error) {
+    infof(data, "getaddrinfo() failed for %s:%d; %s\n",
+          hostname, port, Curl_strerror(conn,WSAGetLastError()));
+    return NULL;
+  }
+  return res;
+}
+#endif /* CURLRES_IPV6 */
 #endif /* CURLRES_THREADED */

