Class: UDPSocket

Inherits:
Object
  • Object
show all
Defined in:
lib/net/dns/resolv-replace.rb

Instance Method Summary collapse

Instance Method Details

#bind(host, port) ⇒ Object



29
30
31
# File 'lib/net/dns/resolv-replace.rb', line 29

def bind(host, port)
  original_resolv_bind(IPSocket.getaddress(host), port)
end

#connect(host, port) ⇒ Object



34
35
36
# File 'lib/net/dns/resolv-replace.rb', line 34

def connect(host, port)
  original_resolv_connect(IPSocket.getaddress(host), port)
end

#original_resolv_bindObject



28
# File 'lib/net/dns/resolv-replace.rb', line 28

alias original_resolv_bind bind

#original_resolv_connectObject



33
# File 'lib/net/dns/resolv-replace.rb', line 33

alias original_resolv_connect connect

#original_resolv_sendObject



38
# File 'lib/net/dns/resolv-replace.rb', line 38

alias original_resolv_send send

#send(mesg, flags, *rest) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/net/dns/resolv-replace.rb', line 39

def send(mesg, flags, *rest)
  if rest.length == 2
    host, port = rest
    begin
      addrs = Resolv.getaddresses(host)
    rescue Resolv::ResolvError
      raise SocketError, "Hostname not known: #{host}"
    end
    err = nil
    addrs[0...-1].each {|addr|
      begin
        return original_resolv_send(mesg, flags, addr, port)
      rescue SystemCallError
      end
    }
    original_resolv_send(mesg, flags, addrs[-1], port)
  else
    original_resolv_send(mesg, flags, *rest)
  end
end