提问人:andy 提问时间:11/15/2023 更新时间:11/15/2023 访问量:15
Java Inet6Address.getScopeId 返回与操作系统不同的值
Java Inet6Address.getScopeId returns different value than the OS
问:
我写了一个小实用程序来打印适配器信息,类似于 Linux 上的 ifconfig。它使用 Inet6Address.getScopeId()。这是它生成的输出:
wlp0s20f3: flags=<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
getafix.fritz.box
inet4 192.168.188.43 netmask 255.255.255.0 broadcast 192.168.188.255
fe80:0:0:0:22e6:bd9d:f6cf:625e%wlp0s20f3
inet6 FE80::22E6:BD9D:F6CF:625E prefixlen 64 scopeid 2 <wlp0s20f3>
Ethernet DC:41:A9:A0:B7:A7
lo: flags=<UP,LOOPBACK,RUNNING> mtu 65536
localhost
inet4 127.0.0.1 netmask 255.0.0.0
localhost
inet6 ::1 prefixlen 128 scopeid 1 <lo>
Local Loopback
适配器的作用域 ID 为 2,环回适配器的作用域 ID 为 1。但是当我运行ifconfig(Ubuntu 22.04)时,我得到:
wlp0s20f3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.188.43 netmask 255.255.255.0 broadcast 192.168.188.255
inet6 fe80::22e6:bd9d:f6cf:625e prefixlen 64 scopeid 0x20<link>
ether dc:41:a9:a0:b7:a7 txqueuelen 1000 (Ethernet)
RX packets 183433 bytes 194827855 (194.8 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 66336 bytes 19686929 (19.6 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 229950 bytes 572171194 (572.1 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 229950 bytes 572171194 (572.1 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ifconfig 打印不同的作用域 ID,并输出不同的作用域名称。看起来我使用 ip6.getScopeId() 获得的数字与适配器索引(通过 ip6.getScopedInterface().getIndex() 派生)匹配。我使用 ip6.getScopedInterface().getName() 获得的名称与实际的适配器名称匹配。 “链接”和“主机”从何而来?
有什么想法吗?
答: 暂无答案
评论