aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXin LI <delphij@FreeBSD.org>2013-04-15 05:24:43 +0000
committerXin LI <delphij@FreeBSD.org>2013-04-15 05:24:43 +0000
commit791bbda65d1e5e5968dd1c698ecbce06cb971d9a (patch)
tree28e6eea4854f5fa275e06170ec4881cd24aea493
parent4d8acfee5239a5eaf051345eb3f23b6188df11a0 (diff)
downloadsrc-791bbda65d1e5e5968dd1c698ecbce06cb971d9a.tar.gz
src-791bbda65d1e5e5968dd1c698ecbce06cb971d9a.zip
Integrate two OpenBSD commits to nc(1):
date: 2013/03/12 02:57:37; author: deraadt; All accept() errors are considered fatal, until someone gives a different reason. No code changed, just documenting it... date: 2013/03/20 09:27:56; author: sthen; 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@
Notes
Notes: svn path=/vendor/netcat/dist/; revision=249498
-rw-r--r--nc.110
-rw-r--r--netcat.c21
2 files changed, 21 insertions, 10 deletions
diff --git a/nc.1 b/nc.1
index 9df7f7f2f17a..4f68a321b6d7 100644
--- a/nc.1
+++ b/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: February 7 2012 $
+.Dd $Mdocdate: July 7 2012 $
.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/netcat.c b/netcat.c
index a034bbab8c03..33246d7a747a 100644
--- a/netcat.c
+++ b/netcat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: netcat.c,v 1.109 2012/07/07 15:33:02 haesbaert 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;
@@ -379,9 +383,10 @@ main(int argc, char *argv[])
len = sizeof(cliaddr);
connfd = accept(s, (struct sockaddr *)&cliaddr,
&len);
- if (connfd == -1)
- err(1, "accept");
-
+ if (connfd == -1) {
+ /* For now, all errnos are fatal */
+ err(1, "accept");
+ }
if (vflag)
report_connect((struct sockaddr *)&cliaddr, len);
@@ -770,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 {
@@ -1013,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\
@@ -1038,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");