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@
This commit is contained in:
Xin LI 2013-04-15 05:24:43 +00:00
parent 4d8acfee52
commit 791bbda65d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/vendor/netcat/dist/; revision=249498
2 changed files with 21 additions and 10 deletions

10
nc.1
View File

@ -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.

View File

@ -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");