[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: system/2091: New /usr/bin/nc (2.9-current), no std-in/out support



The following reply was made to PR system/2091; it has been noted by GNATS.

From: "Brian J. Kifiak" <bk_(_at_)_rt_(_dot_)_fm>
To: gnats_(_at_)_openbsd_(_dot_)_org
Cc:  Subject: Re: system/2091: New /usr/bin/nc (2.9-current), no std-in/out support
Date: 29 Sep 2001 05:06:25 -0000

 > The original /usr/bin/nc, as in OBSD 2.8, accepted standard
 > input and forwarded it to through the connection, and provided
 > output on stdout.  This is no longer the case as of 2.9 with the
 > re-written /usr/bin/nc.
 
 Your example indeed illustrates a problem, but it's not what you
 suggest here.
 
 The old netcat doesn't bail on EOF from STDIN.  The new netcat
 does.
 
 The fix appears to be to ignore EOF from STDIN, leaving termination
 (in non-error conditions) to an EOF from the network:
 
 Index: netcat.c
 ===================================================================
 RCS file: /cvs/src/usr.bin/nc/netcat.c,v
 retrieving revision 1.37
 diff -u -r1.37 netcat.c
 --- netcat.c	2001/09/02 19:11:46	1.37
 +++ netcat.c	2001/09/29 04:59:34
 @@ -471,7 +471,7 @@
  		}
  
  		if (pfd[1].revents & POLLIN) {
 -			if ((n = read(wfd, buf, sizeof(buf))) <= 0) {
 +			if ((n = read(wfd, buf, sizeof(buf))) < 0) {
  				return;
  			} else
  				if((ret = atomicio(write, nfd, buf, n)) != n)
 
 
 
 (Aside: Wow, this is a much nicer readwrite loop than the old
 version.)