Package java.net

Examples of java.net.Inet4Address


  }
 
  @Test
  public void testCompareDifferentVersions() throws UnknownHostException {
   
    Inet4Address ipv4 = Inet4AddressComparatorTest.ip("10.10.10.10");
    Inet6Address ipv6 = Inet6AddressComparatorTest.ip("1111:1111:1111:1111:1111:1111:1111:1111");
   
    Assert.assertTrue(V4_LESS.compare(ipv4, ipv6) < 0);
    Assert.assertTrue(V4_LESS.compare(ipv6, ipv4) > 0);
    Assert.assertTrue(V6_LESS.compare(ipv4, ipv6) > 0);
View Full Code Here


         * result in dns lookup, so we don't serialize it.
         */
        kryo.register(Inet4Address.class, new Serializer() {
            @Override
            public void writeObjectData(ByteBuffer buffer, Object object) {
                Inet4Address i4a = (Inet4Address) object;
                kryo.writeObject(buffer, i4a.getAddress());
            }
           
            @Override
            @SuppressWarnings("unchecked")
            public <T> T readObjectData(ByteBuffer buffer, Class<T> type) {
View Full Code Here

   * Get the network address.
   *
   * @return
   */
  public Inet4Address getNetworAddress(String dialServerAddress) {
    Inet4Address selectedInetAddress = null;
    try {
      InterfaceAddress interfaceAddress = null;
      if (dialServerAddress != null) {
        String prefix = dialServerAddress.substring(0, dialServerAddress.indexOf('.') + 1);
        Log.d(LOG_TAG, "prefix=" + prefix);
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

                    boolean addedIp = false;
                    while (!interfaces.isEmpty()) {
                        NetworkInterface intf = interfaces.poll();
                        Enumeration<InetAddress> inetAddrs = intf.getInetAddresses();
                        Inet6Address inet6addr = null;
                        Inet4Address inet4addr = null;
                        while (inetAddrs.hasMoreElements()) {
                            InetAddress addr = inetAddrs.nextElement();
                            if (addr instanceof Inet6Address) {
                                inet6addr = (Inet6Address)addr;
                                if (inet6addr.isLinkLocalAddress()) {
                                    inet6addr = null;
                                }
                            } else if (addr instanceof Inet4Address) {
                                inet4addr = (Inet4Address)addr;
                            }
                        }
                        if (inet4addr != null) {
                            stringer.value(inet4addr.getHostAddress());
                            addedIp = true;
                        }
                        if (inet6addr != null) {
                            stringer.value(inet6addr.getHostAddress());
                            addedIp = true;
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

        assertAddressToLong("202.12.128.254", 3389817086L);
    }

    private static void assertAddressToLong(String address, long ip)
    {
        Inet4Address addr = (Inet4Address) InetAddresses.forString(address);
        assertEquals(Inet4Network.addressToLong(addr), ip);
    }
View Full Code Here

        assertFromAddress("208.86.202.0", "208.86.202.0/24", 24);
    }

    private static void assertFromAddress(String address, String cidr, int bits)
    {
        Inet4Address addr = (Inet4Address) InetAddresses.forString(address);
        assertEquals(Inet4Network.fromAddress(addr, bits), Inet4Network.fromCidr(cidr));
    }
View Full Code Here

        assertTruncatedFromAddress("208.86.202.0", "208.86.202.0/24", 24);
    }

    private static void assertTruncatedFromAddress(String address, String cidr, int bits)
    {
        Inet4Address addr = (Inet4Address) InetAddresses.forString(address);
        assertEquals(Inet4Network.truncatedFromAddress(addr, bits), Inet4Network.fromCidr(cidr));
    }
View Full Code Here

        assertFalse(containsAddress("202.12.128.0/18", "202.12.192.0"));
    }

    private static boolean containsAddress(String cidr, String address)
    {
        Inet4Address addr = (Inet4Address) InetAddresses.forString(address);
        return Inet4Network.fromCidr(cidr).containsAddress(addr);
    }
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.