diff options
author | sthen <> | 2013-03-20 09:27:56 +0000 |
---|---|---|
committer | sthen <> | 2013-03-20 09:27:56 +0000 |
commit | 5fde2c71362f5a21bf158abc2b2e73674095d596 (patch) | |
tree | 8a3411bc0e5ca0935ae3599f2059c0d90cd65e21 /src | |
parent | 29262687e14b26418671088467d4b032efc4eba5 (diff) | |
download | openbsd-5fde2c71362f5a21bf158abc2b2e73674095d596.tar.gz openbsd-5fde2c71362f5a21bf158abc2b2e73674095d596.tar.bz2 openbsd-5fde2c71362f5a21bf158abc2b2e73674095d596.zip |
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@
Diffstat (limited to 'src')
-rw-r--r-- | src/usr.bin/nc/nc.1 | 10 | ||||
-rw-r--r-- | src/usr.bin/nc/netcat.c | 14 |
2 files changed, 17 insertions, 7 deletions
diff --git a/src/usr.bin/nc/nc.1 b/src/usr.bin/nc/nc.1 index 232b6f5b6e..6fdb56e7e3 100644 --- a/src/usr.bin/nc/nc.1 +++ b/src/usr.bin/nc/nc.1 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $OpenBSD: nc.1,v 1.61 2012/07/07 15:33:02 haesbaert Exp $ | 1 | .\" $OpenBSD: nc.1,v 1.62 2013/03/20 09:27:56 sthen Exp $ |
2 | .\" | 2 | .\" |
3 | .\" Copyright (c) 1996 David Sacerdote | 3 | .\" Copyright (c) 1996 David Sacerdote |
4 | .\" All rights reserved. | 4 | .\" All rights reserved. |
@@ -25,7 +25,7 @@ | |||
25 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 | .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | .\" | 27 | .\" |
28 | .Dd $Mdocdate: July 7 2012 $ | 28 | .Dd $Mdocdate: March 20 2013 $ |
29 | .Dt NC 1 | 29 | .Dt NC 1 |
30 | .Os | 30 | .Os |
31 | .Sh NAME | 31 | .Sh NAME |
@@ -34,7 +34,7 @@ | |||
34 | .Sh SYNOPSIS | 34 | .Sh SYNOPSIS |
35 | .Nm nc | 35 | .Nm nc |
36 | .Bk -words | 36 | .Bk -words |
37 | .Op Fl 46DdhklnrStUuvz | 37 | .Op Fl 46DdhklNnrStUuvz |
38 | .Op Fl I Ar length | 38 | .Op Fl I Ar length |
39 | .Op Fl i Ar interval | 39 | .Op Fl i Ar interval |
40 | .Op Fl O Ar length | 40 | .Op Fl O Ar length |
@@ -137,6 +137,10 @@ options. | |||
137 | Additionally, any timeouts specified with the | 137 | Additionally, any timeouts specified with the |
138 | .Fl w | 138 | .Fl w |
139 | option are ignored. | 139 | option are ignored. |
140 | .It Fl N | ||
141 | .Xr shutdown 2 | ||
142 | the network socket after EOF on the input. | ||
143 | Some servers require this to finish their work. | ||
140 | .It Fl n | 144 | .It Fl n |
141 | Do not do any DNS or service lookups on any specified addresses, | 145 | Do not do any DNS or service lookups on any specified addresses, |
142 | hostnames or ports. | 146 | hostnames or ports. |
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c index 93338dac37..33246d7a74 100644 --- a/src/usr.bin/nc/netcat.c +++ b/src/usr.bin/nc/netcat.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: netcat.c,v 1.110 2013/03/12 02:57:37 deraadt Exp $ */ | 1 | /* $OpenBSD: netcat.c,v 1.111 2013/03/20 09:27:56 sthen Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> | 3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> |
4 | * | 4 | * |
@@ -69,6 +69,7 @@ int dflag; /* detached, no stdin */ | |||
69 | unsigned int iflag; /* Interval Flag */ | 69 | unsigned int iflag; /* Interval Flag */ |
70 | int kflag; /* More than one connect */ | 70 | int kflag; /* More than one connect */ |
71 | int lflag; /* Bind to local port */ | 71 | int lflag; /* Bind to local port */ |
72 | int Nflag; /* shutdown() network socket */ | ||
72 | int nflag; /* Don't do name look up */ | 73 | int nflag; /* Don't do name look up */ |
73 | char *Pflag; /* Proxy username */ | 74 | char *Pflag; /* Proxy username */ |
74 | char *pflag; /* Localport flag */ | 75 | char *pflag; /* Localport flag */ |
@@ -131,7 +132,7 @@ main(int argc, char *argv[]) | |||
131 | sv = NULL; | 132 | sv = NULL; |
132 | 133 | ||
133 | while ((ch = getopt(argc, argv, | 134 | while ((ch = getopt(argc, argv, |
134 | "46DdhI:i:klnO:P:p:rSs:tT:UuV:vw:X:x:z")) != -1) { | 135 | "46DdhI:i:klNnO:P:p:rSs:tT:UuV:vw:X:x:z")) != -1) { |
135 | switch (ch) { | 136 | switch (ch) { |
136 | case '4': | 137 | case '4': |
137 | family = AF_INET; | 138 | family = AF_INET; |
@@ -169,6 +170,9 @@ main(int argc, char *argv[]) | |||
169 | case 'l': | 170 | case 'l': |
170 | lflag = 1; | 171 | lflag = 1; |
171 | break; | 172 | break; |
173 | case 'N': | ||
174 | Nflag = 1; | ||
175 | break; | ||
172 | case 'n': | 176 | case 'n': |
173 | nflag = 1; | 177 | nflag = 1; |
174 | break; | 178 | break; |
@@ -771,7 +775,8 @@ readwrite(int nfd) | |||
771 | if ((n = read(wfd, buf, plen)) < 0) | 775 | if ((n = read(wfd, buf, plen)) < 0) |
772 | return; | 776 | return; |
773 | else if (n == 0) { | 777 | else if (n == 0) { |
774 | shutdown(nfd, SHUT_WR); | 778 | if (Nflag) |
779 | shutdown(nfd, SHUT_WR); | ||
775 | pfd[1].fd = -1; | 780 | pfd[1].fd = -1; |
776 | pfd[1].events = 0; | 781 | pfd[1].events = 0; |
777 | } else { | 782 | } else { |
@@ -1014,6 +1019,7 @@ help(void) | |||
1014 | \t-i secs\t Delay interval for lines sent, ports scanned\n\ | 1019 | \t-i secs\t Delay interval for lines sent, ports scanned\n\ |
1015 | \t-k Keep inbound sockets open for multiple connects\n\ | 1020 | \t-k Keep inbound sockets open for multiple connects\n\ |
1016 | \t-l Listen mode, for inbound connects\n\ | 1021 | \t-l Listen mode, for inbound connects\n\ |
1022 | \t-N Shutdown the network socket after EOF on stdin\n\ | ||
1017 | \t-n Suppress name/port resolutions\n\ | 1023 | \t-n Suppress name/port resolutions\n\ |
1018 | \t-O length TCP send buffer length\n\ | 1024 | \t-O length TCP send buffer length\n\ |
1019 | \t-P proxyuser\tUsername for proxy authentication\n\ | 1025 | \t-P proxyuser\tUsername for proxy authentication\n\ |
@@ -1039,7 +1045,7 @@ void | |||
1039 | usage(int ret) | 1045 | usage(int ret) |
1040 | { | 1046 | { |
1041 | fprintf(stderr, | 1047 | fprintf(stderr, |
1042 | "usage: nc [-46DdhklnrStUuvz] [-I length] [-i interval] [-O length]\n" | 1048 | "usage: nc [-46DdhklNnrStUuvz] [-I length] [-i interval] [-O length]\n" |
1043 | "\t [-P proxy_username] [-p source_port] [-s source] [-T ToS]\n" | 1049 | "\t [-P proxy_username] [-p source_port] [-s source] [-T ToS]\n" |
1044 | "\t [-V rtable] [-w timeout] [-X proxy_protocol]\n" | 1050 | "\t [-V rtable] [-w timeout] [-X proxy_protocol]\n" |
1045 | "\t [-x proxy_address[:port]] [destination] [port]\n"); | 1051 | "\t [-x proxy_address[:port]] [destination] [port]\n"); |