What is the order in which NetworkInterface.getNetworkInterfaces() returns an enumeration of network interfaces? Is there a way to affect that on JVM level or on Linux OS level?
What is the order in which NetworkInterface.getNetworkInterfaces() returns an enumeration of network interfaces? Is
Share
According to the source of the OpenJDK (found in
src/solaris/native/java/net/NetworkInterface.c, methodenumInterfaces) it will return IPv4 interfaces first (methodenumIPv4Interfaces), followed by IPv6 interfaces (methodenumIPv6Interfaces).The order within those categories seems to be the same that the OS uses (it uses the
SIOCGIFCONFioctl).Note that this is implementation dependent and not defined, so any implementation can very easily do it differently.