Package io.netty.resolver.dns
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 DnsServerAddresses
private static final String
private final Map
<String, DnsServerAddresses> private static final String
private static final String
private static final InternalLogger
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private 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 boolean
nameServerAddressStream
(String hostname) Ask this provider for the name servers to query forhostname
.private static Map
<String, DnsServerAddresses> (package private) static UnixResolverOptions
Parse /etc/resolv.conf and return options of interest, namely: timeout, attempts and ndots.(package private) static UnixResolverOptions
parseEtcResolverOptions
(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 int
parseResIntOption
(String opt, String fullLabel) private static void
parseResOptions
(String line, UnixResolverOptions.Builder builder) (package private) static DnsServerAddressStreamProvider
Attempt to parse/etc/resolv.conf
and files in the/etc/resolver
directory by default.private static void
putIfAbsent
(Map<String, DnsServerAddresses> domainToNameServerStreamMap, String domainName, DnsServerAddresses addresses) private static void
putIfAbsent
(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.conf
and files in the/etc/resolver
directory by default. A failure to parse will returnDefaultDnsServerAddressStreamProvider
. -
nameServerAddressStream
Description copied from interface:DnsServerAddressStreamProvider
Ask this provider for the name servers to query forhostname
.- Specified by:
nameServerAddressStream
in interfaceDnsServerAddressStreamProvider
- Parameters:
hostname
- The hostname for which to lookup the DNS server addressed to use. If this is the finalDnsServerAddressStreamProvider
to be queried then generally empty string or'.'
correspond to the defaultDnsServerAddressStream
.- Returns:
- The
DnsServerAddressStream
which 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.
-