| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
1
|
|
|
1
|
|
838
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
41
|
|
|
2
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
101
|
|
|
3
|
|
|
|
|
|
|
package Net::INET6Glue::FTP; |
|
4
|
|
|
|
|
|
|
our $VERSION = 0.6; |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
############################################################################ |
|
7
|
|
|
|
|
|
|
# implement EPRT, EPSV for Net::FTP to support IPv6 |
|
8
|
|
|
|
|
|
|
############################################################################ |
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
505
|
use Net::INET6Glue::INET_is_INET6; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
40
|
|
|
11
|
1
|
|
|
1
|
|
1068
|
use Net::FTP; # tested with 2.77, 2.79 |
|
|
1
|
|
|
|
|
22922
|
|
|
|
1
|
|
|
|
|
101
|
|
|
12
|
|
|
|
|
|
|
BEGIN { |
|
13
|
1
|
|
|
1
|
|
4
|
my %tested = map { $_ => 1 } qw(2.77 2.79); |
|
|
2
|
|
|
|
|
7
|
|
|
14
|
1
|
50
|
|
|
|
20
|
warn "Not tested with Net::FTP version $Net::FTP::VERSION" |
|
15
|
|
|
|
|
|
|
if ! $tested{$Net::FTP::VERSION}; |
|
16
|
|
|
|
|
|
|
} |
|
17
|
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
22
|
use Socket; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
637
|
|
|
19
|
1
|
|
|
1
|
|
6
|
use Carp 'croak'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
390
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
if ( defined &Net::FTP::_EPRT ) { |
|
22
|
|
|
|
|
|
|
# Net::SSLGlue::FTP and Net::FTP 2.80 implement IPv6 too |
|
23
|
|
|
|
|
|
|
warn "somebody else already implements FTP IPv6 support - skipping ". |
|
24
|
|
|
|
|
|
|
__PACKAGE__."\n"; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
} else { |
|
27
|
|
|
|
|
|
|
# implement EPRT |
|
28
|
|
|
|
|
|
|
*Net::FTP::_EPRT = sub { |
|
29
|
0
|
|
|
0
|
|
|
shift->command("EPRT", @_)->response() == Net::FTP::CMD_OK |
|
30
|
|
|
|
|
|
|
}; |
|
31
|
|
|
|
|
|
|
*Net::FTP::eprt = sub { |
|
32
|
0
|
0
|
0
|
0
|
|
|
@_ == 1 || @_ == 2 or croak 'usage: $ftp->eprt([PORT])'; |
|
33
|
0
|
|
|
|
|
|
my ($ftp,$port) = @_; |
|
34
|
0
|
|
|
|
|
|
delete ${*$ftp}{net_ftp_intern_port}; |
|
|
0
|
|
|
|
|
|
|
|
35
|
0
|
0
|
|
|
|
|
unless ($port) { |
|
36
|
0
|
|
0
|
|
|
|
my $listen = ${*$ftp}{net_ftp_listen} ||= |
|
|
0
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$Net::INET6Glue::INET_is_INET6::INET6CLASS->new( |
|
38
|
|
|
|
|
|
|
Listen => 1, |
|
39
|
|
|
|
|
|
|
Timeout => $ftp->timeout, |
|
40
|
|
|
|
|
|
|
LocalAddr => $ftp->sockhost, |
|
41
|
|
|
|
|
|
|
); |
|
42
|
0
|
|
|
|
|
|
${*$ftp}{net_ftp_intern_port} = 1; |
|
|
0
|
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
my $fam = ($listen->sockdomain == AF_INET) ? 1:2; |
|
44
|
0
|
|
|
|
|
|
$port = "|$fam|".$listen->sockhost."|".$listen->sockport."|"; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
0
|
|
|
|
|
|
my $ok = $ftp->_EPRT($port); |
|
47
|
0
|
0
|
|
|
|
|
${*$ftp}{net_ftp_port} = $port if $ok; |
|
|
0
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
return $ok; |
|
49
|
|
|
|
|
|
|
}; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# implement EPSV |
|
52
|
|
|
|
|
|
|
*Net::FTP::_EPSV = sub { |
|
53
|
0
|
|
|
0
|
|
|
shift->command("EPSV", @_)->response() == Net::FTP::CMD_OK |
|
54
|
|
|
|
|
|
|
}; |
|
55
|
|
|
|
|
|
|
*Net::FTP::epsv = sub { |
|
56
|
0
|
|
|
0
|
|
|
my $ftp = shift; |
|
57
|
0
|
0
|
|
|
|
|
@_ and croak 'usage: $ftp->epsv()'; |
|
58
|
0
|
|
|
|
|
|
delete ${*$ftp}{net_ftp_intern_port}; |
|
|
0
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
$ftp->_EPSV && $ftp->message =~ m{\(([\x33-\x7e])\1\1(\d+)\1\)} |
|
61
|
0
|
0
|
0
|
|
|
|
? ${*$ftp}{'net_ftp_pasv'} = $2 |
|
62
|
|
|
|
|
|
|
: undef; |
|
63
|
|
|
|
|
|
|
}; |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# redefine PORT and PASV so that they use EPRT and EPSV if necessary |
|
66
|
1
|
|
|
1
|
|
5
|
no warnings 'redefine'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
415
|
|
|
67
|
|
|
|
|
|
|
my $old_port = \&Net::FTP::port; |
|
68
|
|
|
|
|
|
|
*Net::FTP::port =sub { |
|
69
|
0
|
0
|
0
|
0
|
|
|
goto &$old_port if $_[0]->sockdomain == AF_INET or @_<1 or @_>2; |
|
|
|
|
0
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
goto &Net::FTP::eprt; |
|
71
|
|
|
|
|
|
|
}; |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $old_pasv = \&Net::FTP::pasv; |
|
74
|
|
|
|
|
|
|
*Net::FTP::pasv = sub { |
|
75
|
0
|
0
|
0
|
0
|
|
|
goto &$old_pasv if $_[0]->sockdomain == AF_INET or @_<1 or @_>2; |
|
|
|
|
0
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
goto &Net::FTP::epsv; |
|
77
|
|
|
|
|
|
|
}; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# redefined _dataconn to make use of the data it got from EPSV |
|
80
|
|
|
|
|
|
|
# copied and adapted from Net::FTP::_dataconn |
|
81
|
|
|
|
|
|
|
my $old_dataconn = \&Net::FTP::_dataconn; |
|
82
|
|
|
|
|
|
|
*Net::FTP::_dataconn = sub { |
|
83
|
0
|
0
|
|
0
|
|
|
goto &$old_dataconn if $_[0]->sockdomain == AF_INET; |
|
84
|
0
|
|
|
|
|
|
my $ftp = shift; |
|
85
|
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my $pkg = "Net::FTP::" . $ftp->type; |
|
87
|
0
|
|
|
|
|
|
eval "require $pkg"; |
|
88
|
0
|
|
|
|
|
|
$pkg =~ s/ /_/g; |
|
89
|
0
|
|
|
|
|
|
delete ${*$ftp}{net_ftp_dataconn}; |
|
|
0
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my $data; |
|
92
|
0
|
0
|
|
|
|
|
if ( my $port = ${*$ftp}{net_ftp_pasv} ) { |
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
$data = $pkg->new( |
|
94
|
|
|
|
|
|
|
PeerAddr => $ftp->peerhost, |
|
95
|
|
|
|
|
|
|
PeerPort => $port, |
|
96
|
0
|
|
|
|
|
|
LocalAddr => ${*$ftp}{net_ftp_localaddr}, |
|
97
|
|
|
|
|
|
|
); |
|
98
|
|
|
|
|
|
|
} elsif (my $listen = delete ${*$ftp}{net_ftp_listen}) { |
|
99
|
0
|
|
|
|
|
|
$data = $listen->accept($pkg); |
|
100
|
0
|
|
|
|
|
|
close($listen); |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
0
|
0
|
|
|
|
|
return if ! $data; |
|
104
|
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
$data->timeout($ftp->timeout); |
|
106
|
0
|
|
|
|
|
|
${*$ftp}{net_ftp_dataconn} = $data; |
|
|
0
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
${*$data} = ""; |
|
|
0
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
${*$data}{net_ftp_cmd} = $ftp; |
|
|
0
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
${*$data}{net_ftp_blksize} = ${*$ftp}{net_ftp_blksize}; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
return $data; |
|
111
|
|
|
|
|
|
|
}; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1; |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 NAME |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Net::INET6Glue::FTP - adds IPv6 support to L by hotpatching |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
use Net::INET6Glue::FTP; |
|
123
|
|
|
|
|
|
|
use Net::FTP; |
|
124
|
|
|
|
|
|
|
my $ftp = Net::FTP->new( '::1' ); |
|
125
|
|
|
|
|
|
|
$ftp->login(...) |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
This module adds support for IPv6 by hotpatching support for EPRT and EPSV |
|
130
|
|
|
|
|
|
|
commands into L and hotpatching B, B and B<_dataconn> |
|
131
|
|
|
|
|
|
|
methods to make use of EPRT and EPSV on IPv6 connections. |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
It also includes L to make the L |
|
134
|
|
|
|
|
|
|
sockets IPv6 capable. |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
This module is copyright (c) 2008..2014, Steffen Ullrich. |
|
139
|
|
|
|
|
|
|
All Rights Reserved. |
|
140
|
|
|
|
|
|
|
This module is free software. It may be used, redistributed and/or modified |
|
141
|
|
|
|
|
|
|
under the same terms as Perl itself. |