Package java.net

Examples of java.net.Inet6Address


            } catch (UnknownHostException e) {
                throw new IllegalArgumentException();
            }
            return addr.getHostAddress();
        } else {
            Inet6Address addr;
            try {
                addr = (Inet6Address) InetAddress.getByAddress(b);
            } catch (UnknownHostException e) {
                throw new IllegalArgumentException();
            }
            return addr.getHostAddress();
        }
    }
View Full Code Here


    Inet4Address expected = (Inet4Address) InetAddresses.forString("192.168.1.1");
    assertEquals(expected, InetAddresses.forUriString("192.168.1.1"));
  }

  public void testForUriStringIPv6() {
    Inet6Address expected = (Inet6Address) InetAddresses.forString("3ffe:0:0:0:0:0:0:1");
    assertEquals(expected, InetAddresses.forUriString("[3ffe:0:0:0:0:0:0:1]"));
  }
View Full Code Here

      }
    }
  }

  public void testGetEmbeddedIPv4ClientAddress() {
    Inet6Address testIp;

    // Test regular global unicast address.
    testIp = (Inet6Address) InetAddresses.forString("2001:db8::1");
    assertFalse(InetAddresses.hasEmbeddedIPv4ClientAddress(testIp));
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

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

                // 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());
  }
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

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

    Inet6Address ip6 = (Inet6Address) ip;
    long addressAsLong = 0;
    if (hasEmbeddedIPv4ClientAddress(ip6)) {
      addressAsLong = (long) 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

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.