Socat listens for all IP addresses assigned to a specific network interface.

Does anyone know how I can get socatto listen to all the interfaces assigned to one particular network interface? I am not sure if this is possible.

If I want to bind socatto a specific IP:PORT, I always analyze the IP information from the output of the command ip, and then bind socatto it as follows:

NETIFC=$(ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
socat -d -d TCP4-LISTEN:1234,fork,bind=$(NETIFC) UNIX-CLIENT:/tmp/foo.sock

I thought I could achieve what I needed by running socatas follows:

socat -d -d TCP4-LISTEN:1234,fork,so-bindtodevice=eth0 UNIX-CLIENT:/tmp/foo.sock

But I believe that I do not have enough knowledge in the field of network programming at a low level and, therefore, I do not quite understand what exactly this option should do, and I just hope that it should do what I want, but really it actually binds to all network interfaces.

+4
source share