ftp.rb: use Addrinfo
* lib/net/ftp.rb (sendport, makeport, makepasv, BufferedSocket): use Addrinfo interfaces. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56794 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f46a43fc58
commit
9d6569ff40
@ -381,10 +381,10 @@ module Net
|
|||||||
|
|
||||||
# Constructs and send the appropriate PORT (or EPRT) command
|
# Constructs and send the appropriate PORT (or EPRT) command
|
||||||
def sendport(host, port) # :nodoc:
|
def sendport(host, port) # :nodoc:
|
||||||
af = (@sock.peeraddr)[0]
|
remote_address = @sock.remote_address
|
||||||
if af == "AF_INET"
|
if remote_address.ipv4?
|
||||||
cmd = "PORT " + (host.split(".") + port.divmod(256)).join(",")
|
cmd = "PORT " + (host.split(".") + port.divmod(256)).join(",")
|
||||||
elsif af == "AF_INET6"
|
elsif remote_address.ipv6?
|
||||||
cmd = sprintf("EPRT |2|%s|%d|", host, port)
|
cmd = sprintf("EPRT |2|%s|%d|", host, port)
|
||||||
else
|
else
|
||||||
raise FTPProtoError, host
|
raise FTPProtoError, host
|
||||||
@ -395,13 +395,13 @@ module Net
|
|||||||
|
|
||||||
# Constructs a TCPServer socket
|
# Constructs a TCPServer socket
|
||||||
def makeport # :nodoc:
|
def makeport # :nodoc:
|
||||||
TCPServer.open(@sock.addr[3], 0)
|
TCPServer.open(@sock.local_address.ip_address, 0)
|
||||||
end
|
end
|
||||||
private :makeport
|
private :makeport
|
||||||
|
|
||||||
# sends the appropriate command to enable a passive connection
|
# sends the appropriate command to enable a passive connection
|
||||||
def makepasv # :nodoc:
|
def makepasv # :nodoc:
|
||||||
if @sock.peeraddr[0] == "AF_INET"
|
if @sock.remote_address.ipv4?
|
||||||
host, port = parse227(sendcmd("PASV"))
|
host, port = parse227(sendcmd("PASV"))
|
||||||
else
|
else
|
||||||
host, port = parse229(sendcmd("EPSV"))
|
host, port = parse229(sendcmd("EPSV"))
|
||||||
@ -1283,7 +1283,7 @@ module Net
|
|||||||
end
|
end
|
||||||
|
|
||||||
class BufferedSocket < BufferedIO
|
class BufferedSocket < BufferedIO
|
||||||
[:addr, :peeraddr, :send, :shutdown].each do |method|
|
[:local_address, :remote_address, :addr, :peeraddr, :send, :shutdown].each do |method|
|
||||||
define_method(method) { |*args|
|
define_method(method) { |*args|
|
||||||
@io.__send__(method, *args)
|
@io.__send__(method, *args)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user