Index: include/curl/curl.h
===================================================================
RCS file: /cvsroot/curl/curl/include/curl/curl.h,v
retrieving revision 1.313
diff -u -r1.313 curl.h
--- include/curl/curl.h	8 Jan 2007 11:24:11 -0000	1.313
+++ include/curl/curl.h	30 Jan 2007 04:05:12 -0000
@@ -204,6 +204,10 @@
                                        is a file part) */
 };
 
+typedef void (*curl_preconnect_callback)(void *clientp,
+                                         struct sockaddr *addr,
+                                         int addrlen);
+
 typedef int (*curl_progress_callback)(void *clientp,
                                       double dltotal,
                                       double dlnow,
@@ -1054,6 +1058,11 @@
   /* Send CCC (Clear Command Channel) after authentication */
   CINIT(FTP_SSL_CCC, LONG, 154),
 
+  /* Called before any connect() happens. */
+  CINIT(PRECONNECT, FUNCTIONPOINT, 155),
+  CINIT(PRECONNECTDATA, OBJECTPOINT, 156),
+
+
   CURLOPT_LASTENTRY /* the last unused */
 } CURLoption;
 
Index: lib/connect.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/connect.c,v
retrieving revision 1.158
diff -u -r1.158 connect.c
--- lib/connect.c	22 Dec 2006 13:30:54 -0000	1.158
+++ lib/connect.c	30 Jan 2007 04:06:09 -0000
@@ -698,6 +698,10 @@
   Curl_printable_address(ai, addr_buf, sizeof(addr_buf));
   infof(data, "  Trying %s... ", addr_buf);
 
+  if(data->set.preconnect) {
+	  data->set.preconnect(data->set.preconnect_client, ai->ai_addr, ai->ai_addrlen);
+  }
+
   if(data->set.tcp_nodelay)
     tcpnodelay(conn, sockfd);
 
Index: lib/url.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/url.c,v
retrieving revision 1.579
diff -u -r1.579 url.c
--- lib/url.c	28 Jan 2007 22:45:22 -0000	1.579
+++ lib/url.c	30 Jan 2007 03:56:45 -0000
@@ -1701,6 +1701,14 @@
     data->set.ssh_private_key = va_arg(param, char *);
     break;
 
+  case CURLOPT_PRECONNECT:
+	  data->set.preconnect = va_arg(param, curl_preconnect_callback);
+	  break;
+
+  case CURLOPT_PRECONNECTDATA:
+	  data->set.preconnect_client = va_arg(param, void *);
+	  break;
+
   default:
     /* unknown tag and its companion, just ignore: */
     result = CURLE_FAILED_INIT; /* correct this */
Index: lib/urldata.h
===================================================================
RCS file: /cvsroot/curl/curl/lib/urldata.h,v
retrieving revision 1.316
diff -u -r1.316 urldata.h
--- lib/urldata.h	16 Jan 2007 22:22:25 -0000	1.316
+++ lib/urldata.h	30 Jan 2007 03:55:14 -0000
@@ -1155,6 +1155,7 @@
   unsigned short localport; /* local port number to bind to */
   int localportrange; /* number of additional port numbers to test in case the
                          'localport' one can't be bind()ed */
+  curl_preconnect_callback preconnect; /* function that is called before any connect() */
   curl_write_callback fwrite;        /* function that stores the output */
   curl_write_callback fwrite_header; /* function that stores headers */
   curl_read_callback fread;          /* function that reads the input */
@@ -1172,6 +1173,7 @@
   /* function to convert from UTF-8 encoding: */
   curl_conv_callback convfromutf8;
 
+  void *preconnect_client; /* pointer to pass to the preconnect callback */
   void *progress_client; /* pointer to pass to the progress callback */
   void *ioctl_client;   /* pointer to pass to the ioctl callback */
   long timeout;         /* in seconds, 0 means no timeout */

