/** * Returns an integer representing an IPv4 address regardless of whether the supplied argument is * an IPv4 address or not. * * <p>IPv6 addresses are <b>coerced</b> to IPv4 addresses before being converted to integers. * * <p>As long as there are applications that assume that all IP addresses are IPv4 addresses and * can therefore be converted safely to integers (for whatever purpose) this function can be used * to handle IPv6 addresses as well until the application is suitably fixed. * * <p>NOTE: an IPv6 address coerced to an IPv4 address can only be used for such purposes as * rudimentary identification or indexing into a collection of real {@link InetAddress}es. They * cannot be used as real addresses for the purposes of network communication. * * @param ip {@link InetAddress} to convert * @return {@code int}, "coerced" if ip is not an IPv4 address * @since 7.0 */ public static int coerceToInteger(InetAddress ip) { return ByteStreams.newDataInput(getCoercedIPv4Address(ip).getAddress()).readInt(); }
/** * Returns an integer representing an IPv4 address regardless of whether the supplied argument is * an IPv4 address or not. * * <p>IPv6 addresses are <b>coerced</b> to IPv4 addresses before being converted to integers. * * <p>As long as there are applications that assume that all IP addresses are IPv4 addresses and * can therefore be converted safely to integers (for whatever purpose) this function can be used * to handle IPv6 addresses as well until the application is suitably fixed. * * <p>NOTE: an IPv6 address coerced to an IPv4 address can only be used for such purposes as * rudimentary identification or indexing into a collection of real {@link InetAddress}es. They * cannot be used as real addresses for the purposes of network communication. * * @param ip {@link InetAddress} to convert * @return {@code int}, "coerced" if ip is not an IPv4 address * @since 7.0 */ public static int coerceToInteger(InetAddress ip) { return ByteStreams.newDataInput(getCoercedIPv4Address(ip).getAddress()).readInt(); }
/** * Returns an integer representing an IPv4 address regardless of whether the supplied argument is * an IPv4 address or not. * * <p>IPv6 addresses are <b>coerced</b> to IPv4 addresses before being converted to integers. * * <p>As long as there are applications that assume that all IP addresses are IPv4 addresses and * can therefore be converted safely to integers (for whatever purpose) this function can be used * to handle IPv6 addresses as well until the application is suitably fixed. * * <p>NOTE: an IPv6 address coerced to an IPv4 address can only be used for such purposes as * rudimentary identification or indexing into a collection of real {@link InetAddress}es. They * cannot be used as real addresses for the purposes of network communication. * * @param ip {@link InetAddress} to convert * @return {@code int}, "coerced" if ip is not an IPv4 address * @since 7.0 */ public static int coerceToInteger(InetAddress ip) { return ByteStreams.newDataInput(getCoercedIPv4Address(ip).getAddress()).readInt(); }
assertEquals(localHost4, InetAddresses.getCoercedIPv4Address(localHost4)); assertEquals(localHost4, InetAddresses.getCoercedIPv4Address(InetAddresses.forString("::1"))); InetAddresses.getCoercedIPv4Address(InetAddresses.forString("::"))); != InetAddresses.getCoercedIPv4Address(InetAddresses.forString("::1.2.3.4"))); != InetAddresses.getCoercedIPv4Address(InetAddresses.forString("2002:0102:0304::1"))); InetAddresses.getCoercedIPv4Address(InetAddresses.forString("2002:0102:0304::1")) != InetAddresses.getCoercedIPv4Address(InetAddresses.forString("2002:0506:0708::1"))); InetAddresses.getCoercedIPv4Address(InetAddresses.forString("2002:0102:0304::1")) != InetAddresses.getCoercedIPv4Address(InetAddresses.forString("2002:0102:0304::2"))); != InetAddresses.getCoercedIPv4Address( InetAddresses.forString("2001:0000:4136:e378:8000:63bf:3fff:fdd2"))); InetAddresses.getCoercedIPv4Address( InetAddresses.forString("2001:0000:4136:e378:8000:63bf:3fff:fdd2")) != InetAddresses.getCoercedIPv4Address( InetAddresses.forString("2001:0000:4136:e379:8000:63bf:3fff:fdd2"))); InetAddresses.getCoercedIPv4Address( InetAddresses.forString("2001:0000:4136:e378:8000:63bf:3fff:fdd2")), InetAddresses.getCoercedIPv4Address( InetAddresses.forString("2001:0000:4136:e378:9000:63bf:3fff:fdd2")));
public static boolean isPrivateNetworkAddress(String inetAddress) { Inet4Address address = InetAddresses.getCoercedIPv4Address(InetAddresses.forString(inetAddress)); return isPrivateNetworkAddress(address); }
public static boolean isPrivateNetworkAddress(String inetAddress) { Inet4Address address = InetAddresses.getCoercedIPv4Address(InetAddresses.forString(inetAddress)); return isPrivateNetworkAddress(address); }
/** * Returns an integer representing an IPv4 address regardless of whether the supplied argument is * an IPv4 address or not. * * <p>IPv6 addresses are <b>coerced</b> to IPv4 addresses before being converted to integers. * * <p>As long as there are applications that assume that all IP addresses are IPv4 addresses and * can therefore be converted safely to integers (for whatever purpose) this function can be used * to handle IPv6 addresses as well until the application is suitably fixed. * * <p>NOTE: an IPv6 address coerced to an IPv4 address can only be used for such purposes as * rudimentary identification or indexing into a collection of real {@link InetAddress}es. They * cannot be used as real addresses for the purposes of network communication. * * @param ip {@link InetAddress} to convert * @return {@code int}, "coerced" if ip is not an IPv4 address * @since 7.0 */ public static int coerceToInteger(InetAddress ip) { return ByteStreams.newDataInput(getCoercedIPv4Address(ip).getAddress()).readInt(); }
/** * Returns an integer representing an IPv4 address regardless of whether the supplied argument is * an IPv4 address or not. * * <p>IPv6 addresses are <b>coerced</b> to IPv4 addresses before being converted to integers. * * <p>As long as there are applications that assume that all IP addresses are IPv4 addresses and * can therefore be converted safely to integers (for whatever purpose) this function can be used * to handle IPv6 addresses as well until the application is suitably fixed. * * <p>NOTE: an IPv6 address coerced to an IPv4 address can only be used for such purposes as * rudimentary identification or indexing into a collection of real {@link InetAddress}es. They * cannot be used as real addresses for the purposes of network communication. * * @param ip {@link InetAddress} to convert * @return {@code int}, "coerced" if ip is not an IPv4 address * @since 7.0 */ public static int coerceToInteger(InetAddress ip) { return ByteStreams.newDataInput(getCoercedIPv4Address(ip).getAddress()).readInt(); }
/** * Returns an integer representing an IPv4 address regardless of * whether the supplied argument is an IPv4 address or not. * * <p>IPv6 addresses are <b>coerced</b> to IPv4 addresses before being * converted to integers. * * <p>As long as there are applications that assume that all IP addresses * are IPv4 addresses and can therefore be converted safely to integers * (for whatever purpose) this function can be used to handle IPv6 * addresses as well until the application is suitably fixed. * * <p>NOTE: an IPv6 address coerced to an IPv4 address can only be used * for such purposes as rudimentary identification or indexing into a * collection of real {@link InetAddress}es. They cannot be used as * real addresses for the purposes of network communication. * * @param ip {@link InetAddress} to convert * @return {@code int}, "coerced" if ip is not an IPv4 address * @since 7.0 */ public static int coerceToInteger(InetAddress ip) { return ByteStreams.newDataInput(getCoercedIPv4Address(ip).getAddress()).readInt(); }
/** * Returns an integer representing an IPv4 address regardless of * whether the supplied argument is an IPv4 address or not. * * <p>IPv6 addresses are <b>coerced</b> to IPv4 addresses before being * converted to integers. * * <p>As long as there are applications that assume that all IP addresses * are IPv4 addresses and can therefore be converted safely to integers * (for whatever purpose) this function can be used to handle IPv6 * addresses as well until the application is suitably fixed. * * <p>NOTE: an IPv6 address coerced to an IPv4 address can only be used * for such purposes as rudimentary identification or indexing into a * collection of real {@link InetAddress}es. They cannot be used as * real addresses for the purposes of network communication. * * @param ip {@link InetAddress} to convert * @return {@code int}, "coerced" if ip is not an IPv4 address * @since 7.0 */ public static int coerceToInteger(InetAddress ip) { return ByteStreams.newDataInput(getCoercedIPv4Address(ip).getAddress()).readInt(); }
/** * Returns an integer representing an IPv4 address regardless of * whether the supplied argument is an IPv4 address or not. * * <p>IPv6 addresses are <b>coerced</b> to IPv4 addresses before being * converted to integers. * * <p>As long as there are applications that assume that all IP addresses * are IPv4 addresses and can therefore be converted safely to integers * (for whatever purpose) this function can be used to handle IPv6 * addresses as well until the application is suitably fixed. * * <p>NOTE: an IPv6 address coerced to an IPv4 address can only be used * for such purposes as rudimentary identification or indexing into a * collection of real {@link InetAddress}es. They cannot be used as * real addresses for the purposes of network communication. * * @param ip {@link InetAddress} to convert * @return {@code int}, "coerced" if ip is not an IPv4 address * @since 7.0 */ public static int coerceToInteger(InetAddress ip) { return ByteStreams.newDataInput(getCoercedIPv4Address(ip).getAddress()).readInt(); }
/** * Returns an integer representing an IPv4 address regardless of * whether the supplied argument is an IPv4 address or not. * * <p>IPv6 addresses are <b>coerced</b> to IPv4 addresses before being * converted to integers. * * <p>As long as there are applications that assume that all IP addresses * are IPv4 addresses and can therefore be converted safely to integers * (for whatever purpose) this function can be used to handle IPv6 * addresses as well until the application is suitably fixed. * * <p>NOTE: an IPv6 address coerced to an IPv4 address can only be used * for such purposes as rudimentary identification or indexing into a * collection of real {@link InetAddress}es. They cannot be used as * real addresses for the purposes of network communication. * * @param ip {@link InetAddress} to convert * @return {@code int}, "coerced" if ip is not an IPv4 address * @since 7.0 */ public static int coerceToInteger(InetAddress ip) { return ByteStreams.newDataInput(getCoercedIPv4Address(ip).getAddress()).readInt(); }
/** * Returns an integer representing an IPv4 address regardless of * whether the supplied argument is an IPv4 address or not. * * <p>IPv6 addresses are <b>coerced</b> to IPv4 addresses before being * converted to integers. * * <p>As long as there are applications that assume that all IP addresses * are IPv4 addresses and can therefore be converted safely to integers * (for whatever purpose) this function can be used to handle IPv6 * addresses as well until the application is suitably fixed. * * <p>NOTE: an IPv6 address coerced to an IPv4 address can only be used * for such purposes as rudimentary identification or indexing into a * collection of real {@link InetAddress}es. They cannot be used as * real addresses for the purposes of network communication. * * @param ip {@link InetAddress} to convert * @return {@code int}, "coerced" if ip is not an IPv4 address * @since 7.0 */ public static int coerceToInteger(InetAddress ip) { return ByteStreams.newDataInput(getCoercedIPv4Address(ip).getAddress()).readInt(); }
/** * Returns an integer representing an IPv4 address regardless of * whether the supplied argument is an IPv4 address or not. * * <p>IPv6 addresses are <b>coerced</b> to IPv4 addresses before being * converted to integers. * * <p>As long as there are applications that assume that all IP addresses * are IPv4 addresses and can therefore be converted safely to integers * (for whatever purpose) this function can be used to handle IPv6 * addresses as well until the application is suitably fixed. * * <p>NOTE: an IPv6 address coerced to an IPv4 address can only be used * for such purposes as rudimentary identification or indexing into a * collection of real {@link InetAddress}es. They cannot be used as * real addresses for the purposes of network communication. * * @param ip {@link InetAddress} to convert * @return {@code int}, "coerced" if ip is not an IPv4 address * @since 7.0 */ public static int coerceToInteger(InetAddress ip) { return ByteStreams.newDataInput(getCoercedIPv4Address(ip).getAddress()).readInt(); }
/** * Returns an integer representing an IPv4 address regardless of * whether the supplied argument is an IPv4 address or not. * * <p>IPv6 addresses are <b>coerced</b> to IPv4 addresses before being * converted to integers. * * <p>As long as there are applications that assume that all IP addresses * are IPv4 addresses and can therefore be converted safely to integers * (for whatever purpose) this function can be used to handle IPv6 * addresses as well until the application is suitably fixed. * * <p>NOTE: an IPv6 address coerced to an IPv4 address can only be used * for such purposes as rudimentary identification or indexing into a * collection of real {@link InetAddress}es. They cannot be used as * real addresses for the purposes of network communication. * * @param ip {@link InetAddress} to convert * @return {@code int}, "coerced" if ip is not an IPv4 address * @since 7.0 */ public static int coerceToInteger(InetAddress ip) { return ByteStreams.newDataInput(getCoercedIPv4Address(ip).getAddress()).readInt(); }
/** * Returns an integer representing an IPv4 address regardless of * whether the supplied argument is an IPv4 address or not. * * <p>IPv6 addresses are <b>coerced</b> to IPv4 addresses before being * converted to integers. * * <p>As long as there are applications that assume that all IP addresses * are IPv4 addresses and can therefore be converted safely to integers * (for whatever purpose) this function can be used to handle IPv6 * addresses as well until the application is suitably fixed. * * <p>NOTE: an IPv6 address coerced to an IPv4 address can only be used * for such purposes as rudimentary identification or indexing into a * collection of real {@link InetAddress}es. They cannot be used as * real addresses for the purposes of network communication. * * @param ip {@link InetAddress} to convert * @return {@code int}, "coerced" if ip is not an IPv4 address * @since 7 */ public static int coerceToInteger(InetAddress ip) { return ByteStreams.newDataInput(getCoercedIPv4Address(ip).getAddress()).readInt(); }
/** * Returns an integer representing an IPv4 address regardless of * whether the supplied argument is an IPv4 address or not. * * <p>IPv6 addresses are <b>coerced</b> to IPv4 addresses before being * converted to integers. * * <p>As long as there are applications that assume that all IP addresses * are IPv4 addresses and can therefore be converted safely to integers * (for whatever purpose) this function can be used to handle IPv6 * addresses as well until the application is suitably fixed. * * <p>NOTE: an IPv6 address coerced to an IPv4 address can only be used * for such purposes as rudimentary identification or indexing into a * collection of real {@link InetAddress}es. They cannot be used as * real addresses for the purposes of network communication. * * @param ip {@link InetAddress} to convert * @return {@code int}, "coerced" if ip is not an IPv4 address * @since 7.0 */ public static int coerceToInteger(InetAddress ip) { return ByteStreams.newDataInput(getCoercedIPv4Address(ip).getAddress()).readInt(); }
/** * Returns an integer representing an IPv4 address regardless of * whether the supplied argument is an IPv4 address or not. * * <p>IPv6 addresses are <b>coerced</b> to IPv4 addresses before being * converted to integers. * * <p>As long as there are applications that assume that all IP addresses * are IPv4 addresses and can therefore be converted safely to integers * (for whatever purpose) this function can be used to handle IPv6 * addresses as well until the application is suitably fixed. * * <p>NOTE: an IPv6 address coerced to an IPv4 address can only be used * for such purposes as rudimentary identification or indexing into a * collection of real {@link InetAddress}es. They cannot be used as * real addresses for the purposes of network communication. * * @param ip {@link InetAddress} to convert * @return {@code int}, "coerced" if ip is not an IPv4 address * @since 7.0 */ public static int coerceToInteger(InetAddress ip) { return ByteStreams.newDataInput(getCoercedIPv4Address(ip).getAddress()).readInt(); }
InetAddresses.getCoercedIPv4Address(localHost4)); InetAddresses.getCoercedIPv4Address( InetAddresses.forString("::1"))); InetAddresses.getCoercedIPv4Address( InetAddresses.forString("::"))); InetAddresses.getCoercedIPv4Address( InetAddresses.forString("::1.2.3.4"))); InetAddresses.getCoercedIPv4Address( InetAddresses.forString("2002:0102:0304::1"))); assertTrue(InetAddresses.getCoercedIPv4Address( InetAddresses.forString("2002:0102:0304::1")) != InetAddresses.getCoercedIPv4Address( InetAddresses.forString("2002:0506:0708::1"))); assertTrue(InetAddresses.getCoercedIPv4Address( InetAddresses.forString("2002:0102:0304::1")) != InetAddresses.getCoercedIPv4Address( InetAddresses.forString("2002:0102:0304::2"))); InetAddresses.getCoercedIPv4Address( InetAddresses.forString( "2001:0000:4136:e378:8000:63bf:3fff:fdd2"))); assertTrue(InetAddresses.getCoercedIPv4Address(