我有一个返回 ipv4 地址(4 个八位字节)的 InterfaceAddress。然而,网络前缀长度似乎是与接口关联的 ipv6 地址(它返回为 128)。如何找到正确的网络前缀长度?
Enumeration<NetworkInterface> NetworkInterface.getNetworkInterfaces()
for (; interfaces.hasMoreElements();) {
final List<InterfaceAddress>interfaceAddresses =
interfaces.nextElement().getInterfaceAddresses();
for (final InterfaceAddress address : interfaceAddresses) {
assert(address.getAddress().getAddress().length == 4); // [sic]
assert(address.getNetworkPrefixLength() < 32); // <- Fails. Actually equals 128
}
}