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

丶灬走出姿态 提交于 2021-02-18 21:11:44

问题


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?


回答1:


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

The order within those categories seems to be the same that the OS uses (it uses the SIOCGIFCONF ioctl).

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




回答2:


This simply delegates to a native call, and no I'm not aware of any way to alter it.




回答3:


If you take a look at sources, then you see that getNetworkInterfaces just return enumeration, which backed with a NetworkInterface array, which is returned by getAll() method, which is native. So, it is implementation dependent and system dependent. You can't do anything with this.



来源:https://stackoverflow.com/questions/6055677/affect-the-order-of-networkinterface-getnetworkinterfaces-enumeration-in-java-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!