Search in sources :

Example 96 with InetAddress

use of java.net.InetAddress in project elasticsearch by elastic.

the class NetworkUtilsTests method testSortKeyLinkLocal.

/**
     * test private addresses sort before link local addresses
     */
public void testSortKeyLinkLocal() throws Exception {
    InetAddress linkLocal = InetAddress.getByName("fe80::1");
    assert linkLocal.isLinkLocalAddress();
    InetAddress ordinary = InetAddress.getByName("fddd::1");
    assertTrue(NetworkUtils.sortKey(ordinary, true) < NetworkUtils.sortKey(linkLocal, true));
    assertTrue(NetworkUtils.sortKey(ordinary, false) < NetworkUtils.sortKey(linkLocal, false));
}
Also used : InetAddress(java.net.InetAddress)

Example 97 with InetAddress

use of java.net.InetAddress in project elasticsearch by elastic.

the class InetAddressesTests method testForStringIPv4Input.

public void testForStringIPv4Input() throws UnknownHostException {
    String ipStr = "192.168.0.1";
    InetAddress ipv4Addr = null;
    // Shouldn't hit DNS, because it's an IP string literal.
    ipv4Addr = InetAddress.getByName(ipStr);
    assertEquals(ipv4Addr, InetAddresses.forString(ipStr));
    assertTrue(InetAddresses.isInetAddress(ipStr));
}
Also used : InetAddress(java.net.InetAddress)

Example 98 with InetAddress

use of java.net.InetAddress in project elasticsearch by elastic.

the class InetAddressesTests method testForStringIPv6EightColons.

public void testForStringIPv6EightColons() throws UnknownHostException {
    String[] eightColons = { "::7:6:5:4:3:2:1", "::7:6:5:4:3:2:0", "7:6:5:4:3:2:1::", "0:6:5:4:3:2:1::" };
    for (int i = 0; i < eightColons.length; i++) {
        InetAddress ipv6Addr = null;
        // Shouldn't hit DNS, because it's an IP string literal.
        ipv6Addr = InetAddress.getByName(eightColons[i]);
        assertEquals(ipv6Addr, InetAddresses.forString(eightColons[i]));
        assertTrue(InetAddresses.isInetAddress(eightColons[i]));
    }
}
Also used : InetAddress(java.net.InetAddress)

Example 99 with InetAddress

use of java.net.InetAddress in project elasticsearch by elastic.

the class NetworkServiceTests method testPublishAnyLocalV4.

/**
     * ensure specifying wildcard ipv4 address selects reasonable publish address
     */
public void testPublishAnyLocalV4() throws Exception {
    NetworkService service = new NetworkService(Settings.EMPTY, Collections.emptyList());
    InetAddress address = service.resolvePublishHostAddresses(new String[] { "0.0.0.0" });
    assertFalse(address.isAnyLocalAddress());
}
Also used : InetAddress(java.net.InetAddress)

Example 100 with InetAddress

use of java.net.InetAddress in project elasticsearch by elastic.

the class BoundTransportAddressTests method testSerialization.

public void testSerialization() throws Exception {
    InetAddress[] inetAddresses = InetAddress.getAllByName("0.0.0.0");
    List<TransportAddress> transportAddressList = new ArrayList<>();
    for (InetAddress address : inetAddresses) {
        transportAddressList.add(new TransportAddress(address, randomIntBetween(9200, 9299)));
    }
    final BoundTransportAddress transportAddress = new BoundTransportAddress(transportAddressList.toArray(new TransportAddress[0]), transportAddressList.get(0));
    assertThat(transportAddress.boundAddresses().length, equalTo(transportAddressList.size()));
    // serialize
    BytesStreamOutput streamOutput = new BytesStreamOutput();
    transportAddress.writeTo(streamOutput);
    StreamInput in = streamOutput.bytes().streamInput();
    BoundTransportAddress serializedAddress;
    if (randomBoolean()) {
        serializedAddress = BoundTransportAddress.readBoundTransportAddress(in);
    } else {
        serializedAddress = new BoundTransportAddress();
        serializedAddress.readFrom(in);
    }
    assertThat(serializedAddress, not(sameInstance(transportAddress)));
    assertThat(serializedAddress.boundAddresses().length, equalTo(transportAddress.boundAddresses().length));
    assertThat(serializedAddress.publishAddress(), equalTo(transportAddress.publishAddress()));
    TransportAddress[] serializedBoundAddresses = serializedAddress.boundAddresses();
    TransportAddress[] boundAddresses = transportAddress.boundAddresses();
    for (int i = 0; i < serializedBoundAddresses.length; i++) {
        assertThat(serializedBoundAddresses[i], equalTo(boundAddresses[i]));
    }
}
Also used : ArrayList(java.util.ArrayList) StreamInput(org.elasticsearch.common.io.stream.StreamInput) InetAddress(java.net.InetAddress) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput)

Aggregations

InetAddress (java.net.InetAddress)2063 UnknownHostException (java.net.UnknownHostException)377 IOException (java.io.IOException)284 Test (org.junit.Test)272 InetSocketAddress (java.net.InetSocketAddress)240 NetworkInterface (java.net.NetworkInterface)178 ArrayList (java.util.ArrayList)158 SocketException (java.net.SocketException)148 Inet6Address (java.net.Inet6Address)97 HashMap (java.util.HashMap)95 Inet4Address (java.net.Inet4Address)88 Socket (java.net.Socket)73 LinkAddress (android.net.LinkAddress)70 DatagramPacket (java.net.DatagramPacket)67 Token (org.apache.cassandra.dht.Token)67 DatagramSocket (java.net.DatagramSocket)61 RouteInfo (android.net.RouteInfo)56 Map (java.util.Map)55 LinkProperties (android.net.LinkProperties)52 ServerSocket (java.net.ServerSocket)50