Class: Resolv::DNS::Requester::UnconnectedUDP

Inherits:
Resolv::DNS::Requester show all
Defined in:
lib/resolv.rb

Overview

:nodoc:

Direct Known Subclasses

MDNSOneShot

Defined Under Namespace

Classes: Sender

Instance Method Summary collapse

Methods inherited from Resolv::DNS::Requester

#request, #sender_for

Constructor Details

#initialize(*nameserver_port) ⇒ UnconnectedUDP

Returns a new instance of UnconnectedUDP.


730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
# File 'lib/resolv.rb', line 730

def initialize(*nameserver_port)
  super()
  @nameserver_port = nameserver_port
  @socks_hash = {}
  @socks = []
  nameserver_port.each {|host, port|
    if host.index(':')
      bind_host = "::"
      af = Socket::AF_INET6
    else
      bind_host = "0.0.0.0"
      af = Socket::AF_INET
    end
    next if @socks_hash[bind_host]
    sock = UDPSocket.new(af)
    sock.do_not_reverse_lookup = true
    sock.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined? Fcntl::F_SETFD
    DNS.bind_random_port(sock, bind_host)
    @socks << sock
    @socks_hash[bind_host] = sock
  }
end

Instance Method Details

#closeObject


768
769
770
771
772
773
# File 'lib/resolv.rb', line 768

def close
  super
  @senders.each_key {|service, id|
    DNS.free_request_id(service[0], service[1], id)
  }
end

#recv_reply(readable_socks) ⇒ Object


753
754
755
756
# File 'lib/resolv.rb', line 753

def recv_reply(readable_socks)
  reply, from = readable_socks[0].recvfrom(UDPSize)
  return reply, [from[3],from[1]]
end

#sender(msg, data, host, port = Port) ⇒ Object


758
759
760
761
762
763
764
765
766
# File 'lib/resolv.rb', line 758

def sender(msg, data, host, port=Port)
  service = [host, port]
  id = DNS.allocate_request_id(host, port)
  request = msg.encode
  request[0,2] = [id].pack('n')
  sock = @socks_hash[host.index(':') ? "::" : "0.0.0.0"]
  return @senders[[service, id]] =
    Sender.new(request, data, sock, host, port)
end