On Sun, Jun 24, 2012 at 11:23:05PM +0200, Ariane van der Steldt wrote:
> On Mon, Jun 25, 2012 at 12:09:33AM +0300, dsp wrote:
> > We observe the following behaviour when running nc -ul.
> > The server begins on a recvfrom() and when data arrives it
> > connects() the socket.
> > When the client dies , the server remains in a connected state
> > therefore ignoring subsequent data arriving on the port.
> > Is this really the intended logic for a connectionless protocol like
> > UDP? We proceeded to comment out the connect statement and we were
> > able to receive data from multiple *sessions* as expected.
> > Can you shed some light on the matter???
>
> Reading the man page, I think you want to add the -k option to nc.
The -k option does nothing when used with -u because the readwrite()
session cannot end. Would the following be a reasonable change?
It has the side effect of letting UDP packets to interleave.
Index: nc.1
===================================================================
RCS file: /cvs/src/usr.bin/nc/nc.1,v
retrieving revision 1.60
diff -u -p -r1.60 nc.1
--- nc.1 7 Feb 2012 12:11:43 -0000 1.60
+++ nc.1 25 Jun 2012 10:40:15 -0000
@@ -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 all UDP datagrams arriving on the port are received;
+not just those sent by the first client to connect.
.It Fl l
Used to specify that
.Nm
Index: netcat.c
===================================================================
RCS file: /cvs/src/usr.bin/nc/netcat.c,v
retrieving revision 1.105
diff -u -p -r1.105 netcat.c
--- netcat.c 9 Feb 2012 06:25:35 -0000 1.105
+++ netcat.c 25 Jun 2012 10:40:15 -0000
@@ -364,9 +364,12 @@ main(int argc, char *argv[])
if (rv < 0)
err(1, "recvfrom");
- rv = connect(s, (struct sockaddr *)&z, len);
- if (rv < 0)
- err(1, "connect");
+ if (!kflag) {
+ rv = connect(s, (struct sockaddr *)&z,
+ len);
+ if (rv < 0)
+ err(1, "connect");
+ }
readwrite(s);
} else {