summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-04-30 06:19:21 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-04-30 06:19:21 +0000
commit1ab2de5bddd8db1c7a16a66699d7bb344af517bd (patch)
tree76c29b78bb266f246e502efe96744d386f19995c /lib
parent38060327e8cca6955e3066878cc7c20e539feeee (diff)
ipv6
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_3@452 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/ftplib.rb81
-rw-r--r--lib/mkmf.rb7
2 files changed, 79 insertions, 9 deletions
diff --git a/lib/ftplib.rb b/lib/ftplib.rb
index 4cba9c5..9336e0a 100644
--- a/lib/ftplib.rb
+++ b/lib/ftplib.rb
@@ -150,16 +150,23 @@ class FTP
end
def sendport(host, port)
- hbytes = host.split(".")
- pbytes = [port / 256, port % 256]
- bytes = hbytes + pbytes
- cmd = "PORT " + bytes.join(",")
+ af = (@sock.peeraddr)[0]
+ if af == "AF_INET"
+ hbytes = host.split(".")
+ pbytes = [port / 256, port % 256]
+ bytes = hbytes + pbytes
+ cmd = "PORT " + bytes.join(",")
+ elsif af == "AF_INET6"
+ cmd = "EPRT |2|" + host + "|" + sprintf("%d", port) + "|"
+ else
+ raise FTPProtoError, host
+ end
voidcmd(cmd)
end
private :sendport
def makeport
- sock = TCPserver.open(0)
+ sock = TCPserver.open(@sock.addr[3], 0)
port = sock.addr[1]
host = TCPsocket.getaddress(@sock.addr[2])
resp = sendport(host, port)
@@ -167,9 +174,20 @@ class FTP
end
private :makeport
+ def makepasv
+ if @sock.peeraddr[0] == "AF_INET"
+ host, port = parse227(sendcmd("PASV"))
+ else
+ host, port = parse229(sendcmd("EPSV"))
+# host, port = parse228(sendcmd("LPSV"))
+ end
+ return host, port
+ end
+ private :makepasv
+
def transfercmd(cmd)
if @passive
- host, port = parse227(sendcmd("PASV"))
+ host, port = makepasv
conn = open_socket(host, port)
resp = sendcmd(cmd)
if resp[0] != ?1
@@ -541,6 +559,57 @@ class FTP
end
private :parse227
+ def parse228(resp)
+ if resp[0, 3] != "228"
+ raise FTPReplyError, resp
+ end
+ left = resp.index("(")
+ right = resp.index(")")
+ if left == nil or right == nil
+ raise FTPProtoError, resp
+ end
+ numbers = resp[left + 1 .. right - 1].split(",")
+ if numbers[0] == "4"
+ if numbers.length != 9 || numbers[1] != "4" || numbers[2 + 4] != "2"
+ raise FTPProtoError, resp
+ end
+ host = numbers[2, 4].join(".")
+ port = (numbers[7].to_i << 8) + numbers[8].to_i
+ elsif numbers[0] == "6"
+ if numbers.length != 21 || numbers[1] != "16" || numbers[2 + 16] != "2"
+ raise FTPProtoError, resp
+ end
+ v6 = ["", "", "", "", "", "", "", ""]
+ for i in 0 .. 7
+ v6[i] = sprintf("%02x%02x", numbers[(i * 2) + 2].to_i,
+ numbers[(i * 2) + 3].to_i)
+ end
+ host = v6[0, 8].join(":")
+ port = (numbers[19].to_i << 8) + numbers[20].to_i
+ end
+ return host, port
+ end
+ private :parse228
+
+ def parse229(resp)
+ if resp[0, 3] != "229"
+ raise FTPReplyError, resp
+ end
+ left = resp.index("(")
+ right = resp.index(")")
+ if left == nil or right == nil
+ raise FTPProtoError, resp
+ end
+ numbers = resp[left + 1 .. right - 1].split(resp[left + 1, 1])
+ if numbers.length != 4
+ raise FTPProtoError, resp
+ end
+ port = numbers[3].to_i
+ host = (@sock.peeraddr())[3]
+ return host, port
+ end
+ private :parse228
+
def parse257(resp)
if resp[0, 3] != "257"
raise FTPReplyError, resp
diff --git a/lib/mkmf.rb b/lib/mkmf.rb
index fb37cae..f3654c3 100644
--- a/lib/mkmf.rb
+++ b/lib/mkmf.rb
@@ -71,8 +71,9 @@ def xsystem command
print command, "\n"
return system(command)
end
- $stderr.reopen($null)
- $stdout.reopen($null)
+p command
+# $stderr.reopen($null)
+# $stdout.reopen($null)
r = system(command)
$stderr.reopen($orgerr)
$stdout.reopen($orgout)
@@ -83,7 +84,7 @@ def try_link(src, opt="")
cfile = open("conftest.c", "w")
cfile.print src
cfile.close
- xsystem(format(LINK, $CFLAGS, $LDFLAGS, libs))
+ xsystem(format(LINK, $CFLAGS, $LDFLAGS, opt))
end
def try_cpp(src, opt=$CFLAGS)