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