下面是一些代碼,以確定應該在多宿主箱工作本地主機名:InetAddress.isSiteLocalAddress()實際上是什麼意思?
/**
* 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引進一個錯誤?我找不到有關此方法的任何有用信息,但我有一種感覺,它僅與IP v 6相關並且已被棄用。
爲清楚起見,我不是這個意思,該方法已被否決......的「本地站點」,在IPv6和每http地址只是概念://www.ietf .org/rfc/rfc3879.txt – TiGz 2011-04-11 10:23:36