On 2013/03/19 18:26, Otto Moerbeek wrote: > On Tue, Mar 19, 2013 at 04:00:46PM +0100, Martin Pelikan wrote: > > > > wfd is stdin, so doing a shutdown on it will mostly be a noop, right? > > > > Of course you're right. I was so focused on finding the bug I didn't > > look above what the fd is :-( > > > > Are you okay with removing this particular shutdown(2) line? > > Yes, but it would even be better if there would be an option to get > the shutdown on EOF behaviour back. > > Some servers wait until they see the shutdown from the client to finish > their work. > > -Otto >
oops, missed usage() Index: nc.1 =================================================================== RCS file: /cvs/src/usr.bin/nc/nc.1,v retrieving revision 1.61 diff -u -p -r1.61 nc.1 --- nc.1 7 Jul 2012 15:33:02 -0000 1.61 +++ nc.1 19 Mar 2013 17:40:07 -0000 @@ -34,7 +34,7 @@ .Sh SYNOPSIS .Nm nc .Bk -words -.Op Fl 46DdhklnrStUuvz +.Op Fl 46DdhklNnrStUuvz .Op Fl I Ar length .Op Fl i Ar interval .Op Fl O Ar length @@ -137,6 +137,9 @@ options. Additionally, any timeouts specified with the .Fl w option are ignored. +.It Fl N +Shutdown the network socket after EOF on the input. +Some servers require this to finish their work. .It Fl n Do not do any DNS or service lookups on any specified addresses, hostnames or ports. Index: netcat.c =================================================================== RCS file: /cvs/src/usr.bin/nc/netcat.c,v retrieving revision 1.110 diff -u -p -r1.110 netcat.c --- netcat.c 12 Mar 2013 02:57:37 -0000 1.110 +++ netcat.c 19 Mar 2013 17:40:07 -0000 @@ -69,6 +69,7 @@ int dflag; /* detached, no stdin */ unsigned int iflag; /* Interval Flag */ int kflag; /* More than one connect */ int lflag; /* Bind to local port */ +int Nflag; /* shutdown() network socket */ int nflag; /* Don't do name look up */ char *Pflag; /* Proxy username */ char *pflag; /* Localport flag */ @@ -131,7 +132,7 @@ main(int argc, char *argv[]) sv = NULL; while ((ch = getopt(argc, argv, - "46DdhI:i:klnO:P:p:rSs:tT:UuV:vw:X:x:z")) != -1) { + "46DdhI:i:klNnO:P:p:rSs:tT:UuV:vw:X:x:z")) != -1) { switch (ch) { case '4': family = AF_INET; @@ -169,6 +170,9 @@ main(int argc, char *argv[]) case 'l': lflag = 1; break; + case 'N': + Nflag = 1; + break; case 'n': nflag = 1; break; @@ -771,7 +775,8 @@ readwrite(int nfd) if ((n = read(wfd, buf, plen)) < 0) return; else if (n == 0) { - shutdown(nfd, SHUT_WR); + if (Nflag) + shutdown(nfd, SHUT_WR); pfd[1].fd = -1; pfd[1].events = 0; } else { @@ -1014,6 +1019,7 @@ help(void) \t-i secs\t Delay interval for lines sent, ports scanned\n\ \t-k Keep inbound sockets open for multiple connects\n\ \t-l Listen mode, for inbound connects\n\ + \t-N Shutdown the network socket after EOF on stdin\n\ \t-n Suppress name/port resolutions\n\ \t-O length TCP send buffer length\n\ \t-P proxyuser\tUsername for proxy authentication\n\ @@ -1039,7 +1045,7 @@ void usage(int ret) { fprintf(stderr, - "usage: nc [-46DdhklnrStUuvz] [-I length] [-i interval] [-O length]\n" + "usage: nc [-46DdhklNnrStUuvz] [-I length] [-i interval] [-O length]\n" "\t [-P proxy_username] [-p source_port] [-s source] [-T ToS]\n" "\t [-V rtable] [-w timeout] [-X proxy_protocol]\n" "\t [-x proxy_address[:port]] [destination] [port]\n");