Netcat: using nc -l port_number instead of nc -l -p port_number
debian, netcat, sockets, unix
Solution
I agree with duskwuff that it is better to just use the `-p` option everywhere, but to answer your question:
The one thing you have to do is install a netcat that supports the syntax you want. I know the `netcat-openbsd` package supports it. I know the `netcat-traditional` package does not. There's also a `netcat6` package, which also doesn't. You can then explicitly request the OpenBSD version of netcat like so:
nc.openbsd -l 4242
Optionally you may use the alternatives system to set this version of netcat to run when you issue the `nc` command:
update-alternatives --set nc /bin/nc.openbsd
This will be done automatically for you if this is the only netcat you've installed.
Finally, you may, again optionally, remove the netcat you don't like (`netcat-traditional` or `netcat6`).
Problem
This question is following this one: Sockets working in openSUSE do not work in Debian? When working with sockets on my Debian system, I have to use nc -l -p port_number to simulate the server I want to talk with. If I'm using nc -l port_number, it will fail when using the socket connect function and strerror(errno) will say "Connection refused". Netcat without -p option is working great on other Linux distributions, what should I change on my configuration?