diff -ruN netcat-1.10.orig/Makefile netcat-1.10/Makefile --- netcat-1.10.orig/Makefile Wed Mar 20 04:16:06 1996 +++ netcat-1.10/Makefile Tue Oct 23 12:10:27 2001 @@ -9,12 +9,13 @@ # pick gcc if you'd rather , and/or do -g instead of -O if debugging # debugging # DFLAGS = -DTEST -DDEBUG +DFLAGS = -DTELNET CFLAGS = -O XFLAGS = # xtra cflags, set by systype targets XLIBS = # xtra libs if necessary? # -Bstatic for sunos, -static for gcc, etc. You want this, trust me. STATIC = -CC = cc $(CFLAGS) +CC = gcc $(CFLAGS) LD = $(CC) -s # linker; defaults to stripped executables o = o # object extension @@ -67,7 +68,7 @@ make -e $(ALL) $(MFLAGS) XFLAGS='-DAIX' linux: - make -e $(ALL) $(MFLAGS) XFLAGS='-DLINUX' STATIC=-static + make -e $(ALL) $(MFLAGS) XFLAGS='-DLINUX' # irix 5.2, dunno 'bout earlier versions. If STATIC='-non_shared' doesn't # work for you, null it out and yell at SGI for their STUPID default Binary files netcat-1.10.orig/nc and netcat-1.10/nc differ diff -ruN netcat-1.10.orig/netcat.c netcat-1.10/netcat.c --- netcat-1.10.orig/netcat.c Thu Mar 21 01:38:04 1996 +++ netcat-1.10/netcat.c Tue Oct 23 12:25:21 2001 @@ -73,6 +73,7 @@ #include #include #include /* O_WRONLY et al */ +#include /* handy stuff: */ #define SA struct sockaddr /* socket overgeneralization braindeath */ @@ -160,6 +161,7 @@ USHORT o_verbose = 0; unsigned int o_wait = 0; USHORT o_zero = 0; +int o_quit = -1; /* 0 == quit-now; >0 == quit after o_quit seconds */ /* o_tn in optional section */ /* Debug macro: squirt whatever message and sleep a bit so we can see it go @@ -211,7 +213,6 @@ o_verbose = 1; holler (str, p1, p2, p3, p4, p5, p6); close (netfd); - sleep (1); exit (1); } /* bail */ @@ -222,7 +223,15 @@ errno = 0; if (o_verbose > 1) /* normally we don't care */ bail (wrote_txt, wrote_net, wrote_out); - bail (" punt!"); + bail (""); +} + +/* quit : + handler for a "-q" timeout (exit 0 instead of 1) */ +void quit() +{ + close(netfd); + exit(0); } /* timeout and other signal handling cruft */ @@ -235,9 +244,9 @@ longjmp (jbuf, jval); } -/* arm : +/* arm_timer : set the timer. Zero secs arg means unarm */ -void arm (num, secs) +void arm_timer (num, secs) unsigned int num; unsigned int secs; { @@ -250,7 +259,7 @@ alarm (secs); jval = num; } /* if secs */ -} /* arm */ +} /* arm_timer */ /* Hmalloc : malloc up what I want, rounded up to *4, and pre-zeroed. Either succeeds @@ -743,14 +752,14 @@ } /* if gatesidx */ /* wrap connect inside a timer, and hit it */ - arm (1, o_wait); + arm_timer (1, o_wait); if (setjmp (jbuf) == 0) { rr = connect (nnetfd, (SA *)remend, sizeof (SA)); } else { /* setjmp: connect failed... */ rr = -1; errno = ETIMEDOUT; /* fake it */ } - arm (0, 0); + arm_timer (0, 0); if (rr == 0) return (nnetfd); close (nnetfd); /* clean up junked socket FD!! */ @@ -820,14 +829,14 @@ actually does work after all. Yow. YMMV on strange platforms! */ if (o_udpmode) { x = sizeof (SA); /* retval for recvfrom */ - arm (2, o_wait); /* might as well timeout this, too */ + arm_timer (2, o_wait); /* might as well timeout this, too */ if (setjmp (jbuf) == 0) { /* do timeout for initial connect */ rr = recvfrom /* and here we block... */ (nnetfd, bigbuf_net, BIGSIZ, MSG_PEEK, (SA *) remend, &x); Debug (("dolisten/recvfrom ding, rr = %d, netbuf %s ", rr, bigbuf_net)) } else goto dol_tmo; /* timeout */ - arm (0, 0); + arm_timer (0, 0); /* I'm not completely clear on how this works -- BSD seems to make UDP just magically work in a connect()ed context, but we'll undoubtedly run into systems this deal doesn't work on. For now, we apparently have to @@ -845,12 +854,12 @@ /* fall here for TCP */ x = sizeof (SA); /* retval for accept */ - arm (2, o_wait); /* wrap this in a timer, too; 0 = forever */ + arm_timer (2, o_wait); /* wrap this in a timer, too; 0 = forever */ if (setjmp (jbuf) == 0) { rr = accept (nnetfd, (SA *)remend, &x); } else goto dol_tmo; /* timeout */ - arm (0, 0); + arm_timer (0, 0); close (nnetfd); /* dump the old socket */ nnetfd = rr; /* here's our new one */ @@ -1216,6 +1225,7 @@ if (rr <= 0) { /* at end, or fukt, or ... */ FD_CLR (0, ding1); /* disable and close stdin */ close (0); + shutdown(fd, 1); } else { rzleft = rr; zp = bigbuf_in; @@ -1389,7 +1399,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, "ae:g:G:hi:lno:p:rs:tuvw:z")) != EOF) { + while ((x = getopt (argc, argv, "ae:g:G:hi:lno:p:q:rs:tuvw:z")) != EOF) { /* Debug (("in go: x now %c, optarg %x optind %d", x, optarg, optind)) */ switch (x) { case 'a': @@ -1443,6 +1453,8 @@ break; case 'r': /* randomize various things */ o_random++; break; + case 'q': /* quit after stdin does EOF */ + o_quit = atoi(optarg); break; case 's': /* local source address */ /* do a full lookup [since everything else goes through the same mill], unless -n was previously specified. In fact, careful placement of -n can @@ -1651,6 +1663,7 @@ -o file hex dump of traffic\n\ -p port local port number\n\ -r randomize local and remote ports\n\ + -q secs quit after EOF on stdin and delay of secs\n\ -s addr local source address"); #ifdef TELNET holler ("\