Netcat: using nc -l port_number instead of nc -l -p port_number

后端 未结 2 796
北海茫月
北海茫月 2021-01-13 11:04

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_nu

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-13 11:41

    Do not adjust your set. There are multiple implementations of netcat out there; not all of them behave the same.

    In particular, the "traditional" version of netcat, which is probably what you have installed on your Debian system, will end up doing something totally unexpected if you omit the -p ("port") flag: it will end up treating the last argument as a hostname, pass it to inet_aton(), which will convert it to a nonsensical IP address (e.g, 1234 will become 0.0.4.210), and will then proceed to ignore that IP address and listen on a socket with an automatically assigned (probably random) port number.

    This behavior is obviously silly, so some other implementations of netcat will assume you meant -p. The one you're using doesn't, though, so pass the -p option.

提交回复
热议问题