Search in sources :

Example 56 with InetAddress

use of java.net.InetAddress in project hazelcast by hazelcast.

the class MemberGroupFactoryTest method createMembersWithHostAwareMetadata.

private Collection<Member> createMembersWithHostAwareMetadata() throws UnknownHostException {
    Collection<Member> members = new HashSet<Member>();
    InetAddress fakeAddress = InetAddress.getLocalHost();
    MemberImpl member1 = new MemberImpl(new Address("192.192.0.1", fakeAddress, 5701), VERSION, true);
    member1.setStringAttribute(PartitionGroupMetaData.PARTITION_GROUP_HOST, "host-1");
    MemberImpl member2 = new MemberImpl(new Address("192.192.0.2", fakeAddress, 5701), VERSION, true);
    member2.setStringAttribute(PartitionGroupMetaData.PARTITION_GROUP_HOST, "host-2");
    MemberImpl member3 = new MemberImpl(new Address("192.192.0.3", fakeAddress, 5701), VERSION, true);
    member3.setStringAttribute(PartitionGroupMetaData.PARTITION_GROUP_HOST, "host-3");
    members.add(member1);
    members.add(member2);
    members.add(member3);
    return members;
}
Also used : Address(com.hazelcast.nio.Address) InetAddress(java.net.InetAddress) MemberImpl(com.hazelcast.instance.MemberImpl) Member(com.hazelcast.core.Member) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet)

Example 57 with InetAddress

use of java.net.InetAddress in project hazelcast by hazelcast.

the class MemberGroupFactoryTest method createMembers.

private Collection<Member> createMembers() throws UnknownHostException {
    Collection<Member> members = new HashSet<Member>();
    InetAddress fakeAddress = InetAddress.getLocalHost();
    members.add(new MemberImpl(new Address("192.192.0.1", fakeAddress, 5701), VERSION, false));
    members.add(new MemberImpl(new Address("192.192.0.1", fakeAddress, 5702), VERSION, false));
    members.add(new MemberImpl(new Address("192.168.3.101", fakeAddress, 5701), VERSION, false));
    members.add(new MemberImpl(new Address("192.168.3.101", fakeAddress, 5702), VERSION, false));
    members.add(new MemberImpl(new Address("172.16.5.11", fakeAddress, 5701), VERSION, false));
    members.add(new MemberImpl(new Address("172.16.5.11", fakeAddress, 5702), VERSION, false));
    members.add(new MemberImpl(new Address("172.123.0.13", fakeAddress, 5701), VERSION, false));
    members.add(new MemberImpl(new Address("172.123.0.13", fakeAddress, 5702), VERSION, false));
    members.add(new MemberImpl(new Address("www.hazelcast.com.tr", fakeAddress, 5701), VERSION, false));
    members.add(new MemberImpl(new Address("www.hazelcast.com.tr", fakeAddress, 5702), VERSION, false));
    members.add(new MemberImpl(new Address("jobs.hazelcast.com", fakeAddress, 5701), VERSION, false));
    members.add(new MemberImpl(new Address("jobs.hazelcast.com", fakeAddress, 5702), VERSION, false));
    members.add(new MemberImpl(new Address("www.hazelcast.org", fakeAddress, 5701), VERSION, false));
    members.add(new MemberImpl(new Address("www.hazelcast.org", fakeAddress, 5702), VERSION, false));
    members.add(new MemberImpl(new Address("download.hazelcast.org", fakeAddress, 5701), VERSION, false));
    members.add(new MemberImpl(new Address("download.hazelcast.org", fakeAddress, 5702), VERSION, false));
    return members;
}
Also used : Address(com.hazelcast.nio.Address) InetAddress(java.net.InetAddress) MemberImpl(com.hazelcast.instance.MemberImpl) Member(com.hazelcast.core.Member) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet)

Example 58 with InetAddress

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

the class InetAddressesTest method testIsMaximum.

public void testIsMaximum() throws UnknownHostException {
    InetAddress address = InetAddress.getByName("255.255.255.254");
    assertFalse(InetAddresses.isMaximum(address));
    address = InetAddress.getByName("255.255.255.255");
    assertTrue(InetAddresses.isMaximum(address));
    address = InetAddress.getByName("ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe");
    assertFalse(InetAddresses.isMaximum(address));
    address = InetAddress.getByName("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
    assertTrue(InetAddresses.isMaximum(address));
}
Also used : InetAddress(java.net.InetAddress)

Example 59 with InetAddress

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

the class InetAddressesTest method testMappedIPv4Addresses.

public void testMappedIPv4Addresses() throws UnknownHostException {
    /*
     * Verify that it is not possible to instantiate an Inet6Address
     * from an "IPv4 mapped" IPv6 address.  Our String-based method can
     * at least identify them, however.
     */
    String mappedStr = "::ffff:192.168.0.1";
    assertTrue(InetAddresses.isMappedIPv4Address(mappedStr));
    InetAddress mapped = InetAddresses.forString(mappedStr);
    assertThat(mapped).isNotInstanceOf(Inet6Address.class);
    assertEquals(InetAddress.getByName("192.168.0.1"), mapped);
    // check upper case
    mappedStr = "::FFFF:192.168.0.1";
    assertTrue(InetAddresses.isMappedIPv4Address(mappedStr));
    mapped = InetAddresses.forString(mappedStr);
    assertThat(mapped).isNotInstanceOf(Inet6Address.class);
    assertEquals(InetAddress.getByName("192.168.0.1"), mapped);
    mappedStr = "0:00:000:0000:0:ffff:1.2.3.4";
    assertTrue(InetAddresses.isMappedIPv4Address(mappedStr));
    mapped = InetAddresses.forString(mappedStr);
    assertThat(mapped).isNotInstanceOf(Inet6Address.class);
    assertEquals(InetAddress.getByName("1.2.3.4"), mapped);
    mappedStr = "::ffff:0102:0304";
    assertTrue(InetAddresses.isMappedIPv4Address(mappedStr));
    mapped = InetAddresses.forString(mappedStr);
    assertThat(mapped).isNotInstanceOf(Inet6Address.class);
    assertEquals(InetAddress.getByName("1.2.3.4"), mapped);
    assertFalse(InetAddresses.isMappedIPv4Address("::"));
    assertFalse(InetAddresses.isMappedIPv4Address("::ffff"));
    assertFalse(InetAddresses.isMappedIPv4Address("::ffff:0"));
    assertFalse(InetAddresses.isMappedIPv4Address("::fffe:0:0"));
    assertFalse(InetAddresses.isMappedIPv4Address("::1:ffff:0:0"));
    assertFalse(InetAddresses.isMappedIPv4Address("foo"));
    assertFalse(InetAddresses.isMappedIPv4Address("192.0.2.1"));
}
Also used : InetAddress(java.net.InetAddress)

Example 60 with InetAddress

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

the class InetAddressesTest method testIsatapAddresses.

public void testIsatapAddresses() {
    InetAddress ipv4 = InetAddresses.forString("1.2.3.4");
    String[] validIsatapAddresses = { "2001:db8::5efe:102:304", // Private Multicast? Not likely.
    "2001:db8::100:5efe:102:304", "2001:db8::200:5efe:102:304", // Public Multicast? Also unlikely.
    "2001:db8::300:5efe:102:304" };
    String[] nonIsatapAddresses = { "::1.2.3.4", "3ffe::1", "::", "::1", "2001:db8::0040:5efe:102:304", "2001:db8::5ffe:102:304", "2001:db8::5eff:102:304", // Teredo address; not ISATAP
    "2001:0:102:203:200:5efe:506:708" };
    for (int i = 0; i < validIsatapAddresses.length; i++) {
        InetAddress ip = InetAddresses.forString(validIsatapAddresses[i]);
        assertTrue(InetAddresses.isIsatapAddress((Inet6Address) ip));
        assertEquals("checking '" + validIsatapAddresses[i] + "'", ipv4, InetAddresses.getIsatapIPv4Address((Inet6Address) ip));
    }
    for (int i = 0; i < nonIsatapAddresses.length; i++) {
        InetAddress ip = InetAddresses.forString(nonIsatapAddresses[i]);
        assertFalse(InetAddresses.isIsatapAddress((Inet6Address) ip));
        try {
            InetAddresses.getIsatapIPv4Address((Inet6Address) ip);
            fail("IllegalArgumentException expected for '" + nonIsatapAddresses[i] + "'");
        } catch (IllegalArgumentException expected) {
        // expected behavior
        }
    }
}
Also used : Inet6Address(java.net.Inet6Address) InetAddress(java.net.InetAddress)

Aggregations

InetAddress (java.net.InetAddress)2225 UnknownHostException (java.net.UnknownHostException)423 IOException (java.io.IOException)295 Test (org.junit.Test)289 InetSocketAddress (java.net.InetSocketAddress)251 NetworkInterface (java.net.NetworkInterface)192 ArrayList (java.util.ArrayList)174 SocketException (java.net.SocketException)154 HashMap (java.util.HashMap)104 Inet6Address (java.net.Inet6Address)103 Inet4Address (java.net.Inet4Address)96 Socket (java.net.Socket)78 DatagramPacket (java.net.DatagramPacket)75 LinkAddress (android.net.LinkAddress)70 DatagramSocket (java.net.DatagramSocket)67 Token (org.apache.cassandra.dht.Token)67 Map (java.util.Map)59 RouteInfo (android.net.RouteInfo)56 LinkProperties (android.net.LinkProperties)52 ServerSocket (java.net.ServerSocket)52