当前位置: 首页>>代码示例>>Java>>正文


Java Inet6Address.isIPv4CompatibleAddress方法代码示例

本文整理汇总了Java中java.net.Inet6Address.isIPv4CompatibleAddress方法的典型用法代码示例。如果您正苦于以下问题:Java Inet6Address.isIPv4CompatibleAddress方法的具体用法?Java Inet6Address.isIPv4CompatibleAddress怎么用?Java Inet6Address.isIPv4CompatibleAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.Inet6Address的用法示例。


在下文中一共展示了Inet6Address.isIPv4CompatibleAddress方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isCompatIPv4Address

import java.net.Inet6Address; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:34,代码来源:InetAddresses.java


注:本文中的java.net.Inet6Address.isIPv4CompatibleAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。