I want to know in advance what network interface will be used for a given IP address X
.
I could do that by browsing the result of java.net.NetworkInterface.getNetworkInterfaces()
and checking X
against the IP address and subnet mask of each InterfaceAddress
returned by getInterfaceAddresses()
, but it doesn’t seem like a lot of fun and I could end up with a different result from the one chosen by the IP stack if several choices are valid.
Why do I need that?
I need to know the IP address which can be used to reach me from the peer having the IP address X
.