Search in sources :

Example 41 with Inet6Address

use of java.net.Inet6Address in project android_frameworks_base by DirtyUnicorns.

the class NetworkDiagnostics method prepareExplicitSourceIcmpMeasurements.

private void prepareExplicitSourceIcmpMeasurements(InetAddress target) {
    for (LinkAddress l : mLinkProperties.getLinkAddresses()) {
        InetAddress source = l.getAddress();
        if (source instanceof Inet6Address && l.isGlobalPreferred()) {
            Pair<InetAddress, InetAddress> srcTarget = new Pair<>(source, target);
            if (!mExplicitSourceIcmpChecks.containsKey(srcTarget)) {
                Measurement measurement = new Measurement();
                measurement.thread = new Thread(new IcmpCheck(source, target, measurement));
                mExplicitSourceIcmpChecks.put(srcTarget, measurement);
            }
        }
    }
}
Also used : LinkAddress(android.net.LinkAddress) Inet6Address(java.net.Inet6Address) InetAddress(java.net.InetAddress) Pair(android.util.Pair)

Example 42 with Inet6Address

use of java.net.Inet6Address in project android_frameworks_base by DirtyUnicorns.

the class IPv6TetheringInterfaceServices method updateUpstreamIPv6LinkProperties.

// IPv6TetheringCoordinator sends updates with carefully curated IPv6-only
// LinkProperties. These have extraneous data filtered out and only the
// necessary prefixes included (per its prefix distribution policy).
//
// TODO: Evaluate using a data structure than is more directly suited to
// communicating only the relevant information.
public void updateUpstreamIPv6LinkProperties(LinkProperties v6only) {
    if (mRaDaemon == null)
        return;
    // Avoid unnecessary work on spurious updates.
    if (Objects.equals(mLastIPv6LinkProperties, v6only)) {
        return;
    }
    RaParams params = null;
    if (v6only != null) {
        params = new RaParams();
        params.mtu = v6only.getMtu();
        params.hasDefaultRoute = v6only.hasIPv6DefaultRoute();
        for (LinkAddress linkAddr : v6only.getLinkAddresses()) {
            if (linkAddr.getPrefixLength() != RFC7421_IP_PREFIX_LENGTH)
                continue;
            final IpPrefix prefix = new IpPrefix(linkAddr.getAddress(), linkAddr.getPrefixLength());
            params.prefixes.add(prefix);
            final Inet6Address dnsServer = getLocalDnsIpFor(prefix);
            if (dnsServer != null) {
                params.dnses.add(dnsServer);
            }
        }
    }
    // If v6only is null, we pass in null to setRaParams(), which handles
    // deprecation of any existing RA data.
    setRaParams(params);
    mLastIPv6LinkProperties = v6only;
}
Also used : LinkAddress(android.net.LinkAddress) IpPrefix(android.net.IpPrefix) RaParams(android.net.ip.RouterAdvertisementDaemon.RaParams) Inet6Address(java.net.Inet6Address)

Example 43 with Inet6Address

use of java.net.Inet6Address in project jdk8u_jdk by JetBrains.

the class LookupIPv6 method main.

public static void main(String[] args) throws Exception {
    // use loopback IPv6 address to avoid lengthy socket connection delays
    String[] urls = { "rmi://[0000:0000:0000:0000:0000:0000:0000:0001]/foo", "//[0:0:0:0:0:0:0:1]:88/foo", "rmi://[0::0:0:0:1]/foo:bar", "//[::1]:88" };
    for (int i = 0; i < urls.length; i++) {
        try {
            Naming.lookup(urls[i]);
        } catch (MalformedURLException ex) {
            throw ex;
        } catch (Exception ex) {
        // URLs are bogus, lookups expected to fail
        }
    }
    /* Attempt to use IPv6-based URL to look up object in local registry.
         * Since not all platforms support IPv6, this portion of the test may
         * be a no-op in some cases.  On supporting platforms, the first
         * element of the array returned by InetAddress.getAllByName should be
         * an Inet6Address since this test is run with
         * -Djava.net.preferIPv6Addresses=true.
         */
    InetAddress localAddr = InetAddress.getAllByName(null)[0];
    if (localAddr instanceof Inet6Address) {
        System.out.println("IPv6 detected");
        Registry reg;
        try {
            reg = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
        } catch (Exception ex) {
            reg = LocateRegistry.getRegistry();
        }
        reg.rebind("foo", reg);
        Naming.lookup("rmi://[" + localAddr.getHostAddress() + "]/foo");
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) Inet6Address(java.net.Inet6Address) LocateRegistry(java.rmi.registry.LocateRegistry) Registry(java.rmi.registry.Registry) InetAddress(java.net.InetAddress) MalformedURLException(java.net.MalformedURLException)

Example 44 with Inet6Address

use of java.net.Inet6Address in project jdk8u_jdk by JetBrains.

the class MockE1000g0Inet6Address method testSerializedLo0Inet6Address.

static void testSerializedLo0Inet6Address() throws IOException {
    System.err.println("\n testSerializedLo0Inet6Address:  enter \n");
    boolean testWithNetIf = true;
    boolean useMockInet6Address = false;
    NetworkInterface testNetIf = NetworkInterface.getByName(NETWORK_IF_LO0);
    Inet6Address expectedInet6Address = null;
    if (testNetIf != null) {
        System.err.println("\n testSerializedLo0Inet6Address:  using netif \n");
        try {
            expectedInet6Address = Inet6Address.getByAddress(LOCALHOSTNAME, LOOPBACKIPV6ADDRESS, testNetIf);
        } catch (UnknownHostException ukhEx) {
            ukhEx.printStackTrace();
            testWithNetIf = true;
            useMockInet6Address = true;
        }
    } else {
        System.err.println("\n testSerializedLo0Inet6Address:  using index \n");
        try {
            expectedInet6Address = Inet6Address.getByAddress(LOCALHOSTNAME, LOOPBACKIPV6ADDRESS, SCOPE_ID_ZERO);
        } catch (UnknownHostException ukhEx1) {
            ukhEx1.printStackTrace();
            useMockInet6Address = true;
        }
        testWithNetIf = false;
    }
    // displayExpectedInet6Address(expectedInet6Address);
    byte[] serializedAddress = SerialData_ifname_lo0;
    try (ByteArrayInputStream bis = new ByteArrayInputStream(serializedAddress);
        ObjectInputStream oin = new ObjectInputStream(bis)) {
        Inet6Address deserializedIPV6Addr = (Inet6Address) oin.readObject();
        System.err.println("Deserialized Inet6Address " + deserializedIPV6Addr);
        if (!useMockInet6Address) {
            assertHostNameEqual(expectedInet6Address.getHostName(), deserializedIPV6Addr.getHostName());
            if (testWithNetIf) {
                assertHostAddressEqual(expectedInet6Address.getHostAddress(), deserializedIPV6Addr.getHostAddress());
            } else {
                assertHostAddressEqual(MockLo0Inet6Address.getBareHostAddress(), deserializedIPV6Addr.getHostAddress());
            }
            assertAddressEqual(expectedInet6Address.getAddress(), deserializedIPV6Addr.getAddress());
            assertScopeIdEqual(expectedInet6Address.getScopeId(), deserializedIPV6Addr.getScopeId());
            if (testWithNetIf) {
                assertNetworkInterfaceEqual(expectedInet6Address.getScopedInterface(), deserializedIPV6Addr.getScopedInterface());
            } else {
                assertNetworkInterfaceEqual(null, deserializedIPV6Addr.getScopedInterface());
            }
        } else {
            // use MockLo0Inet6Address
            assertHostNameEqual(MockLo0Inet6Address.getHostName(), deserializedIPV6Addr.getHostName());
            if (testWithNetIf) {
                assertHostAddressEqual(MockLo0Inet6Address.getHostAddress(), deserializedIPV6Addr.getHostAddress());
            } else {
                assertHostAddressEqual(MockLo0Inet6Address.getHostAddressWithIndex(), deserializedIPV6Addr.getHostAddress());
            }
            assertAddressEqual(MockLo0Inet6Address.getAddress(), deserializedIPV6Addr.getAddress());
            if (testWithNetIf) {
                assertScopeIdEqual(MockLo0Inet6Address.getScopeId(), deserializedIPV6Addr.getScopeId());
            } else {
                assertScopeIdEqual(MockLo0Inet6Address.getScopeZero(), deserializedIPV6Addr.getScopeId());
            }
            assertNetworkInterfaceNameEqual(MockLo0Inet6Address.getScopeIfName(), deserializedIPV6Addr.getScopedInterface());
        }
    } catch (Exception e) {
        System.err.println("Exception caught during deserialization");
        failed = true;
        e.printStackTrace();
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) ByteArrayInputStream(java.io.ByteArrayInputStream) NetworkInterface(java.net.NetworkInterface) Inet6Address(java.net.Inet6Address) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) FileNotFoundException(java.io.FileNotFoundException) ObjectInputStream(java.io.ObjectInputStream)

Example 45 with Inet6Address

use of java.net.Inet6Address in project jdk8u_jdk by JetBrains.

the class MockE1000g0Inet6Address method getAllInet6Addresses.

static List<Inet6Address> getAllInet6Addresses() throws Exception {
    // System.err.println("\n getAllInet6Addresses: \n ");
    ArrayList<Inet6Address> inet6Addresses = new ArrayList<Inet6Address>();
    for (Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); e.hasMoreElements(); ) {
        NetworkInterface netIF = e.nextElement();
        for (Enumeration<InetAddress> iadrs = netIF.getInetAddresses(); iadrs.hasMoreElements(); ) {
            InetAddress iadr = iadrs.nextElement();
            if (iadr instanceof Inet6Address) {
                System.err.println("Test NetworkInterface:  " + netIF);
                Inet6Address i6adr = (Inet6Address) iadr;
                System.err.println(" address " + iadr);
                System.err.println(" scoped iface: " + i6adr.getScopedInterface());
                // using this to actually set the hostName for an
                // InetAddress
                // created through the NetworkInterface
                // have found that the fabricated instances has a null
                // hostName
                System.err.println(" hostName: " + i6adr.getHostName());
                inet6Addresses.add(i6adr);
            }
        }
    }
    return inet6Addresses;
}
Also used : ArrayList(java.util.ArrayList) NetworkInterface(java.net.NetworkInterface) Inet6Address(java.net.Inet6Address) InetAddress(java.net.InetAddress)

Aggregations

Inet6Address (java.net.Inet6Address)137 InetAddress (java.net.InetAddress)92 Inet4Address (java.net.Inet4Address)45 NetworkInterface (java.net.NetworkInterface)28 LinkAddress (android.net.LinkAddress)21 IpPrefix (android.net.IpPrefix)19 IOException (java.io.IOException)18 UnknownHostException (java.net.UnknownHostException)17 LinkProperties (android.net.LinkProperties)15 SocketException (java.net.SocketException)15 RouteInfo (android.net.RouteInfo)14 InetSocketAddress (java.net.InetSocketAddress)12 ByteBuffer (java.nio.ByteBuffer)9 HashMap (java.util.HashMap)8 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)7 RaParams (android.net.ip.RouterAdvertisementDaemon.RaParams)5 Pair (android.util.Pair)5 ProvisioningChange (android.net.LinkProperties.ProvisioningChange)4 StructNdMsg (android.net.netlink.StructNdMsg)4