Class UnixResolverDnsServerAddressStreamProvider

java.lang.Object
io.netty.resolver.dns.UnixResolverDnsServerAddressStreamProvider
All Implemented Interfaces:
DnsServerAddressStreamProvider

public final class UnixResolverDnsServerAddressStreamProvider extends java.lang.Object implements DnsServerAddressStreamProvider
Able to parse files such as /etc/resolv.conf and /etc/resolver to respect the system default domain servers.
  • Field Details

    • logger

      private static final InternalLogger logger
    • WHITESPACE_PATTERN

      private static final java.util.regex.Pattern WHITESPACE_PATTERN
    • RES_OPTIONS

      private static final java.lang.String RES_OPTIONS
    • ETC_RESOLV_CONF_FILE

      private static final java.lang.String ETC_RESOLV_CONF_FILE
      See Also:
    • ETC_RESOLVER_DIR

      private static final java.lang.String ETC_RESOLVER_DIR
      See Also:
    • NAMESERVER_ROW_LABEL

      private static final java.lang.String NAMESERVER_ROW_LABEL
      See Also:
    • SORTLIST_ROW_LABEL

      private static final java.lang.String SORTLIST_ROW_LABEL
      See Also:
    • OPTIONS_ROW_LABEL

      private static final java.lang.String OPTIONS_ROW_LABEL
      See Also:
    • OPTIONS_ROTATE_FLAG

      private static final java.lang.String OPTIONS_ROTATE_FLAG
      See Also:
    • DOMAIN_ROW_LABEL

      private static final java.lang.String DOMAIN_ROW_LABEL
      See Also:
    • SEARCH_ROW_LABEL

      private static final java.lang.String SEARCH_ROW_LABEL
      See Also:
    • PORT_ROW_LABEL

      private static final java.lang.String PORT_ROW_LABEL
      See Also:
    • defaultNameServerAddresses

      private final DnsServerAddresses defaultNameServerAddresses
    • domainToNameServerStreamMap

      private final java.util.Map<java.lang.String, DnsServerAddresses> domainToNameServerStreamMap
  • Constructor Details

    • UnixResolverDnsServerAddressStreamProvider

      public UnixResolverDnsServerAddressStreamProvider(java.io.File etcResolvConf, java.io.File... etcResolverFiles) throws java.io.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:
      java.io.IOException - If an error occurs while parsing the input files.
    • UnixResolverDnsServerAddressStreamProvider

      public UnixResolverDnsServerAddressStreamProvider(java.lang.String etcResolvConf, java.lang.String etcResolverDir) throws java.io.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:
      java.io.IOException - If an error occurs while parsing the input files.
  • Method Details

    • parseSilently

      static DnsServerAddressStreamProvider parseSilently()
      Attempt to parse /etc/resolv.conf and files in the /etc/resolver directory by default. A failure to parse will return DefaultDnsServerAddressStreamProvider.
    • nameServerAddressStream

      public DnsServerAddressStream nameServerAddressStream(java.lang.String hostname)
      Description copied from interface: DnsServerAddressStreamProvider
      Ask this provider for the name servers to query for hostname.
      Specified by:
      nameServerAddressStream in interface DnsServerAddressStreamProvider
      Parameters:
      hostname - The hostname for which to lookup the DNS server addressed to use. If this is the final DnsServerAddressStreamProvider to be queried then generally empty string or '.' correspond to the default DnsServerAddressStream.
      Returns:
      The DnsServerAddressStream which should be used to resolve hostname.
    • mayOverrideNameServers

      private boolean mayOverrideNameServers()
    • parse

      private static java.util.Map<java.lang.String, DnsServerAddresses> parse(java.io.File... etcResolverFiles) throws java.io.IOException
      Throws:
      java.io.IOException
    • putIfAbsent

      private static void putIfAbsent(java.util.Map<java.lang.String, DnsServerAddresses> domainToNameServerStreamMap, java.lang.String domainName, java.util.List<java.net.InetSocketAddress> addresses, boolean rotate)
    • putIfAbsent

      private static void putIfAbsent(java.util.Map<java.lang.String, DnsServerAddresses> domainToNameServerStreamMap, java.lang.String domainName, DnsServerAddresses addresses)
    • parseEtcResolverOptions

      static UnixResolverOptions parseEtcResolverOptions() throws java.io.IOException
      Parse /etc/resolv.conf and return options of interest, namely: timeout, attempts and ndots.
      Returns:
      The options values provided by /etc/resolve.conf.
      Throws:
      java.io.IOException - If a failure occurs parsing the file.
    • parseEtcResolverOptions

      static UnixResolverOptions parseEtcResolverOptions(java.io.File etcResolvConf) throws java.io.IOException
      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:
      java.io.IOException - If a failure occurs parsing the file.
    • parseResOptions

      private static void parseResOptions(java.lang.String line, UnixResolverOptions.Builder builder)
    • parseResIntOption

      private static int parseResIntOption(java.lang.String opt, java.lang.String fullLabel)
    • parseEtcResolverSearchDomains

      static java.util.List<java.lang.String> parseEtcResolverSearchDomains() throws java.io.IOException
      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:
      java.io.IOException - If a failure occurs parsing the file.
    • parseEtcResolverSearchDomains

      static java.util.List<java.lang.String> parseEtcResolverSearchDomains(java.io.File etcResolvConf) throws java.io.IOException
      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:
      java.io.IOException - If a failure occurs parsing the file.