Java Code Examples for java.net.Inet6Address#isLoopbackAddress()

The following examples show how to use java.net.Inet6Address#isLoopbackAddress() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IPv6ScopeIdMatchUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void processNetworkInterface(NetworkInterface nif) {
    for (InterfaceAddress ifaddr : nif.getInterfaceAddresses()) {
        InetAddress inetAddress = ifaddr.getAddress();
        if (inetAddress instanceof Inet6Address) {
            Inet6Address inet6 = (Inet6Address) inetAddress;
            if (inet6.isLoopbackAddress()) {
                loopbackInterface = nif;
                loopbackAddress = inet6;
            } else if (addresses.containsKey(nif)) {
                addresses.get(nif).add(inet6);
            } else {
                Set<Inet6Address> set = new HashSet<Inet6Address>();
                set.add(inet6);
                addresses.put(nif, set);
            }
        }
    }
}
 
Example 2
Source File: DnsQueryContextManager.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
private IntObjectMap<DnsQueryContext> getOrCreateContextMap(InetSocketAddress nameServerAddr) {
    synchronized (map) {
        final IntObjectMap<DnsQueryContext> contexts = map.get(nameServerAddr);
        if (contexts != null) {
            return contexts;
        }

        final IntObjectMap<DnsQueryContext> newContexts = new IntObjectHashMap<DnsQueryContext>();
        final InetAddress a = nameServerAddr.getAddress();
        final int port = nameServerAddr.getPort();
        map.put(nameServerAddr, newContexts);

        if (a instanceof Inet4Address) {
            // Also add the mapping for the IPv4-compatible IPv6 address.
            final Inet4Address a4 = (Inet4Address) a;
            if (a4.isLoopbackAddress()) {
                map.put(new InetSocketAddress(NetUtil.LOCALHOST6, port), newContexts);
            } else {
                map.put(new InetSocketAddress(toCompactAddress(a4), port), newContexts);
            }
        } else if (a instanceof Inet6Address) {
            // Also add the mapping for the IPv4 address if this IPv6 address is compatible.
            final Inet6Address a6 = (Inet6Address) a;
            if (a6.isLoopbackAddress()) {
                map.put(new InetSocketAddress(NetUtil.LOCALHOST4, port), newContexts);
            } else if (a6.isIPv4CompatibleAddress()) {
                map.put(new InetSocketAddress(toIPv4Address(a6), port), newContexts);
            }
        }

        return newContexts;
    }
}
 
Example 3
Source File: IP46Utils.java    From RipplePower with Apache License 2.0 4 votes vote down vote up
static boolean isLoopback(Inet6Address a) {
	return a.isLoopbackAddress();
}