本文整理匯總了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;
}