« /usr/local/lib/perl5/site_perl/5.44.0/Method/Generate/Accessor.pm
↑ Summary
/usr/local/lib/perl5/5.44.0/constant.pm »
| 1 | # IO::Socket::INET.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 | package IO::Socket::INET; | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use IO::Socket; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use Socket; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use Exporter; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use Errno; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 5 | our @ISA = qw(IO::Socket); | |||||||||||||||||||||||||||||||||||||||||
| 17 | 5 | our $VERSION = "1.56"; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 5 | ▶ | my $EINVAL = exists(&Errno::EINVAL) ? Errno::EINVAL() : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 5 | IO::Socket::INET->register_domain( AF_INET ); | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 5 | my %socket_type = ( tcp => SOCK_STREAM, | |||||||||||||||||||||||||||||||||||||||||
| 24 | udp => SOCK_DGRAM, | ||||||||||||||||||||||||||||||||||||||||||
| 25 | icmp => SOCK_RAW | ||||||||||||||||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 5 | my %proto_number; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 5 | ▶ | $proto_number{tcp} = Socket::IPPROTO_TCP() if defined &Socket::IPPROTO_TCP; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 5 | ▶ | $proto_number{udp} = Socket::IPPROTO_UDP() if defined &Socket::IPPROTO_UDP; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 5 | ▶ | $proto_number{icmp} = Socket::IPPROTO_ICMP() if defined &Socket::IPPROTO_ICMP; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 5 | my %proto_name = reverse %proto_number; | |||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | unshift(@_, "PeerAddr") if @_ == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | return $class->SUPER::new(@_); | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub _cache_proto { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cache_proto: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my @proto = @_; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | for (map lc($_), $proto[0], split(' ', $proto[1])) { | |||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | $proto_number{$_} = $proto[2]; | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | $proto_name{$proto[2]} = $proto[0]; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub _get_proto_number { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_proto_number: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my $name = lc(shift); | |||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | return undef unless defined $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | return $proto_number{$name} if exists $proto_number{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my @proto = eval { getprotobyname($name) }; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | return undef unless @proto; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | _cache_proto(@proto); | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | return $proto[2]; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub _get_proto_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_proto_name: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my $num = shift; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | return undef unless defined $num; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | return $proto_name{$num} if exists $proto_name{$num}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my @proto = eval { getprotobynumber($num) }; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | return undef unless @proto; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | _cache_proto(@proto); | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | return $proto[0]; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub _sock_info { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sock_info: not called CC=18 SCAR=58.3
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my($addr,$port,$proto) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my $origport = $port; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my @serv = (); | |||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | $port = $1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $addr and $addr =~ s[:([\w\(\)/]+)$][]
MC/DC0%0/2
defined $addr and $addr =~ s[:([\w\(\)/]+)$][]
defined $addr
$addr =~ s[:([\w\(\)/]+)$][]
Truth table0%0/3
A and B
A= defined $addrB= $addr =~ s[:([\w\(\)/]+)$][]
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | if(defined $addr && $addr =~ s,:([\w\(\)/]+)$,,); | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if(defined $proto && $proto =~ /\D/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $proto and $proto =~ /\D/
MC/DC0%0/2
defined $proto and $proto =~ /\D/
defined $proto
$proto =~ /\D/
Truth table0%0/3
A and B
A= defined $protoB= $proto =~ /\D/
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | my $num = _get_proto_number($proto); | |||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | unless (defined $num) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $IO::Socket::errstr = $@ = "Bad protocol '$proto'"; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $proto = $num; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | if(defined $port) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | my $defport = ($port =~ s,\((\d+)\)$,,) ? $1 : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my $pnum = ($port =~ m,^(\d+)$,)[0]; | |||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | @serv = getservbyname($port, _get_proto_name($proto) || "") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
_get_proto_name($proto) || ''
MC/DC0%0/1
_get_proto_name($proto) || ''
_get_proto_name($proto)
Truth table0%0/2
A
A= _get_proto_name($proto)
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | if ($port =~ m,\D,); | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | $port = $serv[2] || $defport || $pnum; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$serv[2] || $defport || $pnum
$serv[2] or $defport
MC/DC0%0/3
$serv[2] || $defport || $pnum
$serv[2]
$defport
$pnum
Truth table0%0/4
A or B || C
A= $serv[2]B= $defportC= $pnum
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | unless (defined $port) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $IO::Socket::errstr = $@ = "Bad service '$origport'"; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | $proto = _get_proto_number($serv[3]) if @serv && !$proto; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@serv and not $proto
MC/DC0%0/2
@serv and not $proto
@serv
not $proto
Truth table0%0/3
A and not(B)
A= @servB= not $proto
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | return ($addr || undef, | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$addr || undef
$port || undef
$proto || undef
MC/DC0%0/1
$addr || undef
$addr
MC/DC0%0/1
$port || undef
$port
MC/DC0%0/1
$proto || undef
$proto
Truth table0%0/2
A
A= $addr
Truth table0%0/2
A
A= $port
Truth table0%0/2
A
A= $proto
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | $port || undef, | ||||||||||||||||||||||||||||||||||||||||||
| 106 | $proto || undef | ||||||||||||||||||||||||||||||||||||||||||
| 107 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub _error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_error: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | my $sock = shift; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | my $err = shift; | |||||||||||||||||||||||||||||||||||||||||
| 113 | { | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | local($!); | |||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | my $title = ref($sock).": "; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | $IO::Socket::errstr = $@ = join("", $_[0] =~ /^$title/ ? "" : $title, @_); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | $sock->close() | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | if(defined fileno($sock)); | ||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | $! = $err; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | sub _get_addr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_addr: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | my($sock,$addr_str, $multi) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | my @addr; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | if ($multi && $addr_str !~ /^\d+(?:\.\d+){3}$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$multi and not $addr_str =~ /^\d+(?:\.\d+){3}$/
MC/DC0%0/2
$multi and not $addr_str =~ /^\d+(?:\.\d+){3}$/
$multi
not $addr_str =~ /^\d+(?:\.\d+){3}$/
Truth table0%0/3
A and not(B)
A= $multiB= not $addr_str =~ /^\d+(?:\.\d+){3}$/
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | (undef, undef, undef, undef, @addr) = gethostbyname($addr_str); | |||||||||||||||||||||||||||||||||||||||||
| 129 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my $h = inet_aton($addr_str); | |||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | push(@addr, $h) if defined $h; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | @addr; | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | sub configure { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
configure: not called CC=42 SCAR=75.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my($sock,$arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my($lport,$rport,$laddr,$raddr,$proto,$type); | |||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | $arg->{LocalAddr} = $arg->{LocalHost} | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | if exists $arg->{LocalHost} && !exists $arg->{LocalAddr}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $arg->{"LocalHost"} and not exists $arg->{"LocalAddr"}
MC/DC0%0/2
exists $arg->{"LocalHost"} and not exists $arg->{"LocalAddr"}
exists $arg->{"LocalHost"}
not exists $arg->{"LocalAddr"}
Truth table0%0/3
A and not(B)
A= exists $arg->{"LocalHost"}B= not exists $arg->{"LocalAddr"}
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | ($laddr,$lport,$proto) = _sock_info($arg->{LocalAddr}, | ||||||||||||||||||||||||||||||||||||||||||
| 145 | $arg->{LocalPort}, | ||||||||||||||||||||||||||||||||||||||||||
| 146 | $arg->{Proto}) | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | or return _error($sock, $!, $@); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | $laddr = defined $laddr ? inet_aton($laddr) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | : INADDR_ANY; | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | return _error($sock, $EINVAL, "Bad hostname '",$arg->{LocalAddr},"'") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | unless(defined $laddr); | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | $arg->{PeerAddr} = $arg->{PeerHost} | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | if exists $arg->{PeerHost} && !exists $arg->{PeerAddr}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $arg->{"PeerHost"} and not exists $arg->{"PeerAddr"}
MC/DC0%0/2
exists $arg->{"PeerHost"} and not exists $arg->{"PeerAddr"}
exists $arg->{"PeerHost"}
not exists $arg->{"PeerAddr"}
Truth table0%0/3
A and not(B)
A= exists $arg->{"PeerHost"}B= not exists $arg->{"PeerAddr"}
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | unless(exists $arg->{Listen}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | ($raddr,$rport,$proto) = _sock_info($arg->{PeerAddr}, | ||||||||||||||||||||||||||||||||||||||||||
| 160 | $arg->{PeerPort}, | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | $proto) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | or return _error($sock, $!, $@); | ||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | $proto ||= _get_proto_number('tcp'); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$proto ||= _get_proto_number("tcp")
MC/DC0%0/2
$proto ||= _get_proto_number("tcp")
$proto
_get_proto_number("tcp")
Truth table0%0/3
A ||= B
A= $protoB= _get_proto_number("tcp")
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | $type = $arg->{Type} || $socket_type{lc _get_proto_name($proto)}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$arg->{'Type'} || $socket_type{lc _get_proto_name($proto)}
MC/DC0%0/2
$arg->{'Type'} || $socket_type{lc _get_proto_name($proto)}
$arg->{'Type'}
$socket_type{lc _get_proto_name($proto)}
Truth table0%0/3
A || B
A= $arg->{'Type'}B= $socket_type{lc _get_proto_name($proto)}
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | my @raddr = (); | |||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | if(defined $raddr) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | @raddr = $sock->_get_addr($raddr, $arg->{MultiHomed}); | |||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | return _error($sock, $EINVAL, "Bad hostname '",$arg->{PeerAddr},"'") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | unless @raddr; | ||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | while(1) { | |||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | $sock->socket(AF_INET, $type, $proto) or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | return _error($sock, $!, "$!"); | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | if (defined $arg->{Blocking}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | defined $sock->blocking($arg->{Blocking}) | ||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | or return _error($sock, $!, "$!"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | if ($arg->{Reuse} || $arg->{ReuseAddr}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$arg->{"Reuse"} or $arg->{"ReuseAddr"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | $sock->sockopt(SO_REUSEADDR,1) or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | return _error($sock, $!, "$!"); | ||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | if ($arg->{ReusePort}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | $sock->sockopt(SO_REUSEPORT,1) or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | return _error($sock, $!, "$!"); | ||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | if ($arg->{Broadcast}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | $sock->sockopt(SO_BROADCAST,1) or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | return _error($sock, $!, "$!"); | ||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | if($lport || ($laddr ne INADDR_ANY) || exists $arg->{Listen}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$lport or $laddr ne "\0\0\0\0" or exists $arg->{"Listen"}
$lport or $laddr ne "\0\0\0\0"
MC/DC0%0/3
$lport or $laddr ne "\0\0\0\0" or exists $arg->{"Listen"}
$lport
$laddr ne "\0\0\0\0"
exists $arg->{"Listen"}
Truth table0%0/4
A or B or C
A= $lportB= $laddr ne "\0\0\0\0"C= exists $arg->{"Listen"}
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | $sock->bind($lport || 0, $laddr) or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$lport || 0
MC/DC0%0/1
$lport || 0
$lport
Truth table0%0/2
A
A= $lport
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | return _error($sock, $!, "$!"); | ||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | if(exists $arg->{Listen}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | $sock->listen($arg->{Listen} || 5) or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$arg->{'Listen'} || 5
MC/DC0%0/1
$arg->{'Listen'} || 5
$arg->{'Listen'}
Truth table0%0/2
A
A= $arg->{'Listen'}
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | return _error($sock, $!, "$!"); | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | # don't try to connect unless we're given a PeerAddr | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | last unless exists($arg->{PeerAddr}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | $raddr = shift @raddr; | |||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | return _error($sock, $EINVAL, 'Cannot determine remote port') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$rport or $type == 2 or $type == 3
$rport or $type == 2
MC/DC0%0/3
$rport or $type == 2 or $type == 3
$rport
$type == 2
$type == 3
Truth table0%0/4
A or B or C
A= $rportB= $type == 2C= $type == 3
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | unless($rport || $type == SOCK_DGRAM || $type == SOCK_RAW); | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | last | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | unless($type == SOCK_STREAM || defined $raddr); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$type == 1 or defined $raddr
MC/DC0%0/2
$type == 1 or defined $raddr
$type == 1
defined $raddr
Truth table0%0/3
A or B
A= $type == 1B= defined $raddr
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | return _error($sock, $EINVAL, "Bad hostname '",$arg->{PeerAddr},"'") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | unless defined $raddr; | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | # my $timeout = ${*$sock}{'io_socket_timeout'}; | ||||||||||||||||||||||||||||||||||||||||||
| 228 | # my $before = time() if $timeout; | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | undef $@; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | if ($sock->connect(pack_sockaddr_in($rport, $raddr))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | # ${*$sock}{'io_socket_timeout'} = $timeout; | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | return $sock; | |||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | return _error($sock, $!, $@ || "Timeout") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$@ || 'Timeout'
MC/DC0%0/1
$@ || 'Timeout'
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | unless @raddr; | ||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | # if ($timeout) { | ||||||||||||||||||||||||||||||||||||||||||
| 240 | # my $new_timeout = $timeout - (time() - $before); | ||||||||||||||||||||||||||||||||||||||||||
| 241 | # return _error($sock, | ||||||||||||||||||||||||||||||||||||||||||
| 242 | # (exists(&Errno::ETIMEDOUT) ? Errno::ETIMEDOUT() : $EINVAL), | ||||||||||||||||||||||||||||||||||||||||||
| 243 | # "Timeout") if $new_timeout <= 0; | ||||||||||||||||||||||||||||||||||||||||||
| 244 | # ${*$sock}{'io_socket_timeout'} = $new_timeout; | ||||||||||||||||||||||||||||||||||||||||||
| 245 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | $sock; | |||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | sub connect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connect: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | @_ == 2 || @_ == 3 or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ == 2 or @_ == 3
MC/DC0%0/2
@_ == 2 or @_ == 3
@_ == 2
@_ == 3
Truth table0%0/3
A or B
A= @_ == 2B= @_ == 3
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | croak 'usage: $sock->connect(NAME) or $sock->connect(PORT, ADDR)'; | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | my $sock = shift; | |||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | return $sock->SUPER::connect(@_ == 1 ? shift : pack_sockaddr_in(@_)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | sub bind { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bind: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | @_ == 2 || @_ == 3 or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ == 2 or @_ == 3
MC/DC0%0/2
@_ == 2 or @_ == 3
@_ == 2
@_ == 3
Truth table0%0/3
A or B
A= @_ == 2B= @_ == 3
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | croak 'usage: $sock->bind(NAME) or $sock->bind(PORT, ADDR)'; | ||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | my $sock = shift; | |||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | return $sock->SUPER::bind(@_ == 1 ? shift : pack_sockaddr_in(@_)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | sub sockaddr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sockaddr: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | @_ == 1 or croak 'usage: $sock->sockaddr()'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | my($sock) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | my $name = $sock->sockname; | |||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | $name ? (sockaddr_in($name))[1] : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | sub sockport { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sockport: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | @_ == 1 or croak 'usage: $sock->sockport()'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | my($sock) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | my $name = $sock->sockname; | |||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | $name ? (sockaddr_in($name))[0] : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | sub sockhost { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sockhost: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | @_ == 1 or croak 'usage: $sock->sockhost()'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | my($sock) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | my $addr = $sock->sockaddr; | |||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | $addr ? inet_ntoa($addr) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | sub peeraddr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
peeraddr: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | @_ == 1 or croak 'usage: $sock->peeraddr()'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | my($sock) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | my $name = $sock->peername; | |||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | $name ? (sockaddr_in($name))[1] : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | sub peerport { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
peerport: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | @_ == 1 or croak 'usage: $sock->peerport()'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | my($sock) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | my $name = $sock->peername; | |||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | $name ? (sockaddr_in($name))[0] : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | sub peerhost { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
peerhost: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | @_ == 1 or croak 'usage: $sock->peerhost()'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | my($sock) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | my $addr = $sock->peeraddr; | |||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | $addr ? inet_ntoa($addr) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | __END__ | ||||||||||||||||||||||||||||||||||||||||||