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