All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.xbill.DNS.config.SunJvmResolverConfigProvider Maven / Gradle / Ivy

There is a newer version: 3.6.2_1
Show newest version
// SPDX-License-Identifier: BSD-3-Clause
package org.xbill.DNS.config;

import java.lang.reflect.Method;
import java.net.InetSocketAddress;
import java.util.List;

/**
 * Resolver config provider that queries the traditional class {@code
 * sun.net.dns.ResolverConfiguration} via reflection.
 *
 * 
    *
  • As of Java 9, generates an illegal reflective access exception. *
  • As of Java 16, adding the JVM flag {@code --add-opens java.base/sun.net.dns=ALL-UNNAMED} is * required. *
  • On Windows, may return invalid nameservers of disconnected NICs before Java 15, JDK-7006496. *
*/ public class SunJvmResolverConfigProvider extends BaseResolverConfigProvider { @Override public void initialize() throws InitializationException { reset(); try { Class resConfClass = Class.forName("sun.net.dns.ResolverConfiguration"); Method open = resConfClass.getDeclaredMethod("open"); Object resConf = open.invoke(null); Method nameserversMethod = resConfClass.getMethod("nameservers"); @SuppressWarnings("unchecked") List jvmNameservers = (List) nameserversMethod.invoke(resConf); for (String ns : jvmNameservers) { addNameserver(new InetSocketAddress(ns, 53)); } Method searchlistMethod = resConfClass.getMethod("searchlist"); @SuppressWarnings("unchecked") List jvmSearchlist = (List) searchlistMethod.invoke(resConf); for (String n : jvmSearchlist) { addSearchPath(n); } } catch (Exception e) { throw new InitializationException(e); } } @Override public boolean isEnabled() { return Boolean.getBoolean("dnsjava.configprovider.sunjvm.enabled"); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy