--- _CVS_cURL_orig_jan/curl/src/main.c	2008-01-04 06:51:59.000000000 +0100
+++ _CVS_cURL_modif_jan_v2/curl/src/main.c	2008-01-04 20:58:22.000000000 +0100
@@ -104,6 +104,15 @@
 #endif
 #endif /* CURL_DOES_CONVERSIONS && HAVE_ICONV */
 
+#ifndef WIN32
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h> /* for IPPROTO_TCP */
+#endif
+#ifdef HAVE_NETINET_TCP_H
+#include <netinet/tcp.h> /* for TCP_KEEPCNT, TCP_KEEPIDLE, TCP_INTVL */
+#endif
+#endif
+
 /* The last #include file should be: */
 #ifdef CURLDEBUG
 #ifndef CURLTOOLDEBUG
@@ -479,7 +488,12 @@
   char *libcurl; /* output libcurl code to this file name */
   bool raw;
   bool post301;
-  bool nokeepalive;
+
+  bool keepalive; /* for keepalive needs */
+  long tcp_keepidle;
+  long tcp_keepintvl;
+  long tcp_keepcnt;
+
   struct OutStruct *outs;
 };
 
@@ -688,7 +702,7 @@
     "    --netrc-optional Use either .netrc or URL; overrides -n",
     "    --ntlm          Use HTTP NTLM authentication (H)",
     " -N/--no-buffer     Disable buffering of the output stream",
-    "    --no-keep-alive Disable keep-alive use on the connection",
+    "    --keep-alive    Enable keep-alive use on the connection",
     "    --no-sessionid  Disable SSL session-ID reusing (SSL)",
     " -o/--output <file> Write output to <file> instead of stdout",
     " -O/--remote-name   Write output to a file named as the remote file",
@@ -715,6 +729,9 @@
     "    --socks4a <host[:port]> Use SOCKS4a proxy on given host + port",
     "    --socks5 <host[:port]> Use SOCKS5 proxy on given host + port",
     "    --stderr <file> Where to redirect stderr. - means stdout",
+    "    --tcp-keepcnt <number> Maximum number of keepalive probes",
+    "    --tcp-keepidle <seconds> Time before sending keepalive probes",
+    "    --tcp-keepintvl <seconds> Time between individual keepalive probes",
     " -t/--telnet-option <OPT=val> Set telnet option",
     "    --trace <file>  Write a debug trace to the given file",
     "    --trace-ascii <file> Like --trace but without the hex output",
@@ -1434,11 +1451,14 @@
 }
 
 
-static int set_so_keepalive(void *clientp, curl_socket_t curlfd,
+static int set_keepalive(void *clientp, curl_socket_t curlfd,
                             curlsocktype purpose)
 {
   struct Configurable *config = (struct Configurable *)clientp;
-  int onoff = config->nokeepalive ? 0 : 1;
+  int onoff = config->keepalive ? 1 : 0;
+  long keepcnt = config->tcp_keepcnt;
+  long keepidle = config->tcp_keepidle;
+  long keepintvl = config->tcp_keepintvl;
 
   switch (purpose) {
   case CURLSOCKTYPE_IPCXN:
@@ -1447,6 +1467,33 @@
       warnf(clientp, "Could not set SO_KEEPALIVE!\n");
       return 1;
     }
+#ifdef TCP_KEEPCNT
+    if (config->tcp_keepcnt>0) {
+      if(setsockopt(curlfd, IPPROTO_TCP, TCP_KEEPCNT, (void *)&keepcnt,
+                    sizeof(keepcnt)) < 0) {
+        warnf(clientp, "Could not set TCP_KEEPCNT!\n");
+        return 1;
+      }
+    }
+#endif
+#ifdef TCP_KEEPIDLE
+    if (config->tcp_keepidle>0) {
+      if(setsockopt(curlfd, IPPROTO_TCP, TCP_KEEPIDLE, (void *)&keepidle,
+                    sizeof(keepidle)) < 0) {
+        warnf(clientp, "Could not set TCP_KEEPIDLE!\n");
+        return 1;
+      }
+    }
+#endif
+#ifdef TCP_KEEPINTVL
+    if (config->tcp_keepintvl>0) {
+      if(setsockopt(curlfd, IPPROTO_TCP, TCP_KEEPINTVL, (void *)&keepintvl,
+                    sizeof(keepintvl)) < 0) {
+        warnf(clientp, "Could not set TCP_KEEPINTVL!\n");
+        return 1;
+      }
+    }
+#endif
     break;
   default:
     break;
@@ -1455,7 +1502,6 @@
   return 0;
 }
 
-
 static ParameterError getparameter(char *flag, /* f or -long-flag */
                                    char *nextarg, /* NULL if unset */
                                    bool *usedarg, /* set to TRUE if the arg
@@ -1543,7 +1589,10 @@
     {"$z", "libcurl",    TRUE},
     {"$#", "raw",        FALSE},
     {"$0", "post301",    FALSE},
-    {"$1", "no-keep-alive",    FALSE},
+    {"$1", "keep-alive",    FALSE},
+    {"$2", "tcp-keepcnt",    TRUE},
+    {"$3", "tcp-keepidle",    TRUE},
+    {"$4", "tcp-keepintvl",    TRUE},
 
     {"0", "http1.0",     FALSE},
     {"1", "tlsv1",       FALSE},
@@ -2004,8 +2053,20 @@
       case '0': /* --post301 */
         config->post301 ^= TRUE;
         break;
-      case '1': /* --no-keep-alive */
-        config->nokeepalive ^= TRUE;
+      case '1': /* --keep-alive */
+        config->keepalive ^= TRUE;
+        break;
+      case '2': /* --tcp-keepcnt */
+        if(str2num(&config->tcp_keepcnt, nextarg))
+          return PARAM_BAD_NUMERIC;
+        break;
+      case '3': /* --tcp-keepidle */
+        if(str2num(&config->tcp_keepidle, nextarg))
+          return PARAM_BAD_NUMERIC;
+        break;
+      case '4': /* --tcp-keepintvl */
+        if(str2num(&config->tcp_keepintvl, nextarg))
+          return PARAM_BAD_NUMERIC;
         break;
       }
       break;
@@ -4533,8 +4594,10 @@
 
         /* curl 7.17.1 */
         my_setopt(curl, CURLOPT_POST301, config->post301);
-        if (!config->nokeepalive) {
-          my_setopt(curl, CURLOPT_SOCKOPTFUNCTION, set_so_keepalive);
+
+        /* curl version to be defined */
+        if (config->keepalive) {
+          my_setopt(curl, CURLOPT_SOCKOPTFUNCTION, set_keepalive);
           my_setopt(curl, CURLOPT_SOCKOPTDATA, config);
         }
 
