diff options
author | haesbaert <> | 2012-07-07 15:33:02 +0000 |
---|---|---|
committer | haesbaert <> | 2012-07-07 15:33:02 +0000 |
commit | 995c38cd464be88005853d62d9c8ac2d96f6dfe1 (patch) | |
tree | 9783115d4fc4eeb94c551ef60f301694559dcb99 | |
parent | 335848c28f31358ed46e5bf33f2fe93200fa4672 (diff) | |
download | openbsd-995c38cd464be88005853d62d9c8ac2d96f6dfe1.tar.gz openbsd-995c38cd464be88005853d62d9c8ac2d96f6dfe1.tar.bz2 openbsd-995c38cd464be88005853d62d9c8ac2d96f6dfe1.zip |
Allow UDP server to receive datagrams from multiple socket pairs with -k
flag. Prompted by a question from dsp at 2f30 dot org, diff from Lazarom
Koromil with a few tweaks by me, many thanks.
ok mikeb@ nicm@ haesbaert@
-rw-r--r-- | src/usr.bin/nc/nc.1 | 8 | ||||
-rw-r--r-- | src/usr.bin/nc/netcat.c | 16 |
2 files changed, 17 insertions, 7 deletions
diff --git a/src/usr.bin/nc/nc.1 b/src/usr.bin/nc/nc.1 index 75d1437580..232b6f5b6e 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.60 2012/02/07 12:11:43 lum Exp $ | 1 | .\" $OpenBSD: nc.1,v 1.61 2012/07/07 15:33:02 haesbaert 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: February 7 2012 $ | 28 | .Dd $Mdocdate: July 7 2012 $ |
29 | .Dt NC 1 | 29 | .Dt NC 1 |
30 | .Os | 30 | .Os |
31 | .Sh NAME | 31 | .Sh NAME |
@@ -119,6 +119,10 @@ is completed. | |||
119 | It is an error to use this option without the | 119 | It is an error to use this option without the |
120 | .Fl l | 120 | .Fl l |
121 | option. | 121 | option. |
122 | When used together with the | ||
123 | .Fl u | ||
124 | option, the server socket is not connected and it can receive UDP datagrams from | ||
125 | multiple hosts. | ||
122 | .It Fl l | 126 | .It Fl l |
123 | Used to specify that | 127 | Used to specify that |
124 | .Nm | 128 | .Nm |
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c index 4bef71a7ca..a034bbab8c 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.108 2012/07/07 09:36:30 haesbaert Exp $ */ | 1 | /* $OpenBSD: netcat.c,v 1.109 2012/07/07 15:33:02 haesbaert Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> | 3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> |
4 | * | 4 | * |
@@ -345,11 +345,17 @@ main(int argc, char *argv[]) | |||
345 | if (s < 0) | 345 | if (s < 0) |
346 | err(1, NULL); | 346 | err(1, NULL); |
347 | /* | 347 | /* |
348 | * For UDP, we will use recvfrom() initially | 348 | * For UDP and -k, don't connect the socket, let it |
349 | * to wait for a caller, then use the regular | 349 | * receive datagrams from multiple socket pairs. |
350 | * functions to talk to the caller. | ||
351 | */ | 350 | */ |
352 | if (uflag) { | 351 | if (uflag && kflag) |
352 | readwrite(s); | ||
353 | /* | ||
354 | * For UDP and not -k, we will use recvfrom() initially | ||
355 | * to wait for a caller, then use the regular functions | ||
356 | * to talk to the caller. | ||
357 | */ | ||
358 | else if (uflag && !kflag) { | ||
353 | int rv, plen; | 359 | int rv, plen; |
354 | char buf[16384]; | 360 | char buf[16384]; |
355 | struct sockaddr_storage z; | 361 | struct sockaddr_storage z; |