Menu

#10 Missing the -k flag

open
nobody
None
3
2011-03-01
2009-08-31
No

The -k flag to nc (in recent versions) causes nc to continue listening after the client connects. In practice, this nc behavior is required for writing any generally useful daemon, as two clients trying to connect at once is not at all rare. When multiple clients connect, nc should service the first connection, then service the next connection as soon as the first connection closes, and so on.

Discussion

  • Giovanni Giacobbi

    Hi, i'm moving this to feature requests as GNU netcat actually aims to full compatibility with the original nc110.
    What version introduces this -k flag? I might consider supporting it, sounds useful.

     
  • Giovanni Giacobbi

    • labels: 429213 -->
    • milestone: 201867 -->
    • priority: 5 --> 3
     
  • David A. Gatwood

    Not exactly sure how long it has been around. It's in all the recent BSD versions (including Mac OS X, FreeBSD, etc.) and in recent Solaris versions as well, apparently.

    As an added note, the BSD behavior, at least in the OSes I've tried thus far, is a bit broken, in that it allows the connection to be terminated from either end, but doesn't require the shell script to acknowledge that the connection has been closed before attaching the next connection. This can result in data corruption if the remote end closes the connection prematurely because the next connection gets the remaining data from the previous connection followed by the data it should get. The fix, of course, is to handle a remote-end close by reading data from the shell and throwing it away until the shell sends an EOF.

    I have a patch for the Mac OS X port that fixes this, thus making it possible to write fairly robust daemons with the tool. However, it does result in a netcat tool that's not bug-for-bug compatible (assuming that's valuable...).

    You can see the hacked version of nc in action with a purely shell-based web server (with CGI support) by downloading the companion files tarball attached to:

    http://developer.apple.com/library/mac/#documentation/opensource/conceptual/shellscripting/StartingPoints/StartingPoints.html

    (Yes, I had too much free time one afternoon.)

     

Log in to post a comment.