在Linux上的Java 6中影响NetworkInterface.getNetworkInterfaces枚举的顺序 [英] Affect the order of NetworkInterface.getNetworkInterfaces enumeration in Java 6 on Linux
问题描述
NetworkInterface.getNetworkInterfaces()
返回网络接口枚举的顺序是什么?有没有办法在JVM级别或Linux OS级别上影响它?
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?
推荐答案
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
).
这些类别中的顺序似乎与操作系统使用的顺序相同(它使用 SIOCGIFCONF
ioctl).
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.
这篇关于在Linux上的Java 6中影响NetworkInterface.getNetworkInterfaces枚举的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!