[BUG] linux tests fail with netcat-traditional
Describe the bug
A clear and concise description of what the bug is.
In case-10-ux-socket-state, case-20-inet-socket-endpoint and case-20-ux-socket-endpoint, nc is used to launch a server. Some Linux distributions use netcat-tranditional by default, which does not recognize the arguments.
To Reproduce Steps to reproduce the behavior:
- Run 'bash ./check.sh linux'
- See error
Expected behavior A clear and concise description of what you expected to happen.
It should not fail.
Program output If applicable, paste program output text here to help explain your problem.
case-10-ux-socket-state ... nc: invalid option -- 'U'
nc -h for help
case-20-inet-socket-endpoint ... nc: invalid option -- '4'
nc -h for help
nc: invalid option -- '4'
nc -h for help
case-20-ux-socket-endpoint ... nc: invalid option -- 'U'
nc -h for help
nc: invalid option -- 'U'
nc -h for help
TEST SUMMARY
=============================================================================
successful: 23
skipped: 2
failed: 3
3 of 28 cases are failed
Environment (please complete the following information):
- Kernel: Linux
- OS: Debian Bookworm
- lsof Version: 4.95.0
- Origin: built from git master
Additional context Add any other context about the problem here.
It seems that there are multiple implementations for nc command.
What I assumed was:
$ rpm -qf $(which nc)
nmap-ncat-7.92-1.fc36.x86_64
$ nc --help
Ncat 7.92 ( https://nmap.org/ncat )
Usage: ncat [options] [hostname] [port]
Options taking a time assume seconds. Append 'ms' for milliseconds,
's' for seconds, 'm' for minutes, or 'h' for hours (e.g. 500ms).
-4 Use IPv4 only
-6 Use IPv6 only
-U, --unixsock Use Unix domain sockets only
--vsock Use vsock sockets only
-C, --crlf Use CRLF for EOL sequence
...
There seem four implementations: GNU, stearns (a.k.a. netcat-traditional in Debian), nmap, and OpenBSD. GNU and stearns are not maintained for a long time and leak many functions. And since Debian 11, Debian will install netcat-openbsd when installing netcat. Before, it install netcat-traditional.
For testing lsof you may want to have a program opening various files (including socket) in various ways. Passing/receiving data is not interesting. Our interest is just fds.
When I started to develop lsfd, I found I had to have a tool just opening files in various ways for testing lsfd, instead of utilizing a tool like nc.
I wrote such a tool for lsfd. https://github.com/util-linux/util-linux/blob/master/tests/helpers/test_mkfds.c
mkfds has not supported any interest sockets yet because lsfd is not ready for sockets enough.