Package: netcat
Version: 1.10-27
Severity: wishlist
Tags: patch
Having an option to turn on the SO_KEEPALIVE sockopt would be nice.
This would allow a netcat in server mode detect if a connection died in
some improper way (a router in path broke, or client unexpectedly lost
internet connectivity, for example).
-- System Information:
Debian Release: 3.1
Architecture: i386 (i686)
Kernel: Linux 2.6.15-1-686-smp
Locale: LANG=en_US, LC_CTYPE=en_US (charmap=ISO-8859-1)
Versions of packages netcat depends on:
ii libc6 2.3.2.ds1-22 GNU C Library: Shared libraries an
-- no debconf information
diff -u -N -r netcat-1.10.orig/debian/patches/series netcat-1.10/debian/patches/series
--- netcat-1.10.orig/debian/patches/series 2006-03-22 16:30:51.188751256 -0500
+++ netcat-1.10/debian/patches/series 2006-03-22 16:28:03.959667585 -0500
@@ -13,3 +13,4 @@
sh-c.patch
tos.patch
rservice-buf.patch
+so-keepalive.patch
diff -u -N -r netcat-1.10.orig/debian/patches/so-keepalive.patch netcat-1.10/debian/patches/so-keepalive.patch
--- netcat-1.10.orig/debian/patches/so-keepalive.patch 1969-12-31 19:00:00.000000000 -0500
+++ netcat-1.10/debian/patches/so-keepalive.patch 2006-03-22 16:41:26.018561739 -0500
@@ -0,0 +1,50 @@
+--- netcat-1.10.orig/netcat.c 2006-03-22 15:21:36.000000000 -0500
++++ netcat-1.10/netcat.c 2006-03-22 16:41:22.101193639 -0500
+@@ -177,6 +177,7 @@
+ unsigned int o_wait = 0;
+ USHORT o_zero = 0;
+ int o_quit = -1; /* 0 == quit-now; >0 == quit after o_quit seconds */
++int o_keepalive = 0;
+ #ifdef IP_TOS
+ unsigned char o_tos = 0;
+ #endif
+@@ -694,6 +695,13 @@
+ holler ("nnetfd tos failed"); /* ??? */
+ }
+ #endif
++ if (o_keepalive) {
++ x = 1;
++ rr = setsockopt(nnetfd, SOL_SOCKET, SO_KEEPALIVE, &x, sizeof(x));
++ if (rr == -1) {
++ holler("nnetfd set keepalive failed");
++ }
++ }
+ #if 0
+ /* If you want to screw with RCVBUF/SNDBUF, do it here. Liudvikas Bukys at
+ Rochester sent this example, which would involve YET MORE options and is
+@@ -1513,7 +1521,7 @@
+
+ /* If your shitbox doesn't have getopt, step into the nineties already. */
+ /* optarg, optind = next-argv-component [i.e. flag arg]; optopt = last-char */
+- while ((x = getopt (argc, argv, "abc:e:g:G:hi:lno:p:q:rs:tuvw:x:z")) != EOF) {
++ while ((x = getopt (argc, argv, "abc:e:g:G:hi:klno:p:q:rs:tuvw:x:z")) != EOF) {
+ /* Debug (("in go: x now %c, optarg %x optind %d", x, optarg, optind)) */
+ switch (x) {
+ case 'a':
+@@ -1560,6 +1568,8 @@
+ if (! o_interval)
+ bail ("invalid interval time %s", optarg);
+ break;
++ case 'k':
++ o_keepalive = 1; break;
+ case 'l': /* listen mode */
+ o_listen++; break;
+ case 'n': /* numeric-only, no DNS lookups */
+@@ -1815,6 +1825,7 @@
+ -G num source-routing pointer: 4, 8, 12, ...\n\
+ -h this cruft\n\
+ -i secs delay interval for lines sent, ports scanned\n\
++ -k set keepalive option on socket\n\
+ -l listen mode, for inbound connects\n\
+ -n numeric-only IP addresses, no DNS\n\
+ -o file hex dump of traffic\n\