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));
}
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]"));
}
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());
}
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));
}
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));
}
Aggregations