java.net.Inet6Address#isIPv4CompatibleAddress ( )源码实例Demo

下面列出了java.net.Inet6Address#isIPv4CompatibleAddress ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netty-4.1.22   文件: DnsQueryContextManager.java
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;
    }
}
 
源代码2 项目: codebuff   文件: InetAddresses.java
/**
 * 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;
}
 
源代码3 项目: codebuff   文件: InetAddresses.java
/**
 * 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;
}
 
源代码4 项目: codebuff   文件: InetAddresses.java
/**
 * 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;
}
 
源代码5 项目: codebuff   文件: InetAddresses.java
/**
 * 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;
}
 
源代码6 项目: codebuff   文件: InetAddresses.java
/**
 * 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;
}
 
源代码7 项目: activemq-artemis   文件: InetAddresses.java
/**
 * 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;
}