1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/resolv-replace.rb (BasicSocket#send): don't replace because

it has no hostname argument.
  (IPSocket.getaddress): raise SocketError instead of
  Resolv::ResolvError for errors.
  (TCPSocket#initialize, UDPSocket#bind, UDPSocket#connect)
  (SOCKSSocket#initialize): use IPSocket.getaddress instead of
  Resolv.getaddress.
  (UDPSocket#send): recognize 3 arguments form.  try all addresses on
  4 arguments form.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5605 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2004-02-01 15:21:24 +00:00
parent 0967d72815
commit c9c51009cf
2 changed files with 41 additions and 16 deletions

View file

@ -1,4 +1,17 @@
Mon Feb 2 00:01:19 2004 Tanaka Akira <akr@m17n.org>
* lib/resolv-replace.rb (BasicSocket#send): don't replace because
it has no hostname argument.
(IPSocket.getaddress): raise SocketError instead of
Resolv::ResolvError for errors.
(TCPSocket#initialize, UDPSocket#bind, UDPSocket#connect)
(SOCKSSocket#initialize): use IPSocket.getaddress instead of
Resolv.getaddress.
(UDPSocket#send): recognize 3 arguments form. try all addresses on
4 arguments form.
Sun Feb 1 23:00:00 2004 Shigeo Kobayashi <shigek@ruby-lang.org>
* ext/bigdecimal.c: Bug in BigDecimal("1e#{n}").add BigDecimal('.5'),n)
reported and fixed by Javier Goizueta.

View file

@ -1,50 +1,62 @@
require 'socket'
require 'resolv'
class BasicSocket
alias original_resolv_send send
def send(mesg, flags, *rest)
rest[0] = Resolv.getaddress(rest[0]).to_s unless rest.empty?
original_resolv_send(mesg, flags, *rest)
end
end
class << IPSocket
alias original_resolv_getaddress getaddress
def getaddress(host)
return Resolv.getaddress(host).to_s
begin
return Resolv.getaddress(host).to_s
rescue Resolv::ResolvError
raise SocketError, "Name or service not known: #{host}"
end
end
end
class TCPSocket
alias original_resolv_initialize initialize
def initialize(host, serv, *rest)
rest[0] = Resolv.getaddress(rest[0]).to_s unless rest.empty?
original_resolv_initialize(Resolv.getaddress(host).to_s, serv, *rest)
rest[0] = IPSocket.getaddress(rest[0]) unless rest.empty?
original_resolv_initialize(IPSocket.getaddress(host), serv, *rest)
end
end
class UDPSocket
alias original_resolv_bind bind
def bind(host, port)
original_resolv_bind(Resolv.getaddress(host).to_s, port)
original_resolv_bind(IPSocket.getaddress(host), port)
end
alias original_resolv_connect connect
def connect(host, port)
original_resolv_connect(Resolv.getaddress(host).to_s, port)
original_resolv_connect(IPSocket.getaddress(host), port)
end
alias original_resolv_send send
def send(mesg, flags, *rest)
rest[0] = Resolv.getaddress(rest[0]).to_s unless rest.empty?
original_resolv_send(mesg, flags, *rest)
if rest.length == 2
host, port = rest
begin
addrs = Resolv.getaddresses(host)
rescue Resolv::ResolvError
raise SocketError, "Name or service 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
end
class SOCKSSocket
alias original_resolv_initialize initialize
def initialize(host, serv)
original_resolv_initialize(Resolv.getaddress(host).to_s, port)
original_resolv_initialize(IPSocket.getaddress(host), port)
end
end if defined? SOCKSSocket