Search in sources :

Example 31 with Inet6Address

use of java.net.Inet6Address in project guava by google.

the class InetAddressesTest method test6to4Addresses.

public void test6to4Addresses() {
    String[] non6to4Addresses = { "::1.2.3.4", "3ffe::1", "::", "::1" };
    for (int i = 0; i < non6to4Addresses.length; i++) {
        InetAddress ip = InetAddresses.forString(non6to4Addresses[i]);
        assertFalse(InetAddresses.is6to4Address((Inet6Address) ip));
        try {
            InetAddresses.get6to4IPv4Address((Inet6Address) ip);
            fail("IllegalArgumentException expected for '" + non6to4Addresses[i] + "'");
        } catch (IllegalArgumentException expected) {
        // expected behavior
        }
    }
    String valid6to4Address = "2002:0102:0304::1";
    String ipv4Str = "1.2.3.4";
    InetAddress ipv4 = InetAddresses.forString(ipv4Str);
    InetAddress ip = InetAddresses.forString(valid6to4Address);
    assertTrue(InetAddresses.is6to4Address((Inet6Address) ip));
    assertEquals(ipv4, InetAddresses.get6to4IPv4Address((Inet6Address) ip));
}
Also used : Inet6Address(java.net.Inet6Address) InetAddress(java.net.InetAddress)

Example 32 with Inet6Address

use of java.net.Inet6Address in project guava by hceylan.

the class InetAddressesTest method testForUriStringIPv6.

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]"));
}
Also used : Inet6Address(java.net.Inet6Address)

Example 33 with Inet6Address

use of java.net.Inet6Address in project guava by hceylan.

the class InetAddressesTest method testTeredoAddresses.

public void testTeredoAddresses() {
    String[] nonTeredoAddresses = { "::1.2.3.4", "3ffe::1", "::", "::1" };
    for (int i = 0; i < nonTeredoAddresses.length; i++) {
        InetAddress ip = InetAddresses.forString(nonTeredoAddresses[i]);
        assertFalse(InetAddresses.isTeredoAddress((Inet6Address) ip));
        try {
            InetAddresses.getTeredoInfo((Inet6Address) ip);
            fail("IllegalArgumentException expected for '" + nonTeredoAddresses[i] + "'");
        } catch (IllegalArgumentException expected) {
        // expected behavior
        }
    }
    String validTeredoAddress = "2001:0000:4136:e378:8000:63bf:3fff:fdd2";
    String serverStr = "65.54.227.120";
    String clientStr = "192.0.2.45";
    int port = 40000;
    int flags = 0x8000;
    InetAddress ip = InetAddresses.forString(validTeredoAddress);
    assertTrue(InetAddresses.isTeredoAddress((Inet6Address) ip));
    InetAddresses.TeredoInfo teredo = InetAddresses.getTeredoInfo((Inet6Address) ip);
    InetAddress server = InetAddresses.forString(serverStr);
    assertEquals(server, teredo.getServer());
    InetAddress client = InetAddresses.forString(clientStr);
    assertEquals(client, teredo.getClient());
    assertEquals(port, teredo.getPort());
    assertEquals(flags, teredo.getFlags());
}
Also used : Inet6Address(java.net.Inet6Address) InetAddress(java.net.InetAddress)

Example 34 with Inet6Address

use of java.net.Inet6Address in project guava by hceylan.

the class InetAddressesTest method testGetEmbeddedIPv4ClientAddress.

public void testGetEmbeddedIPv4ClientAddress() {
    Inet6Address testIp;
    // Test regular global unicast address.
    testIp = (Inet6Address) InetAddresses.forString("2001:db8::1");
    assertFalse(InetAddresses.hasEmbeddedIPv4ClientAddress(testIp));
    // Test ISATAP address.
    testIp = (Inet6Address) InetAddresses.forString("2001:db8::5efe:102:304");
    assertFalse(InetAddresses.hasEmbeddedIPv4ClientAddress(testIp));
    // Test compat address.
    testIp = (Inet6Address) InetAddresses.forString("::1.2.3.4");
    assertTrue(InetAddresses.hasEmbeddedIPv4ClientAddress(testIp));
    InetAddress ipv4 = InetAddresses.forString("1.2.3.4");
    assertEquals(ipv4, InetAddresses.getEmbeddedIPv4ClientAddress(testIp));
    // Test 6to4 address.
    testIp = (Inet6Address) InetAddresses.forString("2002:0102:0304::1");
    assertTrue(InetAddresses.hasEmbeddedIPv4ClientAddress(testIp));
    ipv4 = InetAddresses.forString("1.2.3.4");
    assertEquals(ipv4, InetAddresses.getEmbeddedIPv4ClientAddress(testIp));
    // Test Teredo address.
    testIp = (Inet6Address) InetAddresses.forString("2001:0000:4136:e378:8000:63bf:3fff:fdd2");
    assertTrue(InetAddresses.hasEmbeddedIPv4ClientAddress(testIp));
    ipv4 = InetAddresses.forString("192.0.2.45");
    assertEquals(ipv4, InetAddresses.getEmbeddedIPv4ClientAddress(testIp));
}
Also used : Inet6Address(java.net.Inet6Address) InetAddress(java.net.InetAddress)

Example 35 with Inet6Address

use of java.net.Inet6Address in project guava by hceylan.

the class InetAddressesTest method test6to4Addresses.

public void test6to4Addresses() {
    String[] non6to4Addresses = { "::1.2.3.4", "3ffe::1", "::", "::1" };
    for (int i = 0; i < non6to4Addresses.length; i++) {
        InetAddress ip = InetAddresses.forString(non6to4Addresses[i]);
        assertFalse(InetAddresses.is6to4Address((Inet6Address) ip));
        try {
            InetAddresses.get6to4IPv4Address((Inet6Address) ip);
            fail("IllegalArgumentException expected for '" + non6to4Addresses[i] + "'");
        } catch (IllegalArgumentException expected) {
        // expected behavior
        }
    }
    String valid6to4Address = "2002:0102:0304::1";
    String ipv4Str = "1.2.3.4";
    InetAddress ipv4 = InetAddresses.forString(ipv4Str);
    InetAddress ip = InetAddresses.forString(valid6to4Address);
    assertTrue(InetAddresses.is6to4Address((Inet6Address) ip));
    assertEquals(ipv4, InetAddresses.get6to4IPv4Address((Inet6Address) ip));
}
Also used : Inet6Address(java.net.Inet6Address) InetAddress(java.net.InetAddress)

Aggregations

Inet6Address (java.net.Inet6Address)137 InetAddress (java.net.InetAddress)92 Inet4Address (java.net.Inet4Address)45 NetworkInterface (java.net.NetworkInterface)28 LinkAddress (android.net.LinkAddress)21 IpPrefix (android.net.IpPrefix)19 IOException (java.io.IOException)18 UnknownHostException (java.net.UnknownHostException)17 LinkProperties (android.net.LinkProperties)15 SocketException (java.net.SocketException)15 RouteInfo (android.net.RouteInfo)14 InetSocketAddress (java.net.InetSocketAddress)12 ByteBuffer (java.nio.ByteBuffer)9 HashMap (java.util.HashMap)8 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)7 RaParams (android.net.ip.RouterAdvertisementDaemon.RaParams)5 Pair (android.util.Pair)5 ProvisioningChange (android.net.LinkProperties.ProvisioningChange)4 StructNdMsg (android.net.netlink.StructNdMsg)4