summaryrefslogtreecommitdiff
path: root/usr.bin/nc
diff options
context:
space:
mode:
authorChristiano F. Haesbaert <haesbaert@cvs.openbsd.org>2012-07-07 15:33:03 +0000
committerChristiano F. Haesbaert <haesbaert@cvs.openbsd.org>2012-07-07 15:33:03 +0000
commita1dc706b28d0be9cddcb2d4d3611109f335467c5 (patch)
tree7e164e6e7d2a2a3ceb57633cab4b15b29f3bb6b4 /usr.bin/nc
parentc883ff0d8795f045f38189eab0f8275594faa39c (diff)
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@
Diffstat (limited to 'usr.bin/nc')
-rw-r--r--usr.bin/nc/nc.18
-rw-r--r--usr.bin/nc/netcat.c16
2 files changed, 17 insertions, 7 deletions
diff --git a/usr.bin/nc/nc.1 b/usr.bin/nc/nc.1
index 75d1437580a..232b6f5b6e1 100644
--- a/usr.bin/nc/nc.1
+++ b/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/usr.bin/nc/netcat.c b/usr.bin/nc/netcat.c
index 4bef71a7ca4..a034bbab8c0 100644
--- a/usr.bin/nc/netcat.c
+++ b/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 <ericj@monkey.org>
*
@@ -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;