lib/resolv-replace.rb


DEFINITIONS

This source file includes following functions.


   1  require 'resolv'
   2  
   3  class BasicSocket
   4    alias original_resolv_send send
   5    def send(mesg, flags, *rest)
   6      rest[0] = Resolv.getaddress(rest[0]).to_s if 0 < rest.length
   7      original_resolv_send(mesg, flags, *rest)
   8    end
   9  end
  10  
  11  class << IPSocket
  12    alias original_resolv_getaddress getaddress
  13    def getaddress(host)
  14      return Resolv.getaddress(host).to_s
  15    end
  16  end
  17  
  18  class << TCPSocket
  19    alias original_resolv_new new
  20    def new(host, service)
  21      original_resolv_new(Resolv.getaddress(host).to_s, service)
  22    end
  23  
  24    alias original_resolv_open open
  25    def open(host, service)
  26      original_resolv_open(Resolv.getaddress(host).to_s, service)
  27    end
  28  end
  29  
  30  class UDPSocket
  31    alias original_resolv_connect connect
  32    def connect(host, port)
  33      original_resolv_connect(Resolv.getaddress(host).to_s, port)
  34    end
  35  
  36    alias original_resolv_send send
  37    def send(mesg, flags, *rest)
  38      rest[0] = Resolv.getaddress(rest[0]).to_s if 0 < rest.length
  39      original_resolv_send(mesg, flags, *rest)
  40    end
  41  end