diff -ruN curl-7.15.2/include/curl/curl.h curl-sockopt/include/curl/curl.h
--- curl-7.15.2/include/curl/curl.h	2006-02-11 14:35:16.000000000 -0800
+++ curl-sockopt/include/curl/curl.h	2006-03-15 15:47:34.000000000 -0800
@@ -122,6 +122,38 @@
 #undef FILESIZEBITS
 #endif
 
+#if (defined(WIN32) || defined(_WIN32)) && !defined(_WIN32_WCE) && \
+  !defined(__GNUC__) || defined(__MINGW32__)
+#if !(defined(_WINSOCKAPI_) || defined(_WINSOCK_H))
+/* The check above prevents the winsock2 inclusion if winsock.h already was
+   included, since they can't co-exist without problems */
+#include <winsock2.h>
+#endif
+#else
+
+/* HP-UX systems version 9, 10 and 11 lack sys/select.h and so does oldish
+   libc5-based Linux systems. Only include it on system that are known to
+   require it! */
+#if defined(_AIX) || defined(NETWARE)
+#include <sys/select.h>
+#endif
+
+#ifndef _WIN32_WCE
+#include <sys/socket.h>
+#endif
+#include <sys/time.h>
+#include <sys/types.h>
+#endif
+
+/* Public socket typedef */
+#if defined(WIN32) || defined(_WIN32)
+typedef SOCKET curl_socket_t;
+#define CURL_SOCKET_BAD INVALID_SOCKET
+#else
+typedef int curl_socket_t;
+#define CURL_SOCKET_BAD -1
+#endif
+
 struct curl_httppost {
   struct curl_httppost *next;       /* next entry in the list */
   char *name;                       /* pointer to allocated name */
@@ -173,6 +205,7 @@
                                       size_t nitems,
                                       void *instream);
 
+typedef void (*curl_sockopt_callback)(curl_socket_t curlfd);
 
 #ifndef CURL_NO_OLDIES
   /* not used since 7.10.8, will be removed in a future release */
@@ -927,6 +960,9 @@
      extracting it with CURLINFO_LASTSOCKET */
   CINIT(CONNECT_ONLY, LONG, 141),
 
+  /* Callback function for setting socket options */
+  CINIT(SOCKOPTFUNCTION, FUNCTIONPOINT, 142),
+
   CURLOPT_LASTENTRY /* the last unused */
 } CURLoption;
 
diff -ruN curl-7.15.2/include/curl/multi.h curl-sockopt/include/curl/multi.h
--- curl-7.15.2/include/curl/multi.h	2006-01-28 05:34:56.000000000 -0800
+++ curl-sockopt/include/curl/multi.h	2006-03-15 15:36:05.000000000 -0800
@@ -37,34 +37,6 @@
     file descriptors simultaneous easily.
 
 */
-#if defined(_WIN32) && !defined(WIN32)
-/* Chris Lewis mentioned that he doesn't get WIN32 defined, only _WIN32 so we
-   make this adjustment to catch this. */
-#define WIN32 1
-#endif
-
-#if defined(WIN32) && !defined(_WIN32_WCE) && !defined(__GNUC__) || \
-  defined(__MINGW32__)
-#if !(defined(_WINSOCKAPI_) || defined(_WINSOCK_H))
-/* The check above prevents the winsock2 inclusion if winsock.h already was
-   included, since they can't co-exist without problems */
-#include <winsock2.h>
-#endif
-#else
-
-/* HP-UX systems version 9, 10 and 11 lack sys/select.h and so does oldish
-   libc5-based Linux systems. Only include it on system that are known to
-   require it! */
-#if defined(_AIX) || defined(NETWARE) || defined(__NetBSD__)
-#include <sys/select.h>
-#endif
-
-#ifndef _WIN32_WCE
-#include <sys/socket.h>
-#endif
-#include <sys/time.h>
-#include <sys/types.h>
-#endif
 
 /*
  * This header file should not really need to include "curl.h" since curl.h
@@ -83,22 +55,6 @@
 
 typedef void CURLM;
 
-#ifdef HAVE_CURL_MULTI_SOCKET /* this is not set by anything yet */
-
-#ifndef curl_socket_typedef
-/* Public socket typedef */
-#ifdef WIN32
-typedef SOCKET curl_socket_t;
-#define CURL_SOCKET_BAD INVALID_SOCKET
-#else
-typedef int curl_socket_t;
-#define CURL_SOCKET_BAD -1
-#endif
-#define curl_socket_typedef
-#endif /* curl_socket_typedef */
-
-#endif /* HAVE_CURL_MULTI_SOCKET */
-
 typedef enum {
   CURLM_CALL_MULTI_PERFORM = -1, /* please call curl_multi_perform() soon */
   CURLM_OK,
diff -ruN curl-7.15.2/lib/connect.c curl-sockopt/lib/connect.c
--- curl-7.15.2/lib/connect.c	2006-02-27 07:53:56.000000000 -0800
+++ curl-sockopt/lib/connect.c	2006-03-15 15:46:31.000000000 -0800
@@ -688,6 +688,9 @@
 
   nosigpipe(conn, sockfd);
 
+  if(data->set.fsockopt)
+    data->set.fsockopt(sockfd);
+
   /* possibly bind the local end to an IP, interface or port */
   res = bindlocal(conn, sockfd);
   if(res) {
diff -ruN curl-7.15.2/lib/setup.h curl-sockopt/lib/setup.h
--- curl-7.15.2/lib/setup.h	2006-01-23 05:50:43.000000000 -0800
+++ curl-sockopt/lib/setup.h	2006-03-15 15:33:19.000000000 -0800
@@ -279,15 +279,6 @@
 
 #endif /* WIN32 */
 
-/* now typedef our socket type */
-#ifdef WIN32
-typedef SOCKET curl_socket_t;
-#define CURL_SOCKET_BAD INVALID_SOCKET
-#else
-typedef int curl_socket_t;
-#define CURL_SOCKET_BAD -1
-#endif
-
 #if defined(ENABLE_IPV6) && defined(USE_ARES)
 #error "ares does not yet support IPv6. Disable IPv6 or ares and rebuild"
 #endif
diff -ruN curl-7.15.2/lib/url.c curl-sockopt/lib/url.c
--- curl-7.15.2/lib/url.c	2006-02-24 14:36:40.000000000 -0800
+++ curl-sockopt/lib/url.c	2006-03-15 15:46:59.000000000 -0800
@@ -1486,6 +1486,13 @@
     data->set.connect_only = va_arg(param, long)?TRUE:FALSE;
     break;
 
+  case CURLOPT_SOCKOPTFUNCTION:
+    /*
+     * Set header write callback
+     */
+    data->set.fsockopt = va_arg(param, curl_sockopt_callback);
+    break;
+ 
   default:
     /* unknown tag and its companion, just ignore: */
     result = CURLE_FAILED_INIT; /* correct this */
diff -ruN curl-7.15.2/lib/urldata.h curl-sockopt/lib/urldata.h
--- curl-7.15.2/lib/urldata.h	2006-02-11 14:35:17.000000000 -0800
+++ curl-sockopt/lib/urldata.h	2006-03-15 15:47:14.000000000 -0800
@@ -981,6 +981,7 @@
   curl_progress_callback fprogress;  /* function for progress information */
   curl_debug_callback fdebug;      /* function that write informational data */
   curl_ioctl_callback ioctl;       /* function for I/O control */
+  curl_sockopt_callback fsockopt;	   /* function for setting socket options */
   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 */
