Extended maintenance of Ruby versions 1.8.7 and 1.9.2 ended on July 31, 2014. Read more

In Files

  • resolv.rb

Resolv::Hosts

Resolv::Hosts is a hostname resolver that uses the system hosts file.

Constants

DefaultFileName

Public Class Methods

new(filename = DefaultFileName) click to toggle source

Creates a new Resolv::Hosts, using filename for its data source.

 
               # File resolv.rb, line 178
def initialize(filename = DefaultFileName)
  @filename = filename
  @mutex = Mutex.new
  @initialized = nil
end
            

Public Instance Methods

each_address(name, &proc) click to toggle source

Iterates over all IP addresses for name retrieved from the hosts file.

 
               # File resolv.rb, line 235
def each_address(name, &proc)
  lazy_initialize
  if @name2addr.include?(name)
    @name2addr[name].each(&proc)
  end
end
            
each_name(address, &proc) click to toggle source

Iterates over all hostnames for address retrieved from the hosts file.

 
               # File resolv.rb, line 262
def each_name(address, &proc)
  lazy_initialize
  if @addr2name.include?(address)
    @addr2name[address].each(&proc)
  end
end
            
getaddress(name) click to toggle source

Gets the IP address of name from the hosts file.

 
               # File resolv.rb, line 218
def getaddress(name)
  each_address(name) {|address| return address}
  raise ResolvError.new("#{@filename} has no name: #{name}")
end
            
getaddresses(name) click to toggle source

Gets all IP addresses for name from the hosts file.

 
               # File resolv.rb, line 226
def getaddresses(name)
  ret = []
  each_address(name) {|address| ret << address}
  return ret
end
            
getname(address) click to toggle source

Gets the hostname of address from the hosts file.

 
               # File resolv.rb, line 245
def getname(address)
  each_name(address) {|name| return name}
  raise ResolvError.new("#{@filename} has no address: #{address}")
end
            
getnames(address) click to toggle source

Gets all hostnames for address from the hosts file.

 
               # File resolv.rb, line 253
def getnames(address)
  ret = []
  each_name(address) {|name| ret << name}
  return ret
end