Nmap Development mailing list archives

Re: [PATCH] [Ncat] Fix EOF handling


From: Daniel Roethlisberger <daniel () roe ch>
Date: Sun, 19 Apr 2009 14:34:21 +0200

bensonk () acm wwu edu <bensonk () acm wwu edu> 2009-04-18:
The standard netcat behavior as defined by the canonical
implementation by hobbit explicitly does not halt on EOF.
I would recommend reversing the option, and instead providing
an option like "-q N" in gentoo's netcat.  The "-q N" option
means "after EOF, exit after N seconds". 

I think that, in general, usefulness should supercede history.

I fail to see a use case for keeping running after EOF on the
client side.  If I want Ncat to keep receiving data, I just make
sure not to close Ncat's stdin.  By closing Ncat's stdin (^D on a
tty or close() on the fd in a shell pipe) I signal Ncat that I'm
done.  This is the Unix way of handling standard input/output,
and is what I expect from command line utilities to adhere to, in
order to be useful in constructing larger command pipes.

Do you have a use case that is better served by a -q timer than
proper EOF handling?

On the server side, there is a usefulness to keep running (i.e.
accept more connections); what should be the default is probably
a matter of taste (or typical type of workload).  Personally, I
find it more natural to exit after one connection by default.

On Sat, Apr 18, 2009 at 08:10:23PM +0200, Daniel Roethlisberger wrote:
Ncat currently doesn't handle EOF events in a very intuitive way.
Usability for scripting mainly depends on the ability to pipe
into and out of Ncat:

me@server $ ncat -l 1234 | tar xvf -
me@client $ tar cvf - somedir | ncat server 1234

Currently, this does not work as expected, neither in the client
nor in the server.

In connect mode, EOF on standard input does not cause Ncat to
exit.  `cat file | ncat somewhere 1234' will keep running forever
until Ncat receives a SIGINT.  To be suitable for scripting, Ncat
must exit after EOF on stdin.

In listen mode, closing the TCP connection on the client side
does not cause Ncat to flush stdout and exit, because Ncat is
waiting for other connections.  SIGINT does not help here,
because Ncat will not write the remaining buffered bytes to
stdout in that case, so a received file will have some missing
bytes at the end.

Cince this behaviour can be considered a feature, the attached
patch adds a `-k' option, modelled after the *BSD nc(1) option of
the same name.  `-l -k' gives current behaviour, while just `-l'
gives the expected, scriptable single-shot behaviour which is
default for all netcat variants I am aware of (which is why I'd
propose to make it the default).

The attached patches fix EOF handling in both connect and listen
mode as I'd expect Ncat to handle EOF.  Comments?

-- 
Daniel Roethlisberger
http://daniel.roe.ch/

_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://SecLists.Org


Current thread: