Package java.net

Examples of java.net.Inet4Address


  public static TeredoInfo getTeredoInfo(Inet6Address ip) {
    Preconditions.checkArgument(isTeredoAddress(ip),
        "Address '%s' is not a Teredo address.", toAddrString(ip));

    byte[] bytes = ip.getAddress();
    Inet4Address server = getInet4Address(Arrays.copyOfRange(bytes, 4, 8));

    int flags = ByteStreams.newDataInput(bytes, 8).readShort() & 0xffff;

    // Teredo obfuscates the mapped client port, per section 4 of the RFC.
    int port = ~ByteStreams.newDataInput(bytes, 10).readShort() & 0xffff;

    byte[] clientBytes = Arrays.copyOfRange(bytes, 12, 16);
    for (int i = 0; i < clientBytes.length; i++) {
      // Teredo obfuscates the mapped client IP, per section 4 of the RFC.
      clientBytes[i] = (byte) ~clientBytes[i];
    }
    Inet4Address client = getInet4Address(clientBytes);

    return new TeredoInfo(server, client, port, flags);
  }
View Full Code Here


  public static TeredoInfo getTeredoInfo(Inet6Address ip) {
    Preconditions.checkArgument(isTeredoAddress(ip),
        "Address '%s' is not a Teredo address.", toAddrString(ip));

    byte[] bytes = ip.getAddress();
    Inet4Address server = getInet4Address(Arrays.copyOfRange(bytes, 4, 8));

    int flags = ByteStreams.newDataInput(bytes, 8).readShort() & 0xffff;

    // Teredo obfuscates the mapped client port, per section 4 of the RFC.
    int port = ~ByteStreams.newDataInput(bytes, 10).readShort() & 0xffff;

    byte[] clientBytes = Arrays.copyOfRange(bytes, 12, 16);
    for (int i = 0; i < clientBytes.length; i++) {
      // Teredo obfuscates the mapped client IP, per section 4 of the RFC.
      clientBytes[i] = (byte) ~clientBytes[i];
    }
    Inet4Address client = getInet4Address(clientBytes);

    return new TeredoInfo(server, client, port, flags);
  }
View Full Code Here

  public static TeredoInfo getTeredoInfo(Inet6Address ip) {
    Preconditions.checkArgument(isTeredoAddress(ip),
        "Address '%s' is not a Teredo address.", ip.getHostAddress());

    byte[] bytes = ip.getAddress();
    Inet4Address server = getInet4Address(copyOfRange(bytes, 4, 8));

    int flags = ByteStreams.newDataInput(bytes, 8).readShort() & 0xffff;

    // Teredo obfuscates the mapped client port, per section 4 of the RFC.
    int port = ~ByteStreams.newDataInput(bytes, 10).readShort() & 0xffff;

    byte[] clientBytes = copyOfRange(bytes, 12, 16);
    for (int i = 0; i < clientBytes.length; i++) {
      // Teredo obfuscates the mapped client IP, per section 4 of the RFC.
      clientBytes[i] = (byte) ~clientBytes[i];
    }
    Inet4Address client = getInet4Address(clientBytes);

    return new TeredoInfo(server, client, port, flags);
  }
View Full Code Here

    InetAddress ip = InetAddresses.forString(ipStr);
    assertEquals("[3ffe::1]", InetAddresses.toUriString(ip));
  }

  public void testForUriStringIPv4() {
    Inet4Address expected = (Inet4Address) InetAddresses.forString("192.168.1.1");
    assertEquals(expected, InetAddresses.forUriString("192.168.1.1"));
  }
View Full Code Here

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

  public void testForUriStringIPv4Mapped() {
    Inet4Address expected = (Inet4Address) InetAddresses.forString("192.0.2.1");
    assertEquals(expected, InetAddresses.forUriString("[::ffff:192.0.2.1]"));
  }
View Full Code Here

  public static TeredoInfo getTeredoInfo(Inet6Address ip) {
    Preconditions.checkArgument(isTeredoAddress(ip),
        "Address '%s' is not a Teredo address.", toAddrString(ip));

    byte[] bytes = ip.getAddress();
    Inet4Address server = getInet4Address(copyOfRange(bytes, 4, 8));

    int flags = ByteStreams.newDataInput(bytes, 8).readShort() & 0xffff;

    // Teredo obfuscates the mapped client port, per section 4 of the RFC.
    int port = ~ByteStreams.newDataInput(bytes, 10).readShort() & 0xffff;

    byte[] clientBytes = copyOfRange(bytes, 12, 16);
    for (int i = 0; i < clientBytes.length; i++) {
      // Teredo obfuscates the mapped client IP, per section 4 of the RFC.
      clientBytes[i] = (byte) ~clientBytes[i];
    }
    Inet4Address client = getInet4Address(clientBytes);

    return new TeredoInfo(server, client, port, flags);
  }
View Full Code Here

    @Test
    public void testExpressionArrayResult() throws Exception
    {
        MuleClient muleClient = new MuleClient(muleContext);

        Inet4Address inetAddress = (Inet4Address) InetAddress.getByName(HOSTNAME);
        MuleMessage result = muleClient.send("vm://expression-transformer.in", inetAddress, null);
        assertThat(result, is(notNullValue()));
        assertThat(result.getPayload(), is(notNullValue()));
        assertThat(result.getPayload(), instanceOf(Object[].class));
       
View Full Code Here

    @Test
    public void testExpressionSingleResult() throws Exception
    {
        MuleClient muleClient = new MuleClient(muleContext);

        Inet4Address inetAddress = (Inet4Address) InetAddress.getByName(HOSTNAME);
        MuleMessage result = muleClient.send("vm://expression-transformer-single.in", inetAddress, null);

        Object payload = (Object) result.getPayload();
        assertThat(result, is(notNullValue()));
        assertThat(result.getPayload(), is(notNullValue()));
View Full Code Here

public class NextInetAddressPolicyTest {

    @Test
    public void canPerformNextOnInetAddress() throws UnknownHostException {
        NextInetAddressSequencingPolicy policy = new NextInetAddressSequencingPolicy();
        Inet4Address current = (Inet4Address) Inet4Address.getByName("126.255.255.255");
        Maybe<Inet4Address> got = policy.next(current);
        Assert.assertEquals("127.0.0.0", got.value().getHostAddress());
    }
View Full Code Here

    }

    @Test
    public void orderIsTheSameAsLongOrder() throws UnknownHostException {
        NextInetAddressSequencingPolicy policy = new NextInetAddressSequencingPolicy();
        Inet4Address former = (Inet4Address) Inet4Address.getByName("127.0.0.1");
        Inet4Address latter = (Inet4Address) Inet4Address.getByName("127.0.0.0");
        Assert.assertEquals(Order.GT.order(), policy.compare(former, latter));
    }
View Full Code Here

TOP

Related Classes of java.net.Inet4Address

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.