private static String translateHost(InetAddress address, HostTranslationType hostType) { if (address == null) return null; if (hostType == null) return BootIOUtils.wrapIpv6HostAddressIfNeeded(address); switch (hostType) { case canonicalhost: return address.getCanonicalHostName(); case host: return address.getHostName(); case ip: case ip6: return BootIOUtils.wrapIpv6HostAddressIfNeeded(address); default: throw new IllegalStateException("Unsupported host type: " + hostType); } } }
/** * Return the local host address using <code>java.net.InetAddress.getLocalHost().getHostAddress()</code> * * @return The local host address * @throws java.net.UnknownHostException if no IP address for the local host could be found. */ public static String getHostAddress() throws UnknownHostException { //Fix GS-11738, important! Don't change warmup(); String value = System.getProperty(CommonSystemProperties.HOST_ADDRESS); //if (value == null) // value = System.getenv("XAP_NIC_ADDRESS"); if (value == null) { InetAddress inetAddress = java.net.InetAddress.getLocalHost(); value = BootIOUtils.wrapIpv6HostAddressIfNeeded(inetAddress); } else if (NetworkTuple.isNetworkTuple(value)) { NetworkTuple tuple = getNetworkSnapshot().parse(value); if (tuple.address == null) throw new RuntimeException("Failed to find network interface for [" + value + "]"); value = tuple.host; } else { InetAddress inetAddress = java.net.InetAddress.getByName(value); value = toHostAddress(inetAddress, value); } //Set the translation back in the properties. System.setProperty(CommonSystemProperties.HOST_ADDRESS, value); return value; }
/** * Get address that Webster is bound to * * @return The host address the server socket Webster is using is bound to. If the socket is * null, return null. */ public String getAddress() { if (ss == null) return (null); final InetAddress inetAddress = SystemInfo.singleton().network().isPublicHostConfigured() ? SystemInfo.singleton().network().getPublicHost() : ss.getInetAddress(); return BootIOUtils.wrapIpv6HostAddressIfNeeded(inetAddress); }