/** * @param addr The {@link InetAddress} to be considered * @return <code>true</code> if the address is a loopback one. * <B>Note:</B> if {@link InetAddress#isLoopback()} * returns <code>false</code> the address <U>string</U> is checked * @see #toAddressString(InetAddress) * @see #isLoopback(String) */ public static boolean isLoopback (InetAddress addr) { if (addr == null) { return false; } if (addr.isLoopbackAddress()) { return true; } String ip=toAddressString(addr); return isLoopback(ip); }
public String getProperty(String name) { if (StringUtil.isEmpty(name)) { throw new IllegalArgumentException("No property name"); } if (NETWORK_CONNECTING_IP_KEY.equals(name)) { InetAddress conAddr = getConnectingIp(); return NetworkAddressUtil.toAddressString(conAddr); } else if (NETWORK_FALLBACK_IP_KEY.equals(name)) { InetAddress addr = getFallbackAddress(); return NetworkAddressUtil.toAddressString(addr); } else if (NETWORK_NAME_KEY.equals(name)) { InetAddress addr = getConnectingIp(); if ((addr == null) || NetworkAddressUtil.isLoopback(addr)) { InetAddress fallback=getFallbackAddress(); if (fallback != null) { // if no fallback, then use the address even if it is a loopback addr = fallback; } } if (addr != null) { return addr.getHostName(); } } return null; }
public static String createServerLabel(ServerName serverName, String fqdn, String ip, String pid) { final String label; if (StringUtil.isEmpty(fqdn)) { // if no properties are available, default to server name label = StringUtil.isEmpty(ip) ? serverName.getName() : ip; } else if (NetworkAddressUtil.isLoopback(fqdn)) { // if no IP used use the FQDN even if it is a loopback label = StringUtil.isEmpty(ip) ? fqdn : ip; } else { label = fqdn; } if (StringUtil.isEmpty(pid)) { return label; } else { return label + "-" + pid; } } }
}; for (String ip : candidates) { if ((!StringUtil.isEmpty(ip)) && (!NetworkAddressUtil.isLoopback(ip))) { return ip;