Affect the listing order of NetworkInterface.getNetworkInterfaces in Java 6 on Linux

What is the order in which NetworkInterface.getNetworkInterfaces() returns an enumeration of network interfaces? Is there a way to influence the JVM level or the Linux OS level?

+8
java linux networking
source share
3 answers

According to the OpenJDK source (found in src/solaris/native/java/net/NetworkInterface.c , src/solaris/native/java/net/NetworkInterface.c method), it will return IPv4 interfaces ( enumIPv4Interfaces method) first, and then IPv6 interfaces ( enumIPv6Interfaces method).

The order in these categories seems to be the same as that used by the OS (it uses SIOCGIFCONF ioctl).

Please note that this is implementation dependent and not , so any implementation can very easily do it differently.

+5
source share

It just delegates its own call, and I don't know how to change it.

+1
source share

If you look at the sources, you will see that getNetworkInterfaces simply returns an enumeration that is supported by the NetworkInterface array, which is returned by the getAll () method, which is native. Thus, it is implementation dependent and system dependent. You can't do anything about it.

+1
source share

All Articles