summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStuart Henderson <sthen@cvs.openbsd.org>2013-03-20 09:27:57 +0000
committerStuart Henderson <sthen@cvs.openbsd.org>2013-03-20 09:27:57 +0000
commit3ab723c5b4108351c6e97f06d1d555a7385856d4 (patch)
tree7f52ad0edf5e1f30d8248d23f4a8d7be7f91659b
parentf5bcc3a91721ccfe21cad4ba24aa64e686a8a7fc (diff)
Don't shutdown nc(1)'s network socket when stdin closes. Matches *Hobbit*'s
original netcat and GNU netcat; revert to old behaviour with the new -N flag if needed. After much discussion with otto deraadt tedu and Martin Pelikan. ok deraadt@
-rw-r--r--usr.bin/nc/nc.110
-rw-r--r--usr.bin/nc/netcat.c14
2 files changed, 17 insertions, 7 deletions
diff --git a/usr.bin/nc/nc.1 b/usr.bin/nc/nc.1
index 232b6f5b6e1..6fdb56e7e3e 100644
--- a/usr.bin/nc/nc.1
+++ b/usr.bin/nc/nc.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: nc.1,v 1.61 2012/07/07 15:33:02 haesbaert Exp $
+.\" $OpenBSD: nc.1,v 1.62 2013/03/20 09:27:56 sthen Exp $
.\"
.\" Copyright (c) 1996 David Sacerdote
.\" All rights reserved.
@@ -25,7 +25,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd $Mdocdate: July 7 2012 $
+.Dd $Mdocdate: March 20 2013 $
.Dt NC 1
.Os
.Sh NAME
@@ -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,10 @@ options.
Additionally, any timeouts specified with the
.Fl w
option are ignored.
+.It Fl N
+.Xr shutdown 2
+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.
diff --git a/usr.bin/nc/netcat.c b/usr.bin/nc/netcat.c
index 93338dac375..33246d7a747 100644
--- a/usr.bin/nc/netcat.c
+++ b/usr.bin/nc/netcat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: netcat.c,v 1.110 2013/03/12 02:57:37 deraadt Exp $ */
+/* $OpenBSD: netcat.c,v 1.111 2013/03/20 09:27:56 sthen Exp $ */
/*
* Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
*
@@ -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");