Retrieve an <code>InetAddress</code>. If the address is not
an IP address and cannot be resolved <code>null</code> will
be returned.
336988
public static InetAddress getInetAddress( String key, InetAddress def ) {
        String addr = prp.getProperty( key );
        if( addr != null ) {
            try {
                def = InetAddress.getByName( addr );
            } catch( UnknownHostException uhe ) {
                if( log.level > 0 ) {
                    log.println( addr );
                    uhe.printStackTrace( log );
                }
            }
        }
        return def;
    }
1302696
@Override
  public InetAddress addressLocal()
  {
    Socket s = getSocket();
    
    if (s != null) {
      return s.getLocalAddress();
    }
    else {
      return null;
    }
  }
300173
public InetSocketAddress getRemoteAddressUDP () {
		InetSocketAddress connectedAddress = udp.connectedAddress;
		if (connectedAddress != null) return connectedAddress;
		return udpRemoteAddress;
	}
1190215
protected RFC3881NetworkAccessPointTypeCodes getNetworkAccessPointCodeFromAddress(String address) {
        if (EventUtils.isEmptyOrNull(address)) {
            return null;
        }

        if (address.matches("^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$")) {
            return RFC3881NetworkAccessPointTypeCodes.IP_ADDRESS;
        }

        return RFC3881NetworkAccessPointTypeCodes.MACHINE_NAME;
    }
936137
public static String getIP(final InetAddress inetAddress)
	{
		String ip = "";
		ip = inetAddress.getHostAddress();
		if (ip.equals(""))
		{
			final byte[] ipAddressInBytes = inetAddress.getAddress();
			for (int i = 0; i < ipAddressInBytes.length; i++)
			{
				if (i > 0)
				{
					ip += ".";
				}
				ip += ipAddressInBytes[i] & 0xFF;
			}
		}
		return ip;
	}
43416
public static InetAddress InetAddressByIPv6(String address) {
    StringTokenizer addressTokens = new StringTokenizer(address, ":");
    byte[] bytes = new byte[16];
    if (addressTokens.countTokens() == 8) {
      int count = 0;
      while (addressTokens.hasMoreTokens()) {
        int word = Integer.parseInt(addressTokens.nextToken(), 16);
        bytes[count * 2]     = (byte) ((word >> 8) & 0xff);
        bytes[count * 2 + 1] = (byte) (word & 0xff);
        count++;
      }
    }
    else {
      return null;
    }
    try {
      return InetAddress.getByAddress(bytes);
    } catch (UnknownHostException e) {
      return null;
    }
  }
476179
protected final InetSocketAddress remoteAddress() {
        if (remoteAddress == null) {
            if (server) {
                remoteAddress = new InetSocketAddress(NetUtil.LOCALHOST, randomClientPort());
            } else {
                remoteAddress = new InetSocketAddress(NetUtil.LOCALHOST,
                                                      guessServerPort(sessionProtocol, authority));
            }
        }
        return remoteAddress;
    }
931854
public static int aton(final InetAddress ip)
	{
		if (ip == null)
		{
			throw new Error("the result of aton(null) is undefined");
		}
		if (ip instanceof Inet4Address)
		{
			return aton((Inet4Address) ip);
		}
		else
		{
			throw new Error("int aton(InetAddress) does not function for " + ip.getClass());
		}
	}
26946
static int inet4AsInt(InetAddress ia) {
        if (ia instanceof Inet4Address) {
            byte[] addr = ia.getAddress();
            int address  = addr[3] & 0xFF;
            address |= ((addr[2] << 8) & 0xFF00);
            address |= ((addr[1] << 16) & 0xFF0000);
            address |= ((addr[0] << 24) & 0xFF000000);
            return address;
        }
        throw new AssertionError("Should not reach here");
    }
1134664
public static InetAddress getLocalAddress()
    {
        if (localInetAddress == null)
            try
            {
                localInetAddress = DatabaseDescriptor.getListenAddress() == null
                                    ? InetAddress.getLocalHost()
                                    : DatabaseDescriptor.getListenAddress();
            }
            catch (UnknownHostException e)
            {
                throw new RuntimeException(e);
            }
        return localInetAddress;
    }
138319
public static InetAddress getLocalAddress() {
        if (LOCAL_ADDRESS != null)
            return LOCAL_ADDRESS;
        InetAddress localAddress = getLocalAddress0();
        LOCAL_ADDRESS = localAddress;
        return localAddress;
    }
412616
@Override
    protected InetAddress isAcceptable(NetworkInterface networkInterface, InetAddress address) throws SocketException {

        if( name.equals(networkInterface.getName()) )
            return address;
        return null;
    }
460394
public static InetAddress getLocalIpAddress(String iface) throws RuntimeException
	{
		try
		{
			NetworkInterface nic = NetworkInterface.getByName(iface);

			Enumeration<InetAddress> ips = nic.getInetAddresses();

			InetAddress firstIP = null;
			while (ips != null && ips.hasMoreElements())
			{
				InetAddress ip = ips.nextElement();
				if (firstIP == null)
					firstIP = ip;

				if (log.isDebugEnabled())
					log.debug("[IpHelper] {getLocalIpAddress} Considering locality: " + ip.getHostAddress());

				if (!ip.isAnyLocalAddress())
				{
					return ip;
				}
			}

			// Return the first IP (or null if no IPs were returned)
			return firstIP;
		}
		catch (SocketException e)
		{
			throw new RuntimeException("[IpHelper] {getLocalIpAddress}: Unable to acquire an IP", e);
		}
	}
133646
public InetAddress
getAddress() {
	try {
		if (name == null)
			return InetAddress.getByAddress(address);
		else
			return InetAddress.getByAddress(name.toString(),
							address);
	} catch (UnknownHostException e) {
		return null;
	}
}
70314
public static InetAddress getLoopbackAddress() {
		try {
			final Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
			if (interfaces != null) {
				NetworkInterface inter;
				InetAddress adr;
				Enumeration<InetAddress> addrs;
				while (interfaces.hasMoreElements()) {
					inter = interfaces.nextElement();
					addrs = inter.getInetAddresses();
					if (addrs != null) {
						while (addrs.hasMoreElements()) {
							adr = addrs.nextElement();
							if (adr != null && adr.isLoopbackAddress() && (adr instanceof Inet4Address)) {
								return adr;
							}
						}
					}
				}
			}
		} catch (SocketException e) {
			//
		}
		return null;
	}
1084276
private static String getHostPort(SocketAddress address) {
        if (address instanceof ResourceAddress) {
            ResourceAddress lowest = getLowestTransportLayer((ResourceAddress)address);
            return format(HOST_PORT_FORMAT, lowest.getResource().getHost(), lowest.getResource().getPort());
        }
        if (address instanceof InetSocketAddress) {
            InetSocketAddress inet = (InetSocketAddress)address;
            // we don't use inet.toString() because it would include a leading /, for example "/127.0.0.1:21345"
            // use getHostString() to avoid a reverse DNS lookup
            return format(HOST_PORT_FORMAT, inet.getHostString(), inet.getPort());
        }
        return null;
    }
537191
public static InetAddress getByAddress(String host, byte[] addr, int scopeId)
        throws UnknownHostException {
        if (host != null && host.length() > 0 && host.charAt(0) == '[') {
            if (host.charAt(host.length()-1) == ']') {
                host = host.substring(1, host.length() -1);
            }
        }
        if (addr != null) {
            if (addr.length == Inet4Address.INADDRSZ) {
                return new Inet4Address(host, addr);
            } else if (addr.length == Inet6Address.INADDRSZ) {
                byte[] newAddr
                    = IPAddressUtil.convertFromIPv4MappedAddress(addr);
                if (newAddr != null) {
                    return new Inet4Address(host, newAddr);
                } else {
                    return new Inet6Address(host, addr, scopeId);
                }
            }
        }
        throw new UnknownHostException("addr is of illegal length");
    }