FYI I just refactored and simplified the option/argument verification logic. Here are examples of command invocations with 0, 1, or 2 non-optional arguments.
Listening on AF_UNIX socket /tmp/sock (nc.openbsd <1.187-1 supports only the second invocation). $ strace -e trace=bind nc -U -l -s /tmp/sock bind(3, {sa_family=AF_UNIX, sun_path="/tmp/sock"}, 110) = 0 $ strace -e trace=bind nc -U -l /tmp/sock bind(3, {sa_family=AF_UNIX, sun_path="/tmp/sock"}, 110) = 0 Listening on AF_INET socket 127.0.0.1:12345 (nc.traditional 1.10-41.1 supports only the first invocation, and nc.openbsd <1.187-1 supports only the second one). $ strace -e trace=bind nc -l -s 127.0.0.1 -p 12345 bind(3, {sa_family=AF_INET, sin_port=htons(12345), sin_addr=inet_addr("127.0.0.1")}, 16) = 0 $ strace -e trace=bind nc -l 127.0.0.1 12345 bind(3, {sa_family=AF_INET, sin_port=htons(12345), sin_addr=inet_addr("127.0.0.1")}, 16) = 0 Listening on AF_INET socket ADDR_ANY:12345 (nc.traditional 1.10-41.1 supports only the first invocation, and nc.openbsd <1.187-1 supports only the second one). $ strace -e trace=bind nc -l -p 12345 bind(3, {sa_family=AF_INET, sin_port=htons(12345), sin_addr=inet_addr("0.0.0.0")}, 16) = 0 $ strace -e trace=bind nc -l 12345 bind(3, {sa_family=AF_INET, sin_port=htons(12345), sin_addr=inet_addr("0.0.0.0")}, 16) = 0 Connecting to AF_UNIX socket /tmp/sock $ strace -e trace=socket,bind,connect nc -NU /tmp/sock </dev/null socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0) = 3 connect(3, {sa_family=AF_UNIX, sun_path="/tmp/sock"}, 110) = 0 Connecting to AF_INET socket 127.0.0.1:12345 $ strace -e trace=socket,bind,connect nc -N4 127.0.0.1 12345 </dev/null socket(AF_INET, SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 3 connect(3, {sa_family=AF_INET, sin_port=htons(12345), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EINPROGRESS (Operation now in progress) Connecting to AF_INET socket 127.0.0.1:12345 with a specific source address, source port, or both (broken since 1.187-1 and reported in #897020): $ strace -e trace=socket,bind,connect nc -N4 -s 127.1.2.3 127.0.0.1 12345 </dev/null socket(AF_INET, SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 3 bind(3, {sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("127.1.2.3")}, 16) = 0 connect(3, {sa_family=AF_INET, sin_port=htons(12345), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EINPROGRESS (Operation now in progress) $ strace -e trace=socket,bind,connect nc -N4 -p 54321 127.0.0.1 12345 </dev/null socket(AF_INET, SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 3 bind(3, {sa_family=AF_INET, sin_port=htons(54321), sin_addr=inet_addr("0.0.0.0")}, 16) = 0 connect(3, {sa_family=AF_INET, sin_port=htons(12345), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EINPROGRESS (Operation now in progress) $ strace -e trace=socket,bind,connect nc -N4 -s 127.1.2.3 -p 54321 127.0.0.1 12345 </dev/null socket(AF_INET, SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 3 bind(3, {sa_family=AF_INET, sin_port=htons(54321), sin_addr=inet_addr("127.1.2.3")}, 16) = 0 connect(3, {sa_family=AF_INET, sin_port=htons(12345), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EINPROGRESS (Operation now in progress) -- Guilhem.
signature.asc
Description: PGP signature