InetAddress.isSiteLocalAddress() 实际上是什么意思?
2022-09-03 05:40:51
下面是一些代码,用于确定应该在多宿主计算机上工作的本地主机名:
/**
* Work out the first local host name by iterating the network interfaces
*
* @return
* @throws SocketException
*/
private String findFirstLocalHostName() throws SocketException {
Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();
while (ifaces.hasMoreElements()) {
NetworkInterface iface = ifaces.nextElement();
Enumeration<InetAddress> addresses = iface.getInetAddresses();
while (addresses.hasMoreElements()) {
InetAddress add = addresses.nextElement();
if (!add.isLoopbackAddress() && add.isSiteLocalAddress()) {
return add.getHostName();
}
}
}
throw new RuntimeException("Failed to determine local hostname");
}
对 isSiteLocalAddress 的调用是否引入了 bug?我找不到有关此方法的任何有用信息,但我有一种感觉,它仅与IP v 6相关,并且已被弃用。