blib/lib/IO/Socket/INET6.pm

filter: Statementstmt 44.0% 89 / 202 Branchbran 20.2% 36 / 178 Conditioncond 30.4% 28 / 92 MC/DCmcdc 10.6% 5 / 47 Subroutinesub 44.4% 12 / 27 Podpod 100% 16 / 16 totaltotal 33.1% 186 / 562 CC 125 SCAR 65.1
CC
125
Cov
32%
configure
1544.1
_sock_info
59.4
sockaddr
20.0
CRAP 669.5
↑ Summary
1 # IO::Socket::INET6.pm
2 #
3 # Copyright (c) 1997-8 Graham Barr <gbarr@pobox.com>. All rights reserved.
4 # This program is free software; you can redistribute it and/or
5 # modify it under the same terms as Perl itself.
6 #
7 # Modified by Rafael Martinez-Torres <rafael.martinez@novagnet.com>
8 # Euro6IX project (www.euro6ix.org) 2003.
9  
10 package IO::Socket::INET6;
11  
12 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 8 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 8 our(@ISA, $VERSION);
18  
19 # Do it so we won't import any symbols from IO::Socket which it does export
20 # by default:
21 #
22 # <LeoNerd> IO::Socket is stupidstupidstupid beyond belief. Despite being an
23 # object class, it has an import method
24 # <LeoNerd> So you have to use IO::Socket ();
25 # <LeoNerd> Having done that, this test is now clean
26 8 ▶use IO::Socket ();
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 8 ▶use Socket (qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
29 AF_INET6 PF_INET6 SOCK_RAW SOCK_STREAM INADDR_ANY SOCK_DGRAM
30 AF_INET SO_REUSEADDR SO_REUSEPORT AF_UNSPEC SO_BROADCAST
31 sockaddr_in
32 )
33 8 );
34  
35 # IO::Socket and Socket already import stuff here - possibly AF_INET6
36 # and PF_INET6 so selectively import things from Socket6.
37 8 ▶use Socket6 (
Subroutine BEGIN: called CC=1 SCAR=0.0
38 8 qw(AI_PASSIVE getaddrinfo
39 sockaddr_in6 unpack_sockaddr_in6_all pack_sockaddr_in6_all in6addr_any)
40 8 );
41  
42 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 8 ▶use Errno;
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 8 @ISA = qw(IO::Socket);
46 8 $VERSION = "2.73";
47 #Purpose: allow protocol independent protocol and original interface.
48  
49 8 ▶my $EINVAL = exists(&Errno::EINVAL) ? Errno::EINVAL() : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists &Errno::EINVAL ? : 8 0 8
50  
51 8 IO::Socket::INET6->register_domain( AF_INET6 );
52  
53  
54 8 my %socket_type = ( tcp => SOCK_STREAM,
55 udp => SOCK_DGRAM,
56 icmp => SOCK_RAW
57 );
58  
59 107 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
60 107 my $class = shift;
61 107 ▶ unshift(@_, "PeerAddr") if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 107 107
62 107 return $class->SUPER::new(@_);
63 }
64  
65 # Parsing analysis:
66 # addr,port,and proto may be syntactically related...
67 107 ▶sub _sock_info {
Subroutine _sock_info: called CC=24 SCAR=40.8
68 107 my($addr,$port,$proto) = @_;
69 107 my $origport = $port;
70 107 my @proto = ();
71 107 my @serv = ();
72  
73 107 ▶ if (defined $addr) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $addr) 4 103 107
74 4 ▶ if (!Socket6::inet_pton(AF_INET6,$addr)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (Socket6::inet_pton(10, $addr)) 2 2 4
75 2 ▶ if($addr =~ s,^\[([\da-fA-F:]+)\]:([\w\(\)/]+)$,$1,) {
Branch: 4 branches
BranchTrueFalseTotal
if ($addr =~ s<^\[([\da-fA-F:]+)\]:([\w\(\)/]+)$>[$1]) { } 0 2 2
elsif ($addr =~ s<^\[(::[\da-fA-F.:]+)\]:([\w\(\)/]+)$>[$1]) { } 0 2 2
elsif ($addr =~ s/^\[([\da-fA-F:]+)\]/$1/) { } 0 2 2
elsif ($addr =~ s[:([\w\(\)/]+)$][]) { } 0 2 2
76 0 $port = $2;
77 } elsif($addr =~ s,^\[(::[\da-fA-F.:]+)\]:([\w\(\)/]+)$,$1,) {
78 0 $port = $2;
79 } elsif($addr =~ s,^\[([\da-fA-F:]+)\],$1,) {
80 0 $port = $origport;
81 } elsif($addr =~ s,:([\w\(\)/]+)$,,) {
82 0 $port = $1
83 }
84 }
85 }
86  
87 # $proto as "string".
88 107 ▶ if(defined $proto && $proto =~ /\D/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $proto and $proto =~ /\D/) 6 101 107
Condition66%2/3
defined $proto and $proto =~ /\D/
!ll&&!rl&&r
10106
MC/DC50%1/2
defined $proto and $proto =~ /\D/
defined $proto $proto =~ /\D/
Truth table66%2/3
A and B
A= defined $protoB= $proto =~ /\D/
ABresult
0X0
100
111
89 6 ▶ if(@proto = getprotobyname($proto)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@proto = getprotobyname $proto) { } 0 6 6
90 0 ▶ $proto = $proto[2] || undef;
Condition0%0/2
$proto[2] || undef
l!l
00
MC/DC0%0/1
$proto[2] || undef
$proto[2]
Truth table0%0/2
A
A= $proto[2]
Aresult
11
00
91 }
92 else {
93 6 $@ = "Bad protocol '$proto'";
94 6 return;
95 }
96 }
97  
98 101 ▶ if(defined $port) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $port) 100 1 101
99 100 ▶ my $defport = ($port =~ s,\((\d+)\)$,,) ? $1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
$port =~ s/\((\d+)\)$// ? : 0 100 100
100 100 my $pnum = ($port =~ m,^(\d+)$,)[0];
101  
102 100 ▶ @serv = getservbyname($port, $proto[0] || "")
Branch: 1 branch
BranchTrueFalseTotal
if $port =~ /\D/ 0 100 100
Condition0%0/2
$proto[0] || ''
l!l
00
MC/DC0%0/1
$proto[0] || ''
$proto[0]
Truth table0%0/2
A
A= $proto[0]
Aresult
11
00
103 if ($port =~ m,\D,);
104  
105 100 ▶ $port = $serv[2] || $defport || $pnum;
Condition33%2/6
$serv[2] || $defport || $pnum
l!l&&r!l&&!r
01000
$serv[2] or $defport
l!l&&r!l&&!r
00100
MC/DC0%0/3
$serv[2] || $defport || $pnum
$serv[2] $defport $pnum
Truth table25%1/4
A or B || C
A= $serv[2]B= $defportC= $pnum
ABCresult
1XX1
01X1
0011
0000
106 100 ▶ unless (defined $port) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $port) 0 100 100
107 0 $@ = "Bad service '$origport'";
108 0 return;
109 }
110  
111 100 ▶ $proto = (getprotobyname($serv[3]))[2] || undef
Branch: 1 branch
BranchTrueFalseTotal
if @serv and not $proto 0 100 100
Condition20%1/5
@serv and not $proto
!ll&&!rl&&r
10000
(getprotobyname $serv[3])[2] || undef
l!l
00
MC/DC0%0/2
@serv and not $proto
@serv not $proto
MC/DC0%0/1
(getprotobyname $serv[3])[2] || undef
(getprotobyname $serv[3])[2]
Truth table33%1/3
A and not(B)
A= @servB= not $proto
ABresult
0X0
100
111
Truth table0%0/2
A
A= (getprotobyname $serv[3])[2]
Aresult
11
00
112 if @serv && !$proto;
113 }
114 #printf "Selected port is $port and proto is $proto \n";
115  
116 101 ▶ return ($addr || undef,
Condition83%5/6
$addr || undef
l!l
1100
$port || undef
l!l
1001
$proto || undef
l!l
0101
MC/DC100%1/1
$addr || undef
$addr
MC/DC100%1/1
$port || undef
$port
MC/DC0%0/1
$proto || undef
$proto
Truth table100%2/2
A
A= $addr
Aresult
11
00
Truth table100%2/2
A
A= $port
Aresult
11
00
Truth table50%1/2
A
A= $proto
Aresult
11
00
117 $port || undef,
118 $proto || undef,
119 );
120  
121 }
122  
123 107 ▶sub _error {
Subroutine _error: called CC=3 SCAR=11.1
124 107 my $sock = shift;
125 107 my $err = shift;
126 {
127 107 local($!);
128 107 my $title = ref($sock).": ";
129 107 ▶ $@ = join("", $_[0] =~ /^$title/ ? "" : $title, @_);
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /^$title/ ? : 0 107 107
130 107 ▶ close($sock)
Branch: 1 branch
BranchTrueFalseTotal
if defined fileno $sock 0 107 107
131 if(defined fileno($sock));
132 }
133 107 $! = $err;
134 107 return undef;
135 }
136  
137 107 ▶sub configure {
Subroutine configure: called CC=64 SCAR=73.4
Pod documented
138 107 my($sock,$arg) = @_;
139  
140 $arg->{LocalAddr} = $arg->{LocalHost}
141 107 ▶ if exists $arg->{LocalHost} && !exists $arg->{LocalAddr};
Branch: 1 branch
BranchTrueFalseTotal
if exists $arg->{"LocalHost"} and not exists $arg->{"LocalAddr"} 0 107 107
Condition33%1/3
exists $arg->{"LocalHost"} and not exists $arg->{"LocalAddr"}
!ll&&!rl&&r
10700
MC/DC0%0/2
exists $arg->{"LocalHost"} and not exists $arg->{"LocalAddr"}
exists $arg->{"LocalHost"} not exists $arg->{"LocalAddr"}
Truth table33%1/3
A and not(B)
A= exists $arg->{"LocalHost"}B= not exists $arg->{"LocalAddr"}
ABresult
0X0
100
111
142 $arg->{PeerAddr} = $arg->{PeerHost}
143 107 ▶ if exists $arg->{PeerHost} && !exists $arg->{PeerAddr};
Branch: 1 branch
BranchTrueFalseTotal
if exists $arg->{"PeerHost"} and not exists $arg->{"PeerAddr"} 0 107 107
Condition33%1/3
exists $arg->{"PeerHost"} and not exists $arg->{"PeerAddr"}
!ll&&!rl&&r
10700
MC/DC0%0/2
exists $arg->{"PeerHost"} and not exists $arg->{"PeerAddr"}
exists $arg->{"PeerHost"} not exists $arg->{"PeerAddr"}
Truth table33%1/3
A and not(B)
A= exists $arg->{"PeerHost"}B= not exists $arg->{"PeerAddr"}
ABresult
0X0
100
111
144  
145 107 my $family = $arg->{Domain};
146 # in case no local and peer is given we prefer AF_INET6
147 # because we are IO::Socket::INET6
148 107 ▶ $family ||= ! $arg->{LocalAddr} && ! $arg->{PeerAddr} && AF_INET6
Condition90%9/10
$family ||= !($arg->{"LocalAddr"} || $arg->{"PeerAddr"}) && 10 || 0
l!l&&r!l&&!r
11033
!($arg->{'LocalAddr'} || $arg->{'PeerAddr'}) && 10 || 0
l!l
1033
not $arg->{"LocalAddr"} || $arg->{"PeerAddr"} and 10
!ll
3103
$arg->{'LocalAddr'} || $arg->{'PeerAddr'}
l!l&&r!l&&!r
30103
MC/DC0%0/3
$family ||= !($arg->{"LocalAddr"} || $arg->{"PeerAddr"}) && 10 || 0
$family $arg->{'LocalAddr'} $arg->{'PeerAddr'}
Truth table0%0/4
A ||= not(B || C)
A= $familyB= $arg->{'LocalAddr'}C= $arg->{'PeerAddr'}
ABCresult
1XX1
0001
01X0
0010
149 || AF_UNSPEC;
150  
151 # parse Local*
152 my ($laddr,$lport,$proto) = _sock_info(
153 $arg->{LocalAddr},
154 $arg->{LocalPort},
155 $arg->{Proto}
156 107 ▶ ) or return _error($sock, $!, "sock_info: $@");
Branch: 1 branch
BranchTrueFalseTotal
() = _sock_info($arg->{"LocalAddr"}, $arg->{"LocalPort"}, $arg->{"Proto"}) or return _error($sock, $!, "sock_info: $@") 101 6 107
157 101 ▶ $laddr ||= '';
Condition100%2/2
$laddr ||= ""
l!l
1100
MC/DC100%1/1
$laddr ||= ""
$laddr
Truth table100%2/2
A
A= $laddr
Aresult
11
00
158 101 ▶ $lport ||= 0;
Condition100%2/2
$lport ||= 0
l!l
1001
MC/DC100%1/1
$lport ||= 0
$lport
Truth table100%2/2
A
A= $lport
Aresult
11
00
159 101 ▶ $proto ||= (getprotobyname('tcp'))[2];
Condition33%1/3
$proto ||= (getprotobyname "tcp")[2]
l!l&&r!l&&!r
00101
MC/DC0%0/2
$proto ||= (getprotobyname "tcp")[2]
$proto (getprotobyname "tcp")[2]
Truth table33%1/3
A ||= B
A= $protoB= (getprotobyname "tcp")[2]
ABresult
1X1
011
000
160  
161  
162 # MSWin32 expects at least one of $laddr or $lport to be specified
163 # and does not accept 0 for $lport if $laddr is specified.
164 101 ▶ if ($^O eq 'MSWin32') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "MSWin32") 0 101 101
165 0 ▶ if ((!$laddr) && (!$lport)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $laddr || $lport) { } 0 0 0
elsif (not $lport) { } 0 0 0
Condition0%0/3
$laddr || $lport
l!l&&r!l&&!r
000
MC/DC0%0/2
$laddr || $lport
$laddr $lport
Truth table0%0/3
A || B
A= $laddrB= $lport
ABresult
1X1
011
000
166 0 ▶ $laddr = ($family == AF_INET) ? '0.0.0.0' : '::';
Branch: 1 branch
BranchTrueFalseTotal
$family == 2 ? : 0 0 0
167 0 $lport = '';
168 } elsif (!$lport) {
169 0 $lport = '';
170 }
171 }
172  
173 101 ▶ my $type = $arg->{Type} || $socket_type{(getprotobynumber($proto))[0]};
Condition33%1/3
$arg->{'Type'} || $socket_type{(getprotobynumber $proto)[0]}
l!l&&r!l&&!r
00101
MC/DC0%0/2
$arg->{'Type'} || $socket_type{(getprotobynumber $proto)[0]}
$arg->{'Type'} $socket_type{(getprotobynumber $proto)[0]}
Truth table33%1/3
A || B
A= $arg->{'Type'}B= $socket_type{(getprotobynumber $proto)[0]}
ABresult
1X1
011
000
174  
175 # parse Peer*
176 101 my($rport,$raddr);
177 101 ▶ unless(exists $arg->{Listen}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $arg->{"Listen"}) 0 101 101
178 ($raddr,$rport) = _sock_info(
179 $arg->{PeerAddr},
180 $arg->{PeerPort},
181 0 ▶ $proto
Branch: 1 branch
BranchTrueFalseTotal
($raddr, $rport) = _sock_info($arg->{"PeerAddr"}, $arg->{"PeerPort"}, $proto) or return _error($sock, $!, "sock_info: $@") 0 0 0
182 ) or return _error($sock, $!, "sock_info: $@");
183 }
184  
185 # find out all combinations of local and remote addr with
186 # the same family
187 101 my @lres = getaddrinfo($laddr,$lport,$family,$type,$proto,AI_PASSIVE);
188 101 ▶ return _error($sock, $EINVAL, "getaddrinfo: $lres[0]") if @lres<5;
Branch: 1 branch
BranchTrueFalseTotal
if @lres < 5 0 101 101
189 101 my @rres;
190 101 ▶ if ( defined $raddr ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $raddr) 0 101 101
191 0 @rres = getaddrinfo($raddr,$rport,$family,$type,$proto);
192 0 ▶ return _error($sock, $EINVAL, "getaddrinfo: $rres[0]") if @rres<5;
Branch: 1 branch
BranchTrueFalseTotal
if @rres < 5 0 0 0
193 }
194  
195 101 my @flr;
196 101 ▶ if (@rres) {
Branch: 1 branch
BranchTrueFalseTotal
if (@rres) { } 0 101 101
197 # Collect all combinations with the same family in lres and rres
198 # the order we search should be defined by the order of @rres,
199 # not @lres!
200 0 ▶ for( my $r=0;$r<@rres;$r+=5 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r < @rres) 0 0 0
201 0 ▶ for( my $l=0;$l<@lres;$l+=5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l < @lres) 0 0 0
202 0 my $fam_listen = $lres[$l];
203 0 ▶ next if $rres[$r] != $fam_listen; # must be same family
Branch: 1 branch
BranchTrueFalseTotal
if $rres[$r] != $fam_listen 0 0 0
204 0 push @flr,[ $fam_listen,$lres[$l+3],$rres[$r+3] ];
205 }
206 }
207 } else {
208 101 ▶ for( my $l=0;$l<@lres;$l+=5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l < @lres) 303 101 404
209 303 my $fam_listen = $lres[$l];
210 303 my $lsockaddr = $lres[$l+3];
211 # collect only the binding side
212 303 push @flr,[ $fam_listen,$lsockaddr ];
213 }
214 }
215  
216 # try to bind and maybe connect
217 # if multihomed try all combinations until success
218 101 for my $flr (@flr) {
219 101 my ($family,$lres,$rres) = @$flr;
220  
221 101 ▶ if ( $family == AF_INET6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($family == 10) 100 1 101
222 100 ▶ if ($arg->{LocalFlow} || $arg->{LocalScope}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg->{"LocalFlow"} or $arg->{"LocalScope"}) 0 100 100
Condition33%1/3
$arg->{"LocalFlow"} or $arg->{"LocalScope"}
l!l&&r!l&&!r
00100
MC/DC0%0/2
$arg->{"LocalFlow"} or $arg->{"LocalScope"}
$arg->{"LocalFlow"} $arg->{"LocalScope"}
Truth table33%1/3
A or B
A= $arg->{"LocalFlow"}B= $arg->{"LocalScope"}
ABresult
1X1
011
000
223 0 my @sa_in6 = unpack_sockaddr_in6_all($lres);
224 0 ▶ $sa_in6[1] = $arg->{LocalFlow} || 0;
Condition0%0/2
$arg->{'LocalFlow'} || 0
l!l
00
MC/DC0%0/1
$arg->{'LocalFlow'} || 0
$arg->{'LocalFlow'}
Truth table0%0/2
A
A= $arg->{'LocalFlow'}
Aresult
11
00
225 0 ▶ $sa_in6[3] = _scope_ntohl($arg->{LocalScope}) || 0;
Condition0%0/2
&_scope_ntohl($arg->{'LocalScope'}) || 0
l!l
00
MC/DC0%0/1
&_scope_ntohl($arg->{'LocalScope'}) || 0
&_scope_ntohl($arg->{'LocalScope'})
Truth table0%0/2
A
A= &_scope_ntohl($arg->{'LocalScope'})
Aresult
11
00
226 0 $lres = pack_sockaddr_in6_all(@sa_in6);
227 }
228 }
229  
230 101 ▶ $sock->socket($family, $type, $proto) or
Branch: 1 branch
BranchTrueFalseTotal
$sock->socket($family, $type, $proto) or return _error($sock, $!, "socket: $!") 0 101 101
231 return _error($sock, $!, "socket: $!");
232  
233 0 ▶ if (defined $arg->{Blocking}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg->{"Blocking"}) 0 0 0
234 0 ▶ defined $sock->blocking($arg->{Blocking}) or
Branch: 1 branch
BranchTrueFalseTotal
defined $sock->blocking($arg->{"Blocking"}) or return _error($sock, $!, "sockopt: $!") 0 0 0
235 return _error($sock, $!, "sockopt: $!");
236 }
237  
238 0 ▶ if ($arg->{Reuse} || $arg->{ReuseAddr}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg->{"Reuse"} or $arg->{"ReuseAddr"}) 0 0 0
Condition0%0/3
$arg->{"Reuse"} or $arg->{"ReuseAddr"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$arg->{"Reuse"} or $arg->{"ReuseAddr"}
$arg->{"Reuse"} $arg->{"ReuseAddr"}
Truth table0%0/3
A or B
A= $arg->{"Reuse"}B= $arg->{"ReuseAddr"}
ABresult
1X1
011
000
239 0 ▶ $sock->sockopt(SO_REUSEADDR,1) or
Branch: 1 branch
BranchTrueFalseTotal
$sock->sockopt(2, 1) or return _error($sock, $!, "sockopt: $!") 0 0 0
240 return _error($sock, $!, "sockopt: $!");
241 }
242  
243 0 ▶ if ($arg->{ReusePort}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg->{"ReusePort"}) 0 0 0
244 0 ▶ $sock->sockopt(SO_REUSEPORT,1) or
Branch: 1 branch
BranchTrueFalseTotal
$sock->sockopt(15, 1) or return _error($sock, $!, "sockopt: $!") 0 0 0
245 return _error($sock, $!, "sockopt: $!");
246 }
247  
248 0 ▶ if ($arg->{Broadcast}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg->{"Broadcast"}) 0 0 0
249 0 ▶ $sock->sockopt(SO_BROADCAST,1) or
Branch: 1 branch
BranchTrueFalseTotal
$sock->sockopt(6, 1) or return _error($sock, $!, "sockopt: $!") 0 0 0
250 return _error($sock, $!, "sockopt: $!");
251 }
252  
253 0 ▶ if ( $family == AF_INET ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($family == 2) { } 0 0 0
254 0 my ($p,$a) = sockaddr_in($lres);
255 0 ▶ $sock->bind($lres) or return _error($sock, $!, "bind: $!")
Branch: 1 branch
BranchTrueFalseTotal
if $a ne "\0\0\0\0" or $p != 0 0 0 0
Condition0%0/8
($a ne "\000\000\000\000" || $p != 0) && ($sock->bind($lres) || (return _error($sock, $!, "bind: $!")))
!ll&&!rl&&r
000
$a ne "\0\0\0\0" or $p != 0
l!l&&r!l&&!r
000
$sock->bind($lres) or return _error($sock, $!, "bind: $!")
l!l
00
MC/DC0%0/3
($a ne "\000\000\000\000" || $p != 0) && ($sock->bind($lres) || (return _error($sock, $!, "bind: $!")))
$a ne "\0\0\0\0" $p != 0 $sock->bind($lres)
Truth table0%0/5
A or B && C
A= $a ne "\0\0\0\0"B= $p != 0C= $sock->bind($lres)
ABCresult
00X0
1X00
0100
1X11
0111
256 if ($a ne INADDR_ANY or $p!=0);
257 } else {
258 0 my ($p,$a) = sockaddr_in6($lres);
259 0 ▶ $sock->bind($lres) or return _error($sock, $!, "bind: $!")
Branch: 1 branch
BranchTrueFalseTotal
if $a ne in6addr_any() or $p != 0 0 0 0
Condition0%0/8
($a ne in6addr_any() || $p != 0) && ($sock->bind($lres) || (return _error($sock, $!, "bind: $!")))
!ll&&!rl&&r
000
$a ne in6addr_any() or $p != 0
l!l&&r!l&&!r
000
$sock->bind($lres) or return _error($sock, $!, "bind: $!")
l!l
00
MC/DC0%0/3
($a ne in6addr_any() || $p != 0) && ($sock->bind($lres) || (return _error($sock, $!, "bind: $!")))
$a ne in6addr_any() $p != 0 $sock->bind($lres)
Truth table0%0/5
A or B && C
A= $a ne in6addr_any()B= $p != 0C= $sock->bind($lres)
ABCresult
00X0
1X00
0100
1X11
0111
260 if ($a ne in6addr_any or $p!=0);
261 }
262  
263 0 ▶ if(exists $arg->{Listen}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $arg->{"Listen"}) 0 0 0
264 0 ▶ $sock->listen($arg->{Listen} || 5) or
Branch: 1 branch
BranchTrueFalseTotal
$sock->listen($arg->{"Listen"} || 5) or return _error($sock, $!, "listen: $!") 0 0 0
Condition0%0/2
$arg->{'Listen'} || 5
l!l
00
MC/DC0%0/1
$arg->{'Listen'} || 5
$arg->{'Listen'}
Truth table0%0/2
A
A= $arg->{'Listen'}
Aresult
11
00
265 return _error($sock, $!, "listen: $!");
266 }
267  
268 # connect only if PeerAddr and thus $rres is given
269 0 ▶ last if ! $rres;
Branch: 1 branch
BranchTrueFalseTotal
unless $rres 0 0 0
270  
271 0 ▶ if ( $family == AF_INET6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($family == 10) 0 0 0
272 0 ▶ if ($arg->{PeerFlow} || $arg->{PeerScope}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg->{"PeerFlow"} or $arg->{"PeerScope"}) 0 0 0
Condition0%0/3
$arg->{"PeerFlow"} or $arg->{"PeerScope"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$arg->{"PeerFlow"} or $arg->{"PeerScope"}
$arg->{"PeerFlow"} $arg->{"PeerScope"}
Truth table0%0/3
A or B
A= $arg->{"PeerFlow"}B= $arg->{"PeerScope"}
ABresult
1X1
011
000
273 0 my @sa_in6 = unpack_sockaddr_in6_all($rres);
274 0 ▶ $sa_in6[1] = $arg->{PeerFlow} || 0;
Condition0%0/2
$arg->{'PeerFlow'} || 0
l!l
00
MC/DC0%0/1
$arg->{'PeerFlow'} || 0
$arg->{'PeerFlow'}
Truth table0%0/2
A
A= $arg->{'PeerFlow'}
Aresult
11
00
275 0 ▶ $sa_in6[3] = _scope_ntohl($arg->{PeerScope}) || 0;
Condition0%0/2
&_scope_ntohl($arg->{'PeerScope'}) || 0
l!l
00
MC/DC0%0/1
&_scope_ntohl($arg->{'PeerScope'}) || 0
&_scope_ntohl($arg->{'PeerScope'})
Truth table0%0/2
A
A= &_scope_ntohl($arg->{'PeerScope'})
Aresult
11
00
276 0 $rres = pack_sockaddr_in6_all(@sa_in6);
277 }
278 }
279  
280 0 undef $@;
281 0 ▶ last if $sock->connect($rres);
Branch: 1 branch
BranchTrueFalseTotal
if $sock->connect($rres) 0 0 0
282  
283 return _error($sock, $!, $@ || "Timeout")
284 0 ▶ if ! $arg->{MultiHomed};
Branch: 1 branch
BranchTrueFalseTotal
unless $arg->{"MultiHomed"} 0 0 0
Condition0%0/2
$@ || 'Timeout'
l!l
00
MC/DC0%0/1
$@ || 'Timeout'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
285  
286 }
287  
288 0 return $sock;
289 }
290  
291 sub _scope_ntohl($)
292 0 ▶{
Subroutine _scope_ntohl: not called CC=3 SCAR=24.8
293 # As of Socket6 0.17 the scope field is incorrectly put into
294 # network byte order when it should be in host byte order
295 # in the sockaddr_in6 structure. We correct for that here.
296  
297 0 ▶ if ((Socket6->VERSION <= 0.17) && (pack('s', 0x1234) ne pack('n', 0x1234)))
Branch: 1 branch
BranchTrueFalseTotal
if ('Socket6'->VERSION <= 0.17 and !0) { } 0 0 0
Condition0%0/2
"Socket6"->VERSION <= "0.17" and
!ll
00
MC/DC0%0/1
"Socket6"->VERSION <= "0.17" and
"Socket6"->VERSION <= "0.17"
Truth table0%0/2
A
A= "Socket6"->VERSION <= "0.17"
Aresult
00
11
298 {
299 0 unpack('N', pack('V', $_[0]));
300 } else {
301 0 $_[0];
302 }
303 }
304  
305 sub sockdomain
306 0 ▶{
Subroutine sockdomain: not called CC=2 SCAR=17.9
Pod documented
307 0 my $sock = shift;
308 0 ▶ $sock->SUPER::sockdomain(@_) || AF_INET6;
Branch: 1 branch
BranchTrueFalseTotal
$sock->SUPER::sockdomain(@_) or 10 0 0 0
309 }
310  
311 sub accept
312 0 ▶{
Subroutine accept: not called CC=3 SCAR=24.8
Pod documented
313 0 my $sock = shift;
314  
315 0 my ($new, $peer) = $sock->SUPER::accept(@_);
316  
317 0 ▶ return unless defined($new);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $new 0 0 0
318  
319 0 ${*$new}{io_socket_domain} = ${*$sock}{io_socket_domain};
320 0 ${*$new}{io_socket_type} = ${*$sock}{io_socket_type};
321 0 ${*$new}{io_socket_proto} = ${*$sock}{io_socket_proto};
322  
323 0 ▶ return wantarray ? ($new, $peer) : $new;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
324 }
325  
326 0 ▶sub bind {
Subroutine bind: not called CC=2 SCAR=17.9
Pod documented
327 0 ▶ @_ == 2 or
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or croak("usage: \$sock->bind(NAME) ") 0 0 0
328 croak 'usage: $sock->bind(NAME) ';
329 0 my $sock = shift;
330 0 return $sock->SUPER::bind( shift );
331 }
332  
333 0 ▶sub connect {
Subroutine connect: not called CC=2 SCAR=17.9
Pod documented
334 0 ▶ @_ == 2 or
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or croak("usage: \$sock->connect(NAME) ") 0 0 0
335 croak 'usage: $sock->connect(NAME) ';
336 0 my $sock = shift;
337 0 return $sock->SUPER::connect( shift );
338 }
339  
340 0 ▶sub sockaddr {
Subroutine sockaddr: not called CC=4 SCAR=30.0
Pod documented
341 0 ▶ @_ == 1 or croak 'usage: $sock->sockaddr()';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or croak("usage: \$sock->sockaddr()") 0 0 0
342 0 my ($sock) = @_;
343 0 ▶ return undef unless (my $name = $sock->sockname);
Branch: 1 branch
BranchTrueFalseTotal
unless my $name = $sock->sockname 0 0 0
344 0 ▶ ($sock->sockdomain == AF_INET) ? (sockaddr_in($name))[1] : (sockaddr_in6($name))[1];
Branch: 1 branch
BranchTrueFalseTotal
$sock->sockdomain == 2 ? : 0 0 0
345 }
346  
347 0 ▶sub sockport {
Subroutine sockport: not called CC=4 SCAR=30.0
Pod documented
348 0 ▶ @_ == 1 or croak 'usage: $sock->sockport()';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or croak("usage: \$sock->sockport()") 0 0 0
349 0 my($sock) = @_;
350 0 ▶ return undef unless (my $name = $sock->sockname);
Branch: 1 branch
BranchTrueFalseTotal
unless my $name = $sock->sockname 0 0 0
351 0 ▶ ($sock->sockdomain == AF_INET) ? (sockaddr_in($name))[0] : (sockaddr_in6($name))[0];
Branch: 1 branch
BranchTrueFalseTotal
$sock->sockdomain == 2 ? : 0 0 0
352 }
353  
354 0 ▶sub sockhost {
Subroutine sockhost: not called CC=3 SCAR=24.8
Pod documented
355 0 ▶ @_ == 1 or croak 'usage: $sock->sockhost()';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or croak("usage: \$sock->sockhost()") 0 0 0
356 0 my ($sock) = @_;
357 0 ▶ return undef unless (my $addr = $sock->sockaddr);
Branch: 1 branch
BranchTrueFalseTotal
unless my $addr = $sock->sockaddr 0 0 0
358 0 Socket6::inet_ntop($sock->sockdomain, $addr);
359 }
360  
361 sub sockflow
362 0 ▶{
Subroutine sockflow: not called CC=4 SCAR=30.0
Pod documented
363 0 ▶ @_ == 1 or croak 'usage: $sock->sockflow()';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or croak("usage: \$sock->sockflow()") 0 0 0
364 0 my ($sock) = @_;
365 0 ▶ return undef unless (my $name = $sock->sockname);
Branch: 1 branch
BranchTrueFalseTotal
unless my $name = $sock->sockname 0 0 0
366 0 ▶ ($sock->sockdomain == AF_INET6) ? (unpack_sockaddr_in6_all($name))[1] : 0;
Branch: 1 branch
BranchTrueFalseTotal
$sock->sockdomain == 10 ? : 0 0 0
367 }
368  
369 sub sockscope
370 0 ▶{
Subroutine sockscope: not called CC=4 SCAR=30.0
Pod documented
371 0 ▶ @_ == 1 or croak 'usage: $sock->sockscope()';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or croak("usage: \$sock->sockscope()") 0 0 0
372 0 my ($sock) = @_;
373 0 ▶ return undef unless (my $name = $sock->sockname);
Branch: 1 branch
BranchTrueFalseTotal
unless my $name = $sock->sockname 0 0 0
374 0 ▶ _scope_ntohl(($sock->sockdomain == AF_INET6) ? (unpack_sockaddr_in6_all($name))[3] : 0);
Branch: 1 branch
BranchTrueFalseTotal
$sock->sockdomain == 10 ? : 0 0 0
375 }
376  
377 0 ▶sub peeraddr {
Subroutine peeraddr: not called CC=4 SCAR=30.0
Pod documented
378 0 ▶ @_ == 1 or croak 'usage: $sock->peeraddr()';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or croak("usage: \$sock->peeraddr()") 0 0 0
379 0 my ($sock) = @_;
380 0 ▶ return undef unless (my $name = $sock->peername);
Branch: 1 branch
BranchTrueFalseTotal
unless my $name = $sock->peername 0 0 0
381 0 ▶ ($sock->sockdomain == AF_INET) ? (sockaddr_in($name))[1] : (sockaddr_in6($name))[1];
Branch: 1 branch
BranchTrueFalseTotal
$sock->sockdomain == 2 ? : 0 0 0
382 }
383  
384 0 ▶sub peerport {
Subroutine peerport: not called CC=4 SCAR=30.0
Pod documented
385 0 ▶ @_ == 1 or croak 'usage: $sock->peerport()';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or croak("usage: \$sock->peerport()") 0 0 0
386 0 my($sock) = @_;
387 0 ▶ return undef unless (my $name = $sock->peername);
Branch: 1 branch
BranchTrueFalseTotal
unless my $name = $sock->peername 0 0 0
388 0 ▶ ($sock->sockdomain == AF_INET) ? (sockaddr_in($name))[0] : (sockaddr_in6($name))[0];
Branch: 1 branch
BranchTrueFalseTotal
$sock->sockdomain == 2 ? : 0 0 0
389 }
390  
391 0 ▶sub peerhost {
Subroutine peerhost: not called CC=3 SCAR=24.8
Pod documented
392 0 ▶ @_ == 1 or croak 'usage: $sock->peerhost()';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or croak("usage: \$sock->peerhost()") 0 0 0
393 0 my ($sock) = @_;
394 0 ▶ return undef unless (my $addr = $sock->peeraddr);
Branch: 1 branch
BranchTrueFalseTotal
unless my $addr = $sock->peeraddr 0 0 0
395 0 Socket6::inet_ntop($sock->sockdomain, $addr);
396 }
397  
398 sub peerflow
399 0 ▶{
Subroutine peerflow: not called CC=4 SCAR=30.0
Pod documented
400 0 ▶ @_ == 1 or croak 'usage: $sock->peerflow()';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or croak("usage: \$sock->peerflow()") 0 0 0
401 0 my ($sock) = @_;
402 0 ▶ return undef unless (my $name = $sock->peername);
Branch: 1 branch
BranchTrueFalseTotal
unless my $name = $sock->peername 0 0 0
403 0 ▶ _scope_ntohl(($sock->sockdomain == AF_INET6) ? (unpack_sockaddr_in6_all($name))[1] : 0);
Branch: 1 branch
BranchTrueFalseTotal
$sock->sockdomain == 10 ? : 0 0 0
404 }
405  
406 sub peerscope
407 0 ▶{
Subroutine peerscope: not called CC=4 SCAR=30.0
Pod documented
408 0 ▶ @_ == 1 or croak 'usage: $sock->peerscope()';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or croak("usage: \$sock->peerscope()") 0 0 0
409 0 my ($sock) = @_;
410 0 ▶ return undef unless (my $name = $sock->peername);
Branch: 1 branch
BranchTrueFalseTotal
unless my $name = $sock->peername 0 0 0
411 0 ▶ ($sock->sockdomain == AF_INET6) ? (unpack_sockaddr_in6_all($name))[3] : 0;
Branch: 1 branch
BranchTrueFalseTotal
$sock->sockdomain == 10 ? : 0 0 0
412 }
413  
414 8 1;
415  
416 __END__
↑ Summary