當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。