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


Java Inet6Address.getAddress方法代码示例

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


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

示例1: getTeredoInfo

import java.net.Inet6Address; //导入方法依赖的package包/类
/**
 * Returns the Teredo information embedded in a Teredo address.
 *
 * @param ip {@link Inet6Address} to be examined for embedded Teredo information
 * @return extracted {@code TeredoInfo}
 * @throws IllegalArgumentException if the argument is not a valid IPv6 Teredo address
 */
public static TeredoInfo getTeredoInfo(Inet6Address ip) {
  checkArgument(isTeredoAddress(ip), "Address '%s' is not a Teredo address.", toAddrString(ip));

  byte[] bytes = ip.getAddress();
  Inet4Address server = getInet4Address(Arrays.copyOfRange(bytes, 4, 8));

  int flags = ByteStreams.newDataInput(bytes, 8).readShort() & 0xffff;

  // Teredo obfuscates the mapped client port, per section 4 of the RFC.
  int port = ~ByteStreams.newDataInput(bytes, 10).readShort() & 0xffff;

  byte[] clientBytes = Arrays.copyOfRange(bytes, 12, 16);
  for (int i = 0; i < clientBytes.length; i++) {
    // Teredo obfuscates the mapped client IP, per section 4 of the RFC.
    clientBytes[i] = (byte) ~clientBytes[i];
  }
  Inet4Address client = getInet4Address(clientBytes);

  return new TeredoInfo(server, client, port, flags);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:28,代码来源:InetAddresses.java

示例2: isIsatapAddress

import java.net.Inet6Address; //导入方法依赖的package包/类
/**
 * Evaluates whether the argument is an ISATAP address.
 *
 * <p>From RFC 5214: "ISATAP interface identifiers are constructed in Modified EUI-64 format [...]
 * by concatenating the 24-bit IANA OUI (00-00-5E), the 8-bit hexadecimal value 0xFE, and a 32-bit
 * IPv4 address in network byte order [...]"
 *
 * <p>For more on ISATAP addresses see section 6.1 of
 * <a target="_parent" href="http://tools.ietf.org/html/rfc5214#section-6.1">RFC 5214</a>.
 *
 * @param ip {@link Inet6Address} to be examined for ISATAP address format
 * @return {@code true} if the argument is an ISATAP address
 */
public static boolean isIsatapAddress(Inet6Address ip) {

  // If it's a Teredo address with the right port (41217, or 0xa101)
  // which would be encoded as 0x5efe then it can't be an ISATAP address.
  if (isTeredoAddress(ip)) {
    return false;
  }

  byte[] bytes = ip.getAddress();

  if ((bytes[8] | (byte) 0x03) != (byte) 0x03) {

    // Verify that high byte of the 64 bit identifier is zero, modulo
    // the U/L and G bits, with which we are not concerned.
    return false;
  }

  return (bytes[9] == (byte) 0x00) && (bytes[10] == (byte) 0x5e) && (bytes[11] == (byte) 0xfe);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:33,代码来源:InetAddresses.java

示例3: displayExpectedInet6Address

import java.net.Inet6Address; //导入方法依赖的package包/类
static void displayExpectedInet6Address(Inet6Address expectedInet6Address) {

        String expectedHostName = expectedInet6Address.getHostName();
        byte[] expectedAddress = expectedInet6Address.getAddress();
        String expectedHostAddress = expectedInet6Address.getHostAddress();
        int expectedScopeId = expectedInet6Address.getScopeId();
        NetworkInterface expectedNetIf = expectedInet6Address
                .getScopedInterface();

        System.err.println("Excpected HostName: " + expectedHostName);
        System.err.println("Expected Address: "
                + Arrays.toString(expectedAddress));
        System.err.println("Expected HostAddress: " + expectedHostAddress);
        System.err.println("Expected Scope Id " + expectedScopeId);
        System.err.println("Expected NetworkInterface " + expectedNetIf);
        System.err.println("Expected Inet6Address " + expectedInet6Address);
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:Inet6AddressSerializationTest.java

示例4: ipAddress

import java.net.Inet6Address; //导入方法依赖的package包/类
public ipAddress(Inet6Address address, int mask, boolean include) {
    networkMask = mask;
    included = include;
    int s = 128;
    netAddress = BigInteger.ZERO;
    for (byte b : address.getAddress()) {
        s -= 8;
        netAddress = netAddress.add(BigInteger.valueOf((b & 0xFF)).shiftLeft(s));
    }
}
 
开发者ID:akashdeepsingh9988,项目名称:Cybernet-VPN,代码行数:11,代码来源:NetworkSpace.java

示例5: _getBroadcastIPAddress4IPv6

import java.net.Inet6Address; //导入方法依赖的package包/类
/**
 * The broadcast ip for a icmp v6 request is replaced all bytes except the last three bytes with _IPv6_BROADCAST_IPADDRESS_PREFIX
 *
 * @param inet6Address
 * @return
 */
private Inet6Address _getBroadcastIPAddress4IPv6(Inet6Address inet6Address) throws UnknownHostException {
    //"fe80:0:0:0:250:56ff:febc:2688" -> "FF02::1:FFbc:2688"
    byte[] ipInBytes = inet6Address.getAddress();
    byte[] broadcastIpAddress = new byte[ipInBytes.length];
    System.arraycopy(_IPv6_BROADCAST_IPADDRESS_PREFIX, 0, broadcastIpAddress, 0, _IPv6_BROADCAST_IPADDRESS_PREFIX.length);
    int reservedBytes = 3;
    System.arraycopy(ipInBytes, ipInBytes.length - reservedBytes, broadcastIpAddress, _IPv6_BROADCAST_IPADDRESS_PREFIX.length -
            reservedBytes, reservedBytes);
    return (Inet6Address) Inet6Address.getByAddress(broadcastIpAddress);
}
 
开发者ID:gaoxingliang,项目名称:mac-address-detector-java,代码行数:17,代码来源:MacAddressHelper.java

示例6: _getBroadcastMacAddress4IPv6

import java.net.Inet6Address; //导入方法依赖的package包/类
/**
 * The broadcast mac address for a icmpv6 request is replaced all bytes with 33:33:ff except the last thress bytes
 * fe80::250:56ff:fe95:f8d -> 33:33:ff:95:0f:8d
 *
 * @param inet6Address
 * @return
 */
private MacAddress _getBroadcastMacAddress4IPv6(Inet6Address inet6Address) {
    byte[] ipInBytes = inet6Address.getAddress();
    byte[] broadcastMacAddress = new byte[_IPv6_BROADCAST_MACADDRESS_PREFIX.length];
    System.arraycopy(_IPv6_BROADCAST_MACADDRESS_PREFIX, 0, broadcastMacAddress, 0, _IPv6_BROADCAST_MACADDRESS_PREFIX.length);
    int reservedBytes = 3;
    System.arraycopy(ipInBytes, ipInBytes.length - reservedBytes, broadcastMacAddress, _IPv6_BROADCAST_MACADDRESS_PREFIX.length -
            reservedBytes, reservedBytes);
    return MacAddress.getByAddress(broadcastMacAddress);
}
 
开发者ID:gaoxingliang,项目名称:mac-address-detector-java,代码行数:17,代码来源:MacAddressHelper.java

示例7: 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

示例8: isTeredoAddress

import java.net.Inet6Address; //导入方法依赖的package包/类
/**
 * Evaluates whether the argument is a Teredo address.
 *
 * <p>Teredo addresses begin with the {@code "2001::/32"} prefix.
 *
 * @param ip {@link Inet6Address} to be examined for Teredo address format
 * @return {@code true} if the argument is a Teredo address
 */
public static boolean isTeredoAddress(Inet6Address ip) {
  byte[] bytes = ip.getAddress();
  return (bytes[0] == (byte) 0x20)
      && (bytes[1] == (byte) 0x01)
      && (bytes[2] == 0)
      && (bytes[3] == 0);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:16,代码来源:InetAddresses.java

示例9: is6to4Address

import java.net.Inet6Address; //导入方法依赖的package包/类
/**
 * Evaluates whether the argument is a 6to4 address.
 *
 * <p>6to4 addresses begin with the {@code "2002::/16"} prefix. The next 32 bits are the IPv4
 * address of the host to which IPv6-in-IPv4 tunneled packets should be routed.
 *
 * <p>For more on 6to4 addresses see section 2 of
 * <a target="_parent" href="http://tools.ietf.org/html/rfc3056#section-2">RFC 3056</a>.
 *
 * @param ip {@link Inet6Address} to be examined for 6to4 address format
 * @return {@code true} if the argument is a 6to4 address
 */
public static boolean is6to4Address(Inet6Address ip) {
  byte[] bytes = ip.getAddress();
  return (bytes[0] == (byte) 0x20) && (bytes[1] == (byte) 0x02);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:17,代码来源:InetAddresses.java

示例10: isIPv6LinkLocalAddress

import java.net.Inet6Address; //导入方法依赖的package包/类
/**
 * Detect LinkLocal IPv6 address where the interface is missing, ie %[0-9].
 * 
 * @see InetAddress#isLinkLocalAddress()
 */
private static boolean isIPv6LinkLocalAddress(Inet6Address addr) {
  byte[] addrBytes = addr.getAddress();
  return ((addrBytes[0] == (byte) 0xfe) && (addrBytes[1] == (byte) 0x80));
}
 
开发者ID:ampool,项目名称:monarch,代码行数:10,代码来源:InternalDistributedSystemJUnitTest.java


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