Java Code Examples for java.net.Inet6Address#isIPv4CompatibleAddress()

The following examples show how to use java.net.Inet6Address#isIPv4CompatibleAddress() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DnsQueryContextManager.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
private IntObjectMap<DnsQueryContext> getOrCreateContextMap(InetSocketAddress nameServerAddr) {
    synchronized (map) {
        final IntObjectMap<DnsQueryContext> contexts = map.get(nameServerAddr);
        if (contexts != null) {
            return contexts;
        }

        final IntObjectMap<DnsQueryContext> newContexts = new IntObjectHashMap<DnsQueryContext>();
        final InetAddress a = nameServerAddr.getAddress();
        final int port = nameServerAddr.getPort();
        map.put(nameServerAddr, newContexts);

        if (a instanceof Inet4Address) {
            // Also add the mapping for the IPv4-compatible IPv6 address.
            final Inet4Address a4 = (Inet4Address) a;
            if (a4.isLoopbackAddress()) {
                map.put(new InetSocketAddress(NetUtil.LOCALHOST6, port), newContexts);
            } else {
                map.put(new InetSocketAddress(toCompactAddress(a4), port), newContexts);
            }
        } else if (a instanceof Inet6Address) {
            // Also add the mapping for the IPv4 address if this IPv6 address is compatible.
            final Inet6Address a6 = (Inet6Address) a;
            if (a6.isLoopbackAddress()) {
                map.put(new InetSocketAddress(NetUtil.LOCALHOST4, port), newContexts);
            } else if (a6.isIPv4CompatibleAddress()) {
                map.put(new InetSocketAddress(toIPv4Address(a6), port), newContexts);
            }
        }

        return newContexts;
    }
}
 
Example 2
Source File: InetAddresses.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Evaluates whether the argument is an IPv6 "compat" address.
 *
 * <p>An "IPv4 compatible", or "compat", address is one with 96 leading bits of zero, with the
 * remaining 32 bits interpreted as an IPv4 address. These are conventionally represented in
 * string literals as {@code "::192.168.0.1"}, though {@code "::c0a8:1"} is also considered an
 * IPv4 compatible address (and equivalent to {@code "::192.168.0.1"}).
 *
 * <p>For more on IPv4 compatible addresses see section 2.5.5.1 of
 * <a target="_parent" href="http://tools.ietf.org/html/rfc4291#section-2.5.5.1">RFC 4291</a>.
 *
 * <p>NOTE: This method is different from {@link Inet6Address#isIPv4CompatibleAddress} in that it
 * more correctly classifies {@code "::"} and {@code "::1"} as proper IPv6 addresses (which they
 * are), NOT IPv4 compatible addresses (which they are generally NOT considered to be).
 *
 * @param ip {@link Inet6Address} to be examined for embedded IPv4 compatible address format
 * @return {@code true} if the argument is a valid "compat" address
 */
public static boolean isCompatIPv4Address(Inet6Address ip) {
  if (!ip.isIPv4CompatibleAddress()) {
    return false;
  }

  byte[] bytes = ip.getAddress();
  if ((bytes[12] == 0)
      && (bytes[13] == 0)
      && (bytes[14] == 0)
      && ((bytes[15] == 0) || (bytes[15] == 1))) {
    return false;
  }

  return true;
}
 
Example 3
Source File: InetAddresses.java    From codebuff with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * Evaluates whether the argument is an IPv6 "compat" address.
 *
 * <p>An "IPv4 compatible", or "compat", address is one with 96 leading bits of zero, with the
 * remaining 32 bits interpreted as an IPv4 address. These are conventionally represented in
 * string literals as {@code "::192.168.0.1"}, though {@code "::c0a8:1"} is also considered an
 * IPv4 compatible address (and equivalent to {@code "::192.168.0.1"}).
 *
 * <p>For more on IPv4 compatible addresses see section 2.5.5.1 of
 * <a target="_parent" href="http://tools.ietf.org/html/rfc4291#section-2.5.5.1">RFC 4291</a>.
 *
 * <p>NOTE: This method is different from {@link Inet6Address#isIPv4CompatibleAddress} in that it
 * more correctly classifies {@code "::"} and {@code "::1"} as proper IPv6 addresses (which they
 * are), NOT IPv4 compatible addresses (which they are generally NOT considered to be).
 *
 * @param ip {@link Inet6Address} to be examined for embedded IPv4 compatible address format
 * @return {@code true} if the argument is a valid "compat" address
 */


public static boolean isCompatIPv4Address(Inet6Address ip) {
  if (!ip.isIPv4CompatibleAddress()) {
    return false;
  }
  byte[] bytes = ip.getAddress();
  if ((bytes[12] == 0) && (bytes[13] == 0) && (bytes[14] == 0)
      && ((bytes[15] == 0) || (bytes[15] == 1))) {
    return false;
  }
  return true;
}
 
Example 4
Source File: InetAddresses.java    From codebuff with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * Evaluates whether the argument is an IPv6 "compat" address.
 *
 * <p>An "IPv4 compatible", or "compat", address is one with 96 leading bits of zero, with the
 * remaining 32 bits interpreted as an IPv4 address. These are conventionally represented in
 * string literals as {@code "::192.168.0.1"}, though {@code "::c0a8:1"} is also considered an
 * IPv4 compatible address (and equivalent to {@code "::192.168.0.1"}).
 *
 * <p>For more on IPv4 compatible addresses see section 2.5.5.1 of
 * <a target="_parent" href="http://tools.ietf.org/html/rfc4291#section-2.5.5.1">RFC 4291</a>.
 *
 * <p>NOTE: This method is different from {@link Inet6Address#isIPv4CompatibleAddress} in that it
 * more correctly classifies {@code "::"} and {@code "::1"} as proper IPv6 addresses (which they
 * are), NOT IPv4 compatible addresses (which they are generally NOT considered to be).
 *
 * @param ip {@link Inet6Address} to be examined for embedded IPv4 compatible address format
 * @return {@code true} if the argument is a valid "compat" address
 */


public static boolean isCompatIPv4Address(Inet6Address ip) {
  if (!ip.isIPv4CompatibleAddress()) {
    return false;
  }
  byte[] bytes = ip.getAddress();
  if ((bytes[12] == 0) && (bytes[13] == 0) && (bytes[14] == 0)
      && ((bytes[15] == 0) || (bytes[15] == 1))) {
    return false;
  }
  return true;
}
 
Example 5
Source File: InetAddresses.java    From codebuff with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * Evaluates whether the argument is an IPv6 "compat" address.
 *
 * <p>An "IPv4 compatible", or "compat", address is one with 96 leading bits of zero, with the
 * remaining 32 bits interpreted as an IPv4 address. These are conventionally represented in
 * string literals as {@code "::192.168.0.1"}, though {@code "::c0a8:1"} is also considered an
 * IPv4 compatible address (and equivalent to {@code "::192.168.0.1"}).
 *
 * <p>For more on IPv4 compatible addresses see section 2.5.5.1 of
 * <a target="_parent" href="http://tools.ietf.org/html/rfc4291#section-2.5.5.1">RFC 4291</a>.
 *
 * <p>NOTE: This method is different from {@link Inet6Address#isIPv4CompatibleAddress} in that it
 * more correctly classifies {@code "::"} and {@code "::1"} as proper IPv6 addresses (which they
 * are), NOT IPv4 compatible addresses (which they are generally NOT considered to be).
 *
 * @param ip {@link Inet6Address} to be examined for embedded IPv4 compatible address format
 * @return {@code true} if the argument is a valid "compat" address
 */


public static boolean isCompatIPv4Address(Inet6Address ip) {
  if (!ip.isIPv4CompatibleAddress()) {
    return false;
  }
  byte[] bytes = ip.getAddress();
  if ((bytes[12] == 0) && (bytes[13] == 0) && (bytes[14] == 0)
      && ((bytes[15] == 0) || (bytes[15] == 1))) {
    return false;
  }
  return true;
}
 
Example 6
Source File: InetAddresses.java    From codebuff with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * Evaluates whether the argument is an IPv6 "compat" address.
 *
 * <p>An "IPv4 compatible", or "compat", address is one with 96 leading bits of zero, with the
 * remaining 32 bits interpreted as an IPv4 address. These are conventionally represented in
 * string literals as {@code "::192.168.0.1"}, though {@code "::c0a8:1"} is also considered an
 * IPv4 compatible address (and equivalent to {@code "::192.168.0.1"}).
 *
 * <p>For more on IPv4 compatible addresses see section 2.5.5.1 of
 * <a target="_parent" href="http://tools.ietf.org/html/rfc4291#section-2.5.5.1">RFC 4291</a>.
 *
 * <p>NOTE: This method is different from {@link Inet6Address#isIPv4CompatibleAddress} in that it
 * more correctly classifies {@code "::"} and {@code "::1"} as proper IPv6 addresses (which they
 * are), NOT IPv4 compatible addresses (which they are generally NOT considered to be).
 *
 * @param ip {@link Inet6Address} to be examined for embedded IPv4 compatible address format
 * @return {@code true} if the argument is a valid "compat" address
 */


public static boolean isCompatIPv4Address(Inet6Address ip) {
  if (!ip.isIPv4CompatibleAddress()) {
    return false;
  }
  byte[] bytes = ip.getAddress();
  if ((bytes[12] == 0) && (bytes[13] == 0) && (bytes[14] == 0)
      && ((bytes[15] == 0) || (bytes[15] == 1))) {
    return false;
  }
  return true;
}
 
Example 7
Source File: InetAddresses.java    From activemq-artemis with Apache License 2.0 3 votes vote down vote up
/**
 * Evaluates whether the argument is an IPv6 "compat" address.
 *
 * <p>An "IPv4 compatible", or "compat", address is one with 96 leading
 * bits of zero, with the remaining 32 bits interpreted as an
 * IPv4 address.  These are conventionally represented in string
 * literals as {@code "::192.168.0.1"}, though {@code "::c0a8:1"} is
 * also considered an IPv4 compatible address (and equivalent to
 * {@code "::192.168.0.1"}).
 *
 * <p>For more on IPv4 compatible addresses see section 2.5.5.1 of
 * <a target="_parent"
 *   href="http://tools.ietf.org/html/rfc4291#section-2.5.5.1"
 *   >http://tools.ietf.org/html/rfc4291</a>
 *
 * <p>NOTE: This method is different from
 * {@link Inet6Address#isIPv4CompatibleAddress} in that it more
 * correctly classifies {@code "::"} and {@code "::1"} as
 * proper IPv6 addresses (which they are), NOT IPv4 compatible
 * addresses (which they are generally NOT considered to be).
 *
 * @param ip {@link Inet6Address} to be examined for embedded IPv4 compatible address format
 * @return {@code true} if the argument is a valid "compat" address
 */
public static boolean isCompatIPv4Address(Inet6Address ip) {
   if (!ip.isIPv4CompatibleAddress()) {
      return false;
   }

   byte[] bytes = ip.getAddress();
   if ((bytes[12] == 0) && (bytes[13] == 0) && (bytes[14] == 0)
         && ((bytes[15] == 0) || (bytes[15] == 1))) {
      return false;
   }

   return true;
}