alias original_resolv_getaddress getaddress
return Resolv.getaddress(host).to_s
rescue Resolv::ResolvError
raise SocketError, "Hostname not known: #{host}"
alias original_resolv_initialize initialize
def initialize(host, serv, *rest)
rest[0] = IPSocket.getaddress(rest[0]) unless rest.empty?
original_resolv_initialize(IPSocket.getaddress(host), serv, *rest)
alias original_resolv_bind bind
host = IPSocket.getaddress(host) if host != ""
original_resolv_bind(host, port)
alias original_resolv_connect connect
original_resolv_connect(IPSocket.getaddress(host), port)
alias original_resolv_send send
def send(mesg, flags, *rest)
addrs = Resolv.getaddresses(host)
rescue Resolv::ResolvError
raise SocketError, "Hostname not known: #{host}"
addrs[0...-1].each {|addr|
return original_resolv_send(mesg, flags, addr, port)
original_resolv_send(mesg, flags, addrs[-1], port)
original_resolv_send(mesg, flags, *rest)
alias original_resolv_initialize initialize
def initialize(host, serv)
original_resolv_initialize(IPSocket.getaddress(host), port)
end if defined? SOCKSSocket