影响 Linux 上 Java 6 中 NetworkInterface.getNetworkInterfaces 枚举的顺序

发布于 2024-11-08 05:47:18 字数 107 浏览 8 评论 0原文

NetworkInterface.getNetworkInterfaces() 返回网络接口枚举的顺序是什么?有没有办法在 JVM 级别或 Linux 操作系统级别上影响它?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我是有多爱你 2024-11-15 05:47:18

根据OpenJDK的来源(位于src/solaris/native/java/net/NetworkInterface.c,方法enumInterfaces)它将首先返回 IPv4 接口(方法 enumIPv4Interfaces),然后返回 IPv6 接口(方法 enumIPv6Interfaces)。

这些类别中的顺序似乎与操作系统使用的顺序相同(它使用 SIOCGIFCONF ioctl)。

请注意,这是依赖于实现的并且定义,因此任何实现都可以很容易地以不同的方式进行操作。

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.

伊面 2024-11-15 05:47:18

这只是委托给本机调用,不,我不知道有任何方法可以改变它。

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

别闹i 2024-11-15 05:47:18

如果您查看源代码,您会发现 getNetworkInterfaces 仅返回枚举,该枚举支持 NetworkInterface 数组,该数组由本机 getAll() 方法返回。因此,它依赖于实现和系统。你对此无能为力。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文