Home / Function/ addNameServers() — netty Function Reference

addNameServers() — netty Function Reference

Architecture documentation for the addNameServers() function in DirContextUtils.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  e6f786c3_a102_5d9f_3a06_48f0cc85bb84["addNameServers()"]
  ecf9deed_d211_8a26_74de_3e6f64680b0b["DirContextUtils"]
  e6f786c3_a102_5d9f_3a06_48f0cc85bb84 -->|defined in| ecf9deed_d211_8a26_74de_3e6f64680b0b
  style e6f786c3_a102_5d9f_3a06_48f0cc85bb84 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

resolver-dns/src/main/java/io/netty/resolver/dns/DirContextUtils.java lines 37–75

    static void addNameServers(List<InetSocketAddress> defaultNameServers, int defaultPort) {
        // Using jndi-dns to obtain the default name servers.
        //
        // See:
        // - https://docs.oracle.com/javase/8/docs/technotes/guides/jndi/jndi-dns.html
        // - https://mail.openjdk.java.net/pipermail/net-dev/2017-March/010695.html
        Hashtable<String, String> env = new Hashtable<String, String>();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsContextFactory");
        env.put("java.naming.provider.url", "dns://");

        try {
            DirContext ctx = new InitialDirContext(env);
            String dnsUrls = (String) ctx.getEnvironment().get("java.naming.provider.url");
            // Only try if not empty as otherwise we will produce an exception
            if (dnsUrls != null && !dnsUrls.isEmpty()) {
                String[] servers = dnsUrls.split(" ");
                for (String server : servers) {
                    try {
                        URI uri = new URI(server);
                        String host = uri.getHost();
                        if (host == null || host.isEmpty()) {
                            logger.debug(
                                    "Skipping a nameserver URI as host portion could not be extracted: {}", server);
                            // If the host portion can not be parsed we should just skip this entry.
                            continue;
                        }
                        int port  = uri.getPort();
                        defaultNameServers.add(SocketUtils.socketAddress(uri.getHost(), port == -1 ?
                                defaultPort : port));
                    } catch (URISyntaxException e) {
                        logger.debug("Skipping a malformed nameserver URI: {}", server, e);
                    }
                }
            }
        } catch (Exception ex) {
            // Will try reflection if this fails.
            logger.debug("Unable to obtain nameservers via InitialDirContext", ex);
        }
    }

Subdomains

Frequently Asked Questions

What does addNameServers() do?
addNameServers() is a function in the netty codebase, defined in resolver-dns/src/main/java/io/netty/resolver/dns/DirContextUtils.java.
Where is addNameServers() defined?
addNameServers() is defined in resolver-dns/src/main/java/io/netty/resolver/dns/DirContextUtils.java at line 37.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free