Here's simple case when binding to all ip interfaces and specific udp port:
int bindPort = 5555; // example, udp port number
DatagramSocket socket = new DatagramSocket(bindPort);
byte[] receiveData = new byte[1500];
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
...
socket.receive(receivePacket);
How do I know on which ip interface I received packet ?
I can see there is getSocketAddress():
Gets the SocketAddress (usually IP address + port number) of the remote host that this packet is being sent to or is coming from.
but that returns remote ip+port. I would like to know local ip (local port is 5555 in this example).
Is it possible with std. Java libraries ?
InetAddress IP=InetAddress.getLocalHost();
System.out.println("IP of my system is := "+IP.getHostAddress());
Stolen from https://mcmap.net/q/11202/-getting-the-ip-address-of-the-current-machine-using-java – Cassaundracassava