Example usage for io.netty.util NetUtil LOCALHOST6

List of usage examples for io.netty.util NetUtil LOCALHOST6

Introduction

In this page you can find the example usage for io.netty.util NetUtil LOCALHOST6.

Prototype

Inet6Address LOCALHOST6

To view the source code for io.netty.util NetUtil LOCALHOST6.

Click Source Link

Document

The Inet6Address that represents the IPv6 loopback address '::1'

Usage

From source file:io.vertx.core.dns.impl.fix.DnsQueryContextManager.java

License:Apache License

private IntObjectMap<DnsQueryContext> getOrCreateContextMap(InetSocketAddress nameServerAddr) {
    synchronized (map) {
        final IntObjectMap<DnsQueryContext> contexts = map.get(nameServerAddr);
        if (contexts != null) {
            return contexts;
        }// www .  ja  v  a 2s.co m

        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(toCompatAddress(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;
    }
}