From 4e1ef7984f8cd9372c63770fd97e925a58dfb1de Mon Sep 17 00:00:00 2001 From: haesbaert <> Date: Sat, 7 Jul 2012 15:33:02 +0000 Subject: 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@ --- src/usr.bin/nc/nc.1 | 8 ++++++-- src/usr.bin/nc/netcat.c | 16 +++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) (limited to 'src/usr.bin/nc') 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 @@ -.\" $OpenBSD: nc.1,v 1.60 2012/02/07 12:11:43 lum Exp $ +.\" $OpenBSD: nc.1,v 1.61 2012/07/07 15:33:02 haesbaert 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 @@ -119,6 +119,10 @@ is completed. It is an error to use this option without the .Fl l option. +When used together with the +.Fl u +option, the server socket is not connected and it can receive UDP datagrams from +multiple hosts. .It Fl l Used to specify that .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 @@ -/* $OpenBSD: netcat.c,v 1.108 2012/07/07 09:36:30 haesbaert Exp $ */ +/* $OpenBSD: netcat.c,v 1.109 2012/07/07 15:33:02 haesbaert Exp $ */ /* * Copyright (c) 2001 Eric Jackson * @@ -345,11 +345,17 @@ main(int argc, char *argv[]) if (s < 0) err(1, NULL); /* - * For UDP, we will use recvfrom() initially - * to wait for a caller, then use the regular - * functions to talk to the caller. + * For UDP and -k, don't connect the socket, let it + * receive datagrams from multiple socket pairs. */ - if (uflag) { + if (uflag && kflag) + readwrite(s); + /* + * For UDP and not -k, we will use recvfrom() initially + * to wait for a caller, then use the regular functions + * to talk to the caller. + */ + else if (uflag && !kflag) { int rv, plen; char buf[16384]; struct sockaddr_storage z; -- cgit v1.2.3-55-g6feb