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:
parent
4d8acfee52
commit
791bbda65d
10
nc.1
10
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
|
.\" Copyright (c) 1996 David Sacerdote
|
||||||
.\" All rights reserved.
|
.\" All rights reserved.
|
||||||
@ -25,7 +25,7 @@
|
|||||||
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.Dd $Mdocdate: February 7 2012 $
|
.Dd $Mdocdate: July 7 2012 $
|
||||||
.Dt NC 1
|
.Dt NC 1
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -34,7 +34,7 @@
|
|||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm nc
|
.Nm nc
|
||||||
.Bk -words
|
.Bk -words
|
||||||
.Op Fl 46DdhklnrStUuvz
|
.Op Fl 46DdhklNnrStUuvz
|
||||||
.Op Fl I Ar length
|
.Op Fl I Ar length
|
||||||
.Op Fl i Ar interval
|
.Op Fl i Ar interval
|
||||||
.Op Fl O Ar length
|
.Op Fl O Ar length
|
||||||
@ -137,6 +137,10 @@ options.
|
|||||||
Additionally, any timeouts specified with the
|
Additionally, any timeouts specified with the
|
||||||
.Fl w
|
.Fl w
|
||||||
option are ignored.
|
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
|
.It Fl n
|
||||||
Do not do any DNS or service lookups on any specified addresses,
|
Do not do any DNS or service lookups on any specified addresses,
|
||||||
hostnames or ports.
|
hostnames or ports.
|
||||||
|
17
netcat.c
17
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>
|
* Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
|
||||||
*
|
*
|
||||||
@ -69,6 +69,7 @@ int dflag; /* detached, no stdin */
|
|||||||
unsigned int iflag; /* Interval Flag */
|
unsigned int iflag; /* Interval Flag */
|
||||||
int kflag; /* More than one connect */
|
int kflag; /* More than one connect */
|
||||||
int lflag; /* Bind to local port */
|
int lflag; /* Bind to local port */
|
||||||
|
int Nflag; /* shutdown() network socket */
|
||||||
int nflag; /* Don't do name look up */
|
int nflag; /* Don't do name look up */
|
||||||
char *Pflag; /* Proxy username */
|
char *Pflag; /* Proxy username */
|
||||||
char *pflag; /* Localport flag */
|
char *pflag; /* Localport flag */
|
||||||
@ -131,7 +132,7 @@ main(int argc, char *argv[])
|
|||||||
sv = NULL;
|
sv = NULL;
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv,
|
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) {
|
switch (ch) {
|
||||||
case '4':
|
case '4':
|
||||||
family = AF_INET;
|
family = AF_INET;
|
||||||
@ -169,6 +170,9 @@ main(int argc, char *argv[])
|
|||||||
case 'l':
|
case 'l':
|
||||||
lflag = 1;
|
lflag = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'N':
|
||||||
|
Nflag = 1;
|
||||||
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
nflag = 1;
|
nflag = 1;
|
||||||
break;
|
break;
|
||||||
@ -379,9 +383,10 @@ main(int argc, char *argv[])
|
|||||||
len = sizeof(cliaddr);
|
len = sizeof(cliaddr);
|
||||||
connfd = accept(s, (struct sockaddr *)&cliaddr,
|
connfd = accept(s, (struct sockaddr *)&cliaddr,
|
||||||
&len);
|
&len);
|
||||||
if (connfd == -1)
|
if (connfd == -1) {
|
||||||
|
/* For now, all errnos are fatal */
|
||||||
err(1, "accept");
|
err(1, "accept");
|
||||||
|
}
|
||||||
if (vflag)
|
if (vflag)
|
||||||
report_connect((struct sockaddr *)&cliaddr, len);
|
report_connect((struct sockaddr *)&cliaddr, len);
|
||||||
|
|
||||||
@ -770,6 +775,7 @@ readwrite(int nfd)
|
|||||||
if ((n = read(wfd, buf, plen)) < 0)
|
if ((n = read(wfd, buf, plen)) < 0)
|
||||||
return;
|
return;
|
||||||
else if (n == 0) {
|
else if (n == 0) {
|
||||||
|
if (Nflag)
|
||||||
shutdown(nfd, SHUT_WR);
|
shutdown(nfd, SHUT_WR);
|
||||||
pfd[1].fd = -1;
|
pfd[1].fd = -1;
|
||||||
pfd[1].events = 0;
|
pfd[1].events = 0;
|
||||||
@ -1013,6 +1019,7 @@ help(void)
|
|||||||
\t-i secs\t Delay interval for lines sent, ports scanned\n\
|
\t-i secs\t Delay interval for lines sent, ports scanned\n\
|
||||||
\t-k Keep inbound sockets open for multiple connects\n\
|
\t-k Keep inbound sockets open for multiple connects\n\
|
||||||
\t-l Listen mode, for inbound 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-n Suppress name/port resolutions\n\
|
||||||
\t-O length TCP send buffer length\n\
|
\t-O length TCP send buffer length\n\
|
||||||
\t-P proxyuser\tUsername for proxy authentication\n\
|
\t-P proxyuser\tUsername for proxy authentication\n\
|
||||||
@ -1038,7 +1045,7 @@ void
|
|||||||
usage(int ret)
|
usage(int ret)
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
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 [-P proxy_username] [-p source_port] [-s source] [-T ToS]\n"
|
||||||
"\t [-V rtable] [-w timeout] [-X proxy_protocol]\n"
|
"\t [-V rtable] [-w timeout] [-X proxy_protocol]\n"
|
||||||
"\t [-x proxy_address[:port]] [destination] [port]\n");
|
"\t [-x proxy_address[:port]] [destination] [port]\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user