Subject: Re: Strange netcat behaviour on NetBSD 1.6.1
To: netbsd-users <>
From: Karim Belbachir <>
List: netbsd-users
Date: 12/13/2003 00:21:28
[On Server side]
> root@tigger /tmp # nc -v -p 10004 -l
[On client side]
> root@rabbit /tmp # cat tindny-09-Dec-2003.log | nc tigger 10004
> No problem so far ... until cat reaches the end of the file.
> The nc process on rabbit continues to read from stdin.
> I can see the last line of the file on the remote side
> but the connection wont be closed and the command line from
> the sender (rabbit) still remains "active".
> If I login to another system (not NetBSD) and try the
> cat ... | nc ... command everything works fine and
> the nc process terminates if cat is done with the file.
> Works fine on OpenBSD 3.4, FreeBSD 5.1 and Linux 2.4.22
> and 2.6.0-test11. The netcat version is the same on every
> system. It is v1.10 (nc -h says so) and the file I read
> via cat is a regular file.


I tried on Linux and NetBSD and got the same behaviour on both systems:
Netcat keeps listening as long as the process on the client side is not
killed. If I understand well the author's manual, netcat should end when
the network connection terminates and not when the standard input
closes. Use a timeout with the -w option if you want netcat to end on
both sides just after cat. :

"There are a lot of network services now that accept a small amount of
input and return a large amount of output, such as Gopher and Web
servers, which is the main reason netcat was written to "block" on the
network staying open rather than standard input.  Handling the timeout
this way gives uniform behavior with network servers that *don't* close
by themselves until told to."

Karim Belbachir