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-2-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, this generates an illegal reflective access exception and on Windows, this may * return invalid nameservers of disconnected NICs. */ public class SunJvmResolverConfigProvider extends BaseResolverConfigProvider { public void initialize() throws InitializationException { 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