Class UnixResolverDnsServerAddressStreamProvider
java.lang.Object
io.netty.resolver.dns.UnixResolverDnsServerAddressStreamProvider
- All Implemented Interfaces:
DnsServerAddressStreamProvider
public final class UnixResolverDnsServerAddressStreamProvider
extends Object
implements DnsServerAddressStreamProvider
Able to parse files such as /etc/resolv.conf and
/etc/resolver to respect the system default domain servers.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final DnsServerAddressesprivate static final Stringprivate final Map<String, DnsServerAddresses> private static final Stringprivate static final Stringprivate static final InternalLoggerprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Pattern -
Constructor Summary
ConstructorsConstructorDescriptionUnixResolverDnsServerAddressStreamProvider(File etcResolvConf, File... etcResolverFiles) Parse a file of the format /etc/resolv.conf which may contain the default DNS server to use, and also overrides for individual domains.UnixResolverDnsServerAddressStreamProvider(String etcResolvConf, String etcResolverDir) Parse a file of the format /etc/resolv.conf which may contain the default DNS server to use, and also overrides for individual domains. -
Method Summary
Modifier and TypeMethodDescriptionprivate booleannameServerAddressStream(String hostname) Ask this provider for the name servers to query forhostname.private static Map<String, DnsServerAddresses> (package private) static UnixResolverOptionsParse /etc/resolv.conf and return options of interest, namely: timeout, attempts and ndots.(package private) static UnixResolverOptionsparseEtcResolverOptions(File etcResolvConf) Parse a file of the format /etc/resolv.conf and return options of interest, namely: timeout, attempts and ndots.Parse a file of the format /etc/resolv.conf and return the list of search domains found in it or an empty list if not found.parseEtcResolverSearchDomains(File etcResolvConf) Parse a file of the format /etc/resolv.conf and return the list of search domains found in it or an empty list if not found.private static intparseResIntOption(String opt, String fullLabel) private static voidparseResOptions(String line, UnixResolverOptions.Builder builder) (package private) static DnsServerAddressStreamProviderAttempt to parse/etc/resolv.confand files in the/etc/resolverdirectory by default.private static voidputIfAbsent(Map<String, DnsServerAddresses> domainToNameServerStreamMap, String domainName, DnsServerAddresses addresses) private static voidputIfAbsent(Map<String, DnsServerAddresses> domainToNameServerStreamMap, String domainName, List<InetSocketAddress> addresses, boolean rotate)
-
Field Details
-
logger
-
WHITESPACE_PATTERN
-
RES_OPTIONS
-
ETC_RESOLV_CONF_FILE
- See Also:
-
ETC_RESOLVER_DIR
- See Also:
-
NAMESERVER_ROW_LABEL
- See Also:
-
SORTLIST_ROW_LABEL
- See Also:
-
OPTIONS_ROW_LABEL
- See Also:
-
OPTIONS_ROTATE_FLAG
- See Also:
-
DOMAIN_ROW_LABEL
- See Also:
-
SEARCH_ROW_LABEL
- See Also:
-
PORT_ROW_LABEL
- See Also:
-
defaultNameServerAddresses
-
domainToNameServerStreamMap
-
-
Constructor Details
-
UnixResolverDnsServerAddressStreamProvider
public UnixResolverDnsServerAddressStreamProvider(File etcResolvConf, File... etcResolverFiles) throws IOException Parse a file of the format /etc/resolv.conf which may contain the default DNS server to use, and also overrides for individual domains. Also parse list of files of the format /etc/resolver which may contain multiple files to override the name servers used for multiple domains.- Parameters:
etcResolvConf- /etc/resolv.conf.etcResolverFiles- List of files of the format defined in /etc/resolver.- Throws:
IOException- If an error occurs while parsing the input files.
-
UnixResolverDnsServerAddressStreamProvider
public UnixResolverDnsServerAddressStreamProvider(String etcResolvConf, String etcResolverDir) throws IOException Parse a file of the format /etc/resolv.conf which may contain the default DNS server to use, and also overrides for individual domains. Also parse a directory of the format /etc/resolver which may contain multiple files to override the name servers used for multiple domains.- Parameters:
etcResolvConf- /etc/resolv.conf.etcResolverDir- Directory containing files of the format defined in /etc/resolver.- Throws:
IOException- If an error occurs while parsing the input files.
-
-
Method Details
-
parseSilently
Attempt to parse/etc/resolv.confand files in the/etc/resolverdirectory by default. A failure to parse will returnDefaultDnsServerAddressStreamProvider. -
nameServerAddressStream
Description copied from interface:DnsServerAddressStreamProviderAsk this provider for the name servers to query forhostname.- Specified by:
nameServerAddressStreamin interfaceDnsServerAddressStreamProvider- Parameters:
hostname- The hostname for which to lookup the DNS server addressed to use. If this is the finalDnsServerAddressStreamProviderto be queried then generally empty string or'.'correspond to the defaultDnsServerAddressStream.- Returns:
- The
DnsServerAddressStreamwhich should be used to resolvehostname.
-
mayOverrideNameServers
private boolean mayOverrideNameServers() -
parse
- Throws:
IOException
-
putIfAbsent
private static void putIfAbsent(Map<String, DnsServerAddresses> domainToNameServerStreamMap, String domainName, List<InetSocketAddress> addresses, boolean rotate) -
putIfAbsent
private static void putIfAbsent(Map<String, DnsServerAddresses> domainToNameServerStreamMap, String domainName, DnsServerAddresses addresses) -
parseEtcResolverOptions
Parse /etc/resolv.conf and return options of interest, namely: timeout, attempts and ndots.- Returns:
- The options values provided by /etc/resolve.conf.
- Throws:
IOException- If a failure occurs parsing the file.
-
parseEtcResolverOptions
Parse a file of the format /etc/resolv.conf and return options of interest, namely: timeout, attempts and ndots.- Parameters:
etcResolvConf- a file of the format /etc/resolv.conf.- Returns:
- The options values provided by /etc/resolve.conf.
- Throws:
IOException- If a failure occurs parsing the file.
-
parseResOptions
-
parseResIntOption
-
parseEtcResolverSearchDomains
Parse a file of the format /etc/resolv.conf and return the list of search domains found in it or an empty list if not found.- Returns:
- List of search domains.
- Throws:
IOException- If a failure occurs parsing the file.
-
parseEtcResolverSearchDomains
Parse a file of the format /etc/resolv.conf and return the list of search domains found in it or an empty list if not found.- Parameters:
etcResolvConf- a file of the format /etc/resolv.conf.- Returns:
- List of search domains.
- Throws:
IOException- If a failure occurs parsing the file.
-