nc as client keeps sending after the server shutdown the socket:
$ </dev/null nc -Nl 5000 | sed s,^,srv:, &
[1] 90413 53862
$ nc localhost 5000
msg
srv:msg
tedu@ introduced this with r1.125 (three years ago), r1.124 works as
expected just like telnet does for that matter:
$ </dev/null nc -Nl 5000 &
[1] 22357
$ ./nc_old localhost 5000
$ jobs
[1] + Done nc -Nl 5000 < /dev/null
$ </dev/null nc -Nl 5000 &
[1] 9080
$ telnet localhost 5000 >/dev/null
Connection closed by foreign host.
[1] + Done nc -Nl 5000 < /dev/null
With the following diff nc will properly exit again as it used to.
Feedback?
diff --git a/usr.bin/nc/netcat.c b/usr.bin/nc/netcat.c
index f8bd8fa4988..bf65ba381e3 100644
--- a/usr.bin/nc/netcat.c
+++ b/usr.bin/nc/netcat.c
@@ -1074,6 +1074,9 @@ readwrite(int net_fd, struct tls *tls_ctx)
if (lflag && pfd[POLL_NETIN].fd == -1 &&
stdinbufpos == 0 && netinbufpos == 0)
return;
+ /* server shutdown socket, done */
+ if (pfd[POLL_NETIN].fd == -1 && pfd[POLL_STDOUT].fd == -1)
+ return;
/* help says -i is for "wait between lines sent". We read and
* write arbitrary amounts of data, and we don't want to start