Ip Aliasing allows us to associate more than one ip address to the same interface. My question is how can one bind and hence receive the data from all of the addresses associated to an interface? Is there some option like INADDR_ANY available for the purpose?
Share
Always remember that bind(2) does not bind to interfaces, but addresses.
Each socket generally only stores exactly one binding, even if that is 0.0.0.0 port 0. It is just that 0.0.0.0, :: and port 0 are taken as wildcards when checking incoming requests. As such, you will need one socket for non-wildcard addresses.
See setsockopt SO_BINDTODEVICE if you really need interface binding, but that is in general not the right thing to do in programs other than e.g. tcpdump, as it will inhibit contacting over different interfaces even if they allow reception. For example, if your own host has 192.168.0.1 as an address on a private LAN, binding to eth1 will make it impossible to connect to 192.168.0.1 from .0.1 itself over lo. Hence, device binding is usually undesired.