This method to try getting the local IP address seem to work correctly on linux and windows, even though for windows, the current method works just fine.
The way this code works depends on java's protected native void connect0(InetAddress address, int port) native C code java accessible through java.net.PlainDatagramSocketImpl.
The best way I was able to find to use such method is by making a datagram (UDP packet) and send it to nowhere reachable.
This method to try getting the local IP address seem to work correctly on linux and windows, even though for windows, the current method works just fine.
The way this code works depends on java's
protected native void connect0(InetAddress address, int port)
nativeC
code java accessible throughjava.net.PlainDatagramSocketImpl
. The best way I was able to find to use such method is by making a datagram (UDP packet) and send it to nowhere reachable.