Currently, 'nc -l <port>' can only process one TCP connection to the
same port at a time, because it keeps the listening socket open during
communication, therefore preventing others to connect to the other
instances of 'nc' on the same port.
Attached patch moves close() call up to be right after accept and before
communication.
Yuri
diff -ru src/usr.bin/nc.orig/netcat.c src/usr.bin/nc/netcat.c
--- src/usr.bin/nc.orig/netcat.c 2014-12-01 18:03:54.000000000 -0800
+++ src/usr.bin/nc/netcat.c 2014-12-01 18:05:50.000000000 -0800
@@ -403,13 +403,14 @@
if (vflag)
report_connect((struct sockaddr *)&cliaddr, len);
+ if (family != AF_UNIX)
+ close(s);
+
readwrite(connfd);
close(connfd);
}
- if (family != AF_UNIX)
- close(s);
- else if (uflag) {
+ if (family == AF_UNIX && uflag) {
if (connect(s, NULL, 0) < 0)
err(1, "connect");
}