# Resolv::DNS::Config (Class)

In: | resolv.rb
Parent: | Object

## Methods

generate_candidates generate_timeouts lazy_initialize new resolv single?

## Constants

InitialTimeout | = | 5

## Classes and Modules

Class Resolv::DNS::Config::NXDomain
Class Resolv::DNS::Config::OtherResolvError

## Public Class methods

new(filename="/etc/resolv.conf")

[Source]

    # File resolv.rb, line 707
          def initialize(filename="/etc/resolv.conf")
            @mutex = Mutex.new
            @filename = filename
            @initialized = nil
          end

## Public Instance methods

lazy_initialize()

[Source]

    # File resolv.rb, line 713
          def lazy_initialize
            @mutex.synchronize {
              unless @initialized
                @nameserver = []
                @search = nil
                @ndots = 1
                begin
                  open(@filename) {|f|
                    f.each {|line|
                      line.sub!(/[#;].*/, '')
                      keyword, *args = line.split(/\s+/)
                      args.each { |arg|
                        arg.untaint
                      }
                      next unless keyword
                      case keyword
                      when 'nameserver'
                        @nameserver += args
                      when 'domain'
                        @search = [Label.split(args[0])]
                      when 'search'
                        @search = args.map {|arg| Label.split(arg)}
                      end
                    }
                  }
                rescue Errno::ENOENT
                  if /mswin32|cygwin|mingw|bccwin/ =~ RUBY_PLATFORM
                    search, nameserver = Win32::Resolv.get_resolv_info
                    @search = [search] if search
                    @nameserver = nameserver if nameserver
                  end
                end

                @nameserver = ['0.0.0.0'] if @nameserver.empty?
                unless @search
                  hostname = Socket.gethostname
                  if /\./ =~ hostname
                    @search = [Label.split($')]
                  else
                    @search = [[]]
                  end
                end
                @initialized = true
              end
            }
          end

single?()

[Source]

    # File resolv.rb, line 760
          def single?
            lazy_initialize
            if @nameserver.length == 1
              return @nameserver[0]
            else
              return nil
            end
          end

generate_candidates(name)

[Source]

    # File resolv.rb, line 769
          def generate_candidates(name)
            candidates = nil
            name = Name.create(name)
            if name.absolute?
              candidates = [name]
            else
              if @ndots <= name.length - 1
                candidates = [Name.new(name.to_a)]
              else
                candidates = []
              end
              candidates.concat(@search.map {|domain| Name.new(name.to_a + domain)})
            end
            return candidates
          end

generate_timeouts()

[Source]

    # File resolv.rb, line 787
          def generate_timeouts
            ts = [InitialTimeout]
            ts << ts[-1] * 2 / @nameserver.length
            ts << ts[-1] * 2
            ts << ts[-1] * 2
            return ts
          end

resolv(name) {|candidate, tout, nameserver| ...}

[Source]

    # File resolv.rb, line 795
          def resolv(name)
            candidates = generate_candidates(name)
            timeouts = generate_timeouts
            begin
              candidates.each {|candidate|
                begin
                  timeouts.each {|tout|
                    @nameserver.each {|nameserver|
                      begin
                        yield candidate, tout, nameserver
                      rescue ResolvTimeout
                      end
                    }
                  }
                  raise ResolvError.new("DNS resolv timeout: #{name}")
                rescue NXDomain
                end
              }
            rescue OtherResolvError
              raise ResolvError.new("DNS error: #{$!.message}")
            end
            raise ResolvError.new("DNS resolv error: #{name}")
          end

[Validate]