Package java.net

Examples of java.net.Inet6Address


  /**
   * @tests java.net.Inet6Address#isIPv4CompatibleAddress()
   */
  public void test_isIPv4CompatibleAddress() {
    String addrName = "";
    Inet6Address addr = null;

    try {

      // Tests a number of addresses to see if they are compatable with
      // IPv6 addresses

      addrName = "FFFF::42:42"; // 11111111 = FFFF
      addr = (Inet6Address) InetAddress.getByName(addrName);
      assertTrue("A non-compatable IPv6 address " + addrName
          + " incorrectly identified as a IPv4 compatable address.",
          !addr.isIPv4CompatibleAddress());

      // IPv4-compatible IPv6 address tests
      //
      // Now create 2 IP v6 addresses that are IP v4 compatable
      // to IP v6 addresses.

      addrName = "::0.0.0.0";
      addr = (Inet6Address) InetAddress.getByName(addrName);
      assertTrue("IPv4 compatable address " + addrName
          + " not detected correctly.", addr
          .isIPv4CompatibleAddress());

      addrName = "::255.255.255.255"; // an ipv4 non-multicast address
      addr = (Inet6Address) InetAddress.getByName(addrName);
      assertTrue("IPv4 compatable address " + addrName
          + " not detected correctly.", addr
          .isIPv4CompatibleAddress());

    } catch (Exception e) {
      e.printStackTrace();
      fail("Unknown address : " + addrName);
View Full Code Here


  /**
   * @throws UnknownHostException
   * @tests java.net.Inet6Address#getScopeID()
   */
  public void test_getScopeID() throws UnknownHostException {
    Inet6Address v6ia;
    byte[] addr = { (byte) 0xFE, (byte) 0x80, 0, 0, 0, 0, 0, 0, 0x02, 0x11,
        0x25, (byte) 0xFF, (byte) 0xFE, (byte) 0xF8, (byte) 0x7C,
        (byte) 0xB2 };

    v6ia = Inet6Address.getByAddress("123", addr, 3);
    assertEquals(3, v6ia.getScopeId());

    v6ia = Inet6Address.getByAddress("123", addr, 0);
    assertEquals(0, v6ia.getScopeId());

    v6ia = Inet6Address.getByAddress("123", addr, -1);
    assertEquals(0, v6ia.getScopeId());
  }
View Full Code Here

   */
  public void test_getScopedInterface() throws UnknownHostException {
    byte[] addr = { (byte) 0xFE, (byte) 0x80, (byte) 0x09, (byte) 0xb5,
        (byte) 0x6b, (byte) 0xa4, 0, 0, 0, 0, 0, 0, (byte) 0x09,
        (byte) 0xb5, (byte) 0x6b, (byte) 0xa4 };
    Inet6Address v6Addr;
    v6Addr = Inet6Address.getByAddress("123", addr, null);
    assertNull(v6Addr.getScopedInterface());
  }
View Full Code Here

      return LOOPBACK4;  // ::1
    } else if (leadingBytesOfZero && (bytes[15] == 0)) {
      return ANY4;  // ::0
    }

    Inet6Address ip6 = (Inet6Address) ip;
    long addressAsLong = 0;
    if (hasEmbeddedIPv4ClientAddress(ip6)) {
      addressAsLong = getEmbeddedIPv4ClientAddress(ip6).hashCode();
    } else {

      // Just extract the high 64 bits (assuming the rest is user-modifiable).
      addressAsLong = ByteBuffer.wrap(ip6.getAddress(), 0, 8).getLong();
    }

    // Many strategies for hashing are possible.  This might suffice for now.
    int coercedHash = Hashing.murmur3_32().hashLong(addressAsLong).asInt();
View Full Code Here

      // HORNETQ-907 - strip off IPv6 scope-id (if necessary)
      remoteDestination = new InetSocketAddress(host, port);
      InetAddress inetAddress = ((InetSocketAddress) remoteDestination).getAddress();
      if (inetAddress instanceof Inet6Address)
      {
         Inet6Address inet6Address = (Inet6Address) inetAddress;
         if (inet6Address.getScopeId() != 0)
         {
            try
            {
               remoteDestination = new InetSocketAddress(InetAddress.getByAddress(inet6Address.getAddress()), ((InetSocketAddress) remoteDestination).getPort());
            }
            catch (UnknownHostException e)
            {
               throw new IllegalArgumentException(e.getMessage());
            }
View Full Code Here

      // HORNETQ-907 - strip off IPv6 scope-id (if necessary)
      remoteDestination = new InetSocketAddress(host, port);
      InetAddress inetAddress = ((InetSocketAddress) remoteDestination).getAddress();
      if (inetAddress instanceof Inet6Address)
      {
         Inet6Address inet6Address = (Inet6Address) inetAddress;
         if (inet6Address.getScopeId() != 0)
         {
            try
            {
               remoteDestination = new InetSocketAddress(InetAddress.getByAddress(inet6Address.getAddress()), ((InetSocketAddress) remoteDestination).getPort());
            }
            catch (UnknownHostException e)
            {
               throw new IllegalArgumentException(e.getMessage());
            }
View Full Code Here

      return LOOPBACK4;  // ::1
    } else if (leadingBytesOfZero && (bytes[15] == 0)) {
      return ANY4;  // ::0
    }

    Inet6Address ip6 = (Inet6Address) ip;
    long addressAsLong = 0;
    if (hasEmbeddedIPv4ClientAddress(ip6)) {
      addressAsLong = getEmbeddedIPv4ClientAddress(ip6).hashCode();
    } else {

      // Just extract the high 64 bits (assuming the rest is user-modifiable).
      addressAsLong = ByteBuffer.wrap(ip6.getAddress(), 0, 8).getLong();
    }

    // Many strategies for hashing are possible.  This might suffice for now.
    int coercedHash = hash64To32(addressAsLong);
View Full Code Here

      // HORNETQ-907 - strip off IPv6 scope-id (if necessary)
      remoteDestination = new InetSocketAddress(host, port);
      InetAddress inetAddress = ((InetSocketAddress) remoteDestination).getAddress();
      if (inetAddress instanceof Inet6Address)
      {
         Inet6Address inet6Address = (Inet6Address) inetAddress;
         if (inet6Address.getScopeId() != 0)
         {
            try
            {
               remoteDestination = new InetSocketAddress(InetAddress.getByAddress(inet6Address.getAddress()), ((InetSocketAddress) remoteDestination).getPort());
            }
            catch (UnknownHostException e)
            {
               throw new IllegalArgumentException(e.getMessage());
            }
View Full Code Here

    byte[] addr = getInetAddress().getAddress();
    int scopeSize = 0;
    int scopeID = 0;
    if (getInetAddress() instanceof Inet6Address) {
      try {
        Inet6Address ip6Addr = (Inet6Address) getInetAddress();
        Method m = Inet6Address.class.getMethod("getScopeId", null);
        Object scope = m.invoke(ip6Addr, null);
        scopeID = ((Number)scope).intValue();
        scopeSize = 4;
      }
View Full Code Here

           
            if (addr instanceof Inet4Address) {
                Inet4Address addr4 = (Inet4Address)addr;
                ret[2] = r.newFixnum(AF_INET); //AF_INET
            } else if (addr instanceof Inet6Address) {
                Inet6Address addr6 = (Inet6Address)addr;
                ret[2] = r.newFixnum(AF_INET6); //AF_INET
            }
            return r.newArrayNoCopy(ret);
        } catch(UnknownHostException e) {
            throw sockerr(context.getRuntime(), "gethostbyname: name or service not known");
View Full Code Here

TOP

Related Classes of java.net.Inet6Address

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.