Module: EventMachine::DnsResolver

Defined in:
lib/em-dns-resolver.rb

Defined Under Namespace

Classes: DnsSocket, Request, RequestIdAlreadyUsed

Constant Summary collapse

Port =

Global interface

53

Class Method Summary collapse

Class Method Details

.nameserver_portObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/em-dns-resolver.rb', line 45

def self.nameserver_port
  return @nameserver_port if defined? @nameserver_port
  config_hash = ::Resolv::DNS::Config.default_config_hash
  @nameserver_port = if config_hash.include? :nameserver
    [ config_hash[:nameserver].first, Port ]
  elsif config_hash.include? :nameserver_port
    config_hash[:nameserver_port].first
  else
    [ '0.0.0.0', Port ]
  end
end

.nameserver_port=(ns_p) ⇒ Object



42
43
44
# File 'lib/em-dns-resolver.rb', line 42

def self.nameserver_port= (ns_p)
  @nameserver_port = ns_p
end

.resolve(hostname) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/em-dns-resolver.rb', line 12

def self.resolve(hostname)
  type = Resolv::DNS::Resource::IN::A
  if ::Resolv::AddressRegex =~ hostname
    # hostname contains an IP address, nothing to resolve
    Request.new(nil, hostname, type)
  else
    Request.new(socket, hostname, type)
  end
end

.reverse(address) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/em-dns-resolver.rb', line 22

def self.reverse(address)
  case address
  when Resolv::IPv4::Regex
    ptr = Resolv::IPv4.create(address).to_name
  when Resolv::IPv6::Regex
    ptr = Resolv::IPv6.create(address).to_name
  else
    raise ArgumentError, "invalid address: #{address}"
  end
  Request.new(socket, ptr, Resolv::DNS::Resource::IN::PTR)
end

.socketObject



34
35
36
37
38
39
40
# File 'lib/em-dns-resolver.rb', line 34

def self.socket
  if defined?(@socket) && @socket.connected?
    @socket
  else
    @socket = DnsSocket.open
  end
end