summaryrefslogtreecommitdiffstats
path: root/contrib/netcat
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2013-04-15 05:31:59 +0000
committerdelphij <delphij@FreeBSD.org>2013-04-15 05:31:59 +0000
commitf60aecd8cceb20af13105c4a025a7e923e2c5602 (patch)
tree4889102881d3a86c1ff9838137312a2039176cea /contrib/netcat
parent096e09138648568e0e471b4b613c96060a268e19 (diff)
downloadFreeBSD-src-f60aecd8cceb20af13105c4a025a7e923e2c5602.zip
FreeBSD-src-f60aecd8cceb20af13105c4a025a7e923e2c5602.tar.gz
MFV r249496,249498. The most visible change is that we no longer shuts
down the connection when stdin closes, by default. This matches Hobbit's original netcat and GNU netcat. Old behavior can be restored with the new -N flag. MFC after: 2 weeks
Diffstat (limited to 'contrib/netcat')
-rw-r--r--contrib/netcat/atomicio.c4
-rw-r--r--contrib/netcat/nc.110
-rw-r--r--contrib/netcat/netcat.c23
3 files changed, 23 insertions, 14 deletions
diff --git a/contrib/netcat/atomicio.c b/contrib/netcat/atomicio.c
index feb6f19..344ac63 100644
--- a/contrib/netcat/atomicio.c
+++ b/contrib/netcat/atomicio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: atomicio.c,v 1.10 2011/01/08 00:47:19 jeremy Exp $ */
+/* $OpenBSD: atomicio.c,v 1.11 2012/12/04 02:24:47 deraadt Exp $ */
/*
* Copyright (c) 2006 Damien Miller. All rights reserved.
* Copyright (c) 2005 Anil Madhavapeddy. All rights reserved.
@@ -26,8 +26,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/param.h>
-
#include <errno.h>
#include <poll.h>
#include <unistd.h>
diff --git a/contrib/netcat/nc.1 b/contrib/netcat/nc.1
index 62eca47..e62cdea 100644
--- a/contrib/netcat/nc.1
+++ b/contrib/netcat/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.
@@ -27,7 +27,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd February 7, 2012
+.Dd July 7, 2012
.Dt NC 1
.Os
.Sh NAME
@@ -36,7 +36,7 @@
.Sh SYNOPSIS
.Nm nc
.Bk -words
-.Op Fl 46DdEhklnrStUuvz
+.Op Fl 46DdEhklNnrStUuvz
.Op Fl e Ar IPsec_policy
.Op Fl I Ar length
.Op Fl i Ar interval
@@ -155,6 +155,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/contrib/netcat/netcat.c b/contrib/netcat/netcat.c
index a062162..71454af 100644
--- a/contrib/netcat/netcat.c
+++ b/contrib/netcat/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>
*
@@ -77,6 +77,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 */
int FreeBSD_Oflag; /* Do not use TCP options */
char *Pflag; /* Proxy username */
@@ -153,7 +154,7 @@ main(int argc, char *argv[])
sv = NULL;
while ((ch = getopt_long(argc, argv,
- "46DdEe:hI:i:klnoO:P:p:rSs:tT:UuV:vw:X:x:z",
+ "46DdEe:hI:i:klNnoO:P:p:rSs:tT:UuV:vw:X:x:z",
longopts, NULL)) != -1) {
switch (ch) {
case '4':
@@ -207,6 +208,9 @@ main(int argc, char *argv[])
case 'l':
lflag = 1;
break;
+ case 'N':
+ Nflag = 1;
+ break;
case 'n':
nflag = 1;
break;
@@ -424,9 +428,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);
@@ -833,7 +838,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 {
@@ -1087,6 +1093,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--no-tcpopt Disable TCP options\n\
\t-O length TCP send buffer length\n\
@@ -1139,9 +1146,9 @@ usage(int ret)
{
fprintf(stderr,
#ifdef IPSEC
- "usage: nc [-46DdEhklnrStUuvz] [-e policy] [-I length] [-i interval] [-O length]\n"
+ "usage: nc [-46DdEhklNnrStUuvz] [-e policy] [-I length] [-i interval] [-O length]\n"
#else
- "usage: nc [-46DdhklnrStUuvz] [-I length] [-i interval] [-O length]\n"
+ "usage: nc [-46DdhklNnrStUuvz] [-I length] [-i interval] [-O length]\n"
#endif
"\t [-P proxy_username] [-p source_port] [-s source] [-T ToS]\n"
"\t [-V rtable] [-w timeout] [-X proxy_protocol]\n"
OpenPOWER on IntegriCloud