Branch Coverage

blib/lib/IO/Socket/Socks.pm
Criterion Covered Total %
branch 268 536 50.0


line true false branch
14 34 0 exists &Errno::EPROTO ? :
153 0 4 if (exists $arg{'Timeout'})
157 0 4 unless scalar %arg
161 0 4 unless $sock->configure(\%arg) or $IO::Socket::Socks::SOCKS_ERROR == 21
173 0 4 if (exists $arg{'Timeout'})
180 4 0 $sock->command(%arg) ? :
186 4 160 unless $CAN_CHANGE_SOCKET
194 0 164 unless $self->_configure($args)
200 97 67 exists $args->{'ProxyAddr'} ? :
206 97 67 exists $args->{'ProxyPort'} ? :
211 67 97 if (exists $args->{'Listen'}) { }
97 0 elsif (${*$self;}->{'SOCKS'}{'ProxyAddr'} and ${*$self;}->{'SOCKS'}{'ProxyPort'}) { }
222 164 0 if (not defined ${*$self;}->{'SOCKS'}{'TCP'}) { }
0 0 elsif (not defined $args->{'Proto'}) { }
232 8 156 unless ($self->SUPER::configure($args))
233 0 8 if ($IO::Socket::Socks::SOCKS_ERROR == undef)
255 146 0 $args->{'SocksVersion'} == 4 || $args->{'SocksVersion'} == 5 || exists $args->{'Listen'} && ref $args->{'SocksVersion'} eq 'ARRAY' && _validate_multi_version($args->{'SocksVersion'}) ? :
146 22 exists $args->{'SocksVersion'} ? :
263 26 142 exists $args->{'AuthType'} ? :
269 62 106 exists $args->{'RequireAuth'} ? :
275 62 106 exists $args->{'UserAuth'} ? :
281 142 0 ${*$self;}->{'SOCKS'}{'AuthType'} eq 'none' ? :
26 142 exists $args->{'Username'} ? :
289 142 0 ${*$self;}->{'SOCKS'}{'AuthType'} eq 'none' ? :
26 142 exists $args->{'Password'} ? :
297 0 168 exists $args->{'SocksDebug'} ? :
303 26 142 exists $args->{'SocksResolve'} ? :
308 153 15 unless ${*$self;}->{'SOCKS'}{'RequireAuth'}
316 88 80 if not exists $args->{'Listen'} and ${*$self;}->{'SOCKS'}{'AuthType'} eq 'userpass' or exists $args->{'Listen'} and defined ${*$self;}->{'SOCKS'}{'UserAuth'}
319 0 168 if (exists $args->{'BindAddr'} and exists $args->{'BindPort'}) { }
0 168 elsif (exists $args->{'UdpAddr'} and exists $args->{'UdpPort'}) { }
101 67 elsif (exists $args->{'ConnectAddr'} and exists $args->{'ConnectPort'}) { }
325 0 0 if (${*$self;}->{'SOCKS'}{'Version'} == 4)
336 0 0 exists $args->{'Blocking'} ? :
0 0 unless ${*$self;}->{'SOCKS'}{'TCP'} = 'IO::Socket::Socks'->new('Timeout', $args->{'Timeout'}, 'Proto', 'tcp', 'PeerAddr', $args->{'ProxyAddr'}, 'PeerPort', $args->{'ProxyPort'}, exists $args->{'Blocking'} ? ('Blocking', $args->{'Blocking'}) : ())
355 0 97 unless defined $self
360 0 97 defined ${*$self;}->{'SOCKS'}{'TCP'} ? :
363 47 50 if ($! == 115 || $! == 11 and (${*$self;}->{'SOCKS'}{'TCP'} || $self)->blocking == 0) { }
0 50 elsif (not $ok) { }
378 0 97 unless ${*$self;}->{'SOCKS'}{'ProxyAddr'} and ${*$self;}->{'SOCKS'}{'ProxyPort'}
387 37 64 if (${*$self;}->{'SOCKS'}{'Version'} == 4) { }
391 0 37 ${*$self;}->{'SOCKS'}{'Bind'} ? :
403 0 64 ${*$self;}->{'SOCKS'}{'TCP'} ? :
0 64 ${*$self;}->{'SOCKS'}{'Bind'} ? :
414 47 54 if (delete ${*$self;}->{'SOCKS'}{'_in_progress'}) { }
415 47 0 if ($self->isa('IO::Socket::IP'))
427 8 46 unless defined $self->_run_queue
438 47 0 if $sock->SUPER::connect
439 0 0 if ($! == 115 or $! == 11)
459 13 713 unless (defined $retval)
465 210 503 if $retval == -1
467 0 503 if ($elt->[5])
473 155 241 if (defined $retval and not @{${*$self;}->{'SOCKS'}{'queue'};})
475 0 155 $IO::Socket::Socks::SOCKS_ERROR ? :
490 0 110 if ${*$self;}->{'SOCKS'}{'Debug'}
495 0 110 defined ${*$self;}->{'SOCKS'}{'TCP'} ? :
509 166 164 if (${*$self;}->{'SOCKS'}{'AuthMethods'}[$method] == 1)
516 0 110 unless $reply = $sock->_socks_send(pack('CCa*', 5, $nmethods, $methods), ++$sends)
519 0 110 if ($debug and not $self->_debugged(++$debugs))
537 49 61 unless $reply = $sock->_socks_read(2, ++$reads)
542 0 61 if ($debug and not $self->_debugged(++$debugs))
550 0 61 if ($auth_method == 255)
561 26 38 if (${*$self;}->{'SOCKS'}{'queue_results'}{'_socks5_connect'} != 0)
572 0 36 if ${*$self;}->{'SOCKS'}{'Debug'}
577 0 36 defined ${*$self;}->{'SOCKS'}{'TCP'} ? :
593 0 36 unless $reply = $sock->_socks_send(pack("CCa${ulen}Ca*", 1, $ulen, $uname, $plen, $passwd), ++$sends)
596 0 36 if ($debug and not $self->_debugged(++$debugs))
616 10 26 unless $reply = $sock->_socks_read(2, ++$reads)
621 0 26 if ($debug and not $self->_debugged(++$debugs))
629 13 13 if ($status != 0)
641 0 51 if ${*$self;}->{'SOCKS'}{'Debug'}
643 8 43 defined ${*$self;}->{'SOCKS'}{'Resolve'} ? :
647 0 51 defined ${*$self;}->{'SOCKS'}{'TCP'} ? :
659 51 0 $resolve ? :
0 51 unless my($atyp, $dstaddr) = $resolve ? (3, ${*$self;}->{'SOCKS'}{'CmdAddr'}) : _resolve(${*$self;}->{'SOCKS'}{'CmdAddr'})
660 51 0 if $resolve
663 51 0 defined $hlen ? :
0 51 unless $reply = $sock->_socks_send(pack('C4', 5, $command, 0, $atyp) . (defined $hlen ? pack('C', $hlen) : '') . $dstaddr . $dstport, ++$sends)
666 0 51 if ($debug and not $self->_debugged(++$debugs))
673 0 0 if defined $hlen
677 0 0 $resolve ? :
686 0 75 if ${*$self;}->{'SOCKS'}{'Debug'}
691 0 75 defined ${*$self;}->{'SOCKS'}{'TCP'} ? :
703 42 33 unless $reply = $sock->_socks_read(4, ++$reads)
708 0 33 if ($debug)
719 0 33 if ($atyp == 3) { }
33 0 elsif ($atyp == 1) { }
0 0 elsif ($atyp == 4) { }
720 0 0 unless length($reply = $sock->_socks_read(1, ++$reads))
724 0 0 unless $bndaddr = $sock->_socks_read($hlen, ++$reads)
727 0 0 if ($debug)
732 0 33 unless $bndaddr = $sock->_socks_read(4, ++$reads)
736 0 0 unless $bndaddr = $sock->_socks_read(16, ++$reads)
745 0 33 unless $reply = $sock->_socks_read(2, ++$reads)
753 0 33 if ($debug and not $self->_debugged(++$debugs))
762 0 33 if ($rep != 0)
764 0 0 unless (exists $IO::Socket::Socks::CODES{'REPLY'}{$rep})
780 0 34 if ${*$self;}->{'SOCKS'}{'Debug'}
782 12 22 defined ${*$self;}->{'SOCKS'}{'Resolve'} ? :
794 12 22 $resolve ? :
0 34 unless my $dstaddr = $resolve ? inet_aton('0.0.0.1') : inet_aton(${*$self;}->{'SOCKS'}{'CmdAddr'})
798 12 22 if ($resolve)
803 0 34 unless $reply = $self->_socks_send(pack('CC', 4, $command) . $dstport . $dstaddr . $userid . "\000" . $dsthost, ++$sends)
806 0 34 if ($debug and not $self->_debugged(++$debugs))
811 0 0 length $dstaddr == 4 ? :
815 0 0 if ($dsthost)
829 0 63 if ${*$self;}->{'SOCKS'}{'Debug'}
842 36 27 unless $reply = $self->_socks_read(8, ++$reads)
852 0 27 if ($debug and not $self->_debugged(++$debugs))
864 0 27 if ($rep != 90)
866 0 0 unless (exists $IO::Socket::Socks::CODES{'REPLY'}{$rep})
879 0 49 unless defined $self
882 49 0 if (${*$self;}->{'SOCKS'}{'Listen'}) { }
885 0 49 unless ($client)
886 0 0 if ($! == 11 or $! == 11) { }
900 10 0 @{${*$self;}->{'SOCKS'}{'Version'};} > 1 ? :
10 39 ref ${*$self;}->{'SOCKS'}{'Version'} ? :
911 10 39 if (ref $ver) { }
17 22 elsif ($ver == 4) { }
926 0 49 unless defined $client->_run_queue
934 0 0 if ({*$self}->{'SOCKS'}{'Version'} == 4) { }
941 0 0 unless defined $self->_run_queue
953 10 10 unless $request = $self->_socks_read(1, 0)
957 2 8 if ($ver == 4) { }
8 0 elsif ($ver == 5) { }
979 0 47 if ${*$self;}->{'SOCKS'}{'Debug'}
992 8 39 $ver ? :
12 35 unless $request = $self->_socks_read($ver ? 1 : 2, ++$reads)
995 27 8 unless ($ver)
1000 5 30 unless $request = $self->_socks_read($nmethods, ++$reads)
1005 0 30 if ($debug and not $self->_debugged(++$debugs))
1014 0 30 if ($ver != 5)
1020 0 30 if ($nmethods == 0)
1029 30 2 if (${*$self;}->{'SOCKS'}{'AuthMethods'}[$method] == 1)
1035 0 30 unless (defined $authmech)
1048 0 30 unless $request = $self->_socks_send(pack('CC', 5, $authmech), ++$sends)
1051 0 30 if ($debug and not $self->_debugged(++$debugs))
1059 0 30 if ($authmech == 255)
1071 2 28 if (${*$self;}->{'SOCKS'}{'queue_results'}{'_socks5_accept'} == 2)
1081 0 2 if ${*$self;}->{'SOCKS'}{'Debug'}
1094 0 2 unless $request = $self->_socks_read(2, ++$reads)
1098 0 2 unless $request = $self->_socks_read($ulen + 1, ++$reads)
1104 0 2 unless $passwd = $self->_socks_read($plen, ++$reads)
1107 0 2 if ($debug and not $self->_debugged(++$debugs))
1119 2 0 if (defined ${*$self;}->{'SOCKS'}{'UserAuth'})
1132 2 0 $status ? :
1133 0 2 unless $request = $self->_socks_send(pack('CC', 1, $status), ++$sends)
1136 0 2 if ($debug and not $self->_debugged(++$debugs))
1144 0 2 if ($status != 0)
1155 0 50 if ${*$self;}->{'SOCKS'}{'Debug'}
1170 20 30 unless $request = $self->_socks_read(4, ++$reads)
1174 0 30 if ($debug and not $self->_debugged(++$debugs))
1184 30 0 if ($atyp == 3) { }
0 0 elsif ($atyp == 1) { }
0 0 elsif ($atyp == 4) { }
1185 0 30 unless length($request = $self->_socks_read(1, ++$reads))
1189 0 30 unless $dstaddr = $self->_socks_read($hlen, ++$reads)
1192 0 30 if ($debug and not $self->_debugged(++$debugs))
1197 0 0 unless $request = $self->_socks_read(4, ++$reads)
1200 0 0 length $request == 4 ? :
1203 0 0 unless $request = $self->_socks_read(16, ++$reads)
1206 0 0 length $request == 16 ? :
1220 0 30 unless $request = $self->_socks_read(2, ++$reads)
1225 0 30 if ($debug and not $self->_debugged(++$debugs))
1243 0 28 if ${*$self;}->{'SOCKS'}{'Debug'}
1244 8 20 defined ${*$self;}->{'SOCKS'}{'Resolve'} ? :
1247 0 28 unless (defined $reply and defined $host and defined $port)
1260 28 0 $resolve ? :
0 28 unless my($atyp, $bndaddr) = $resolve ? _resolve($host) : (3, $host)
1262 28 0 $resolve ? :
1264 28 0 $resolve ? :
0 28 unless $rc = $self->_socks_send(pack('CCCC', 5, $reply, 0, $atyp) . ($resolve ? '' : pack('C', $hlen)) . $bndaddr . pack('n', $port), ++$sends)
1267 0 28 if ($debug and not $self->_debugged(++$debugs))
1274 0 0 unless $resolve
1275 0 0 $resolve ? :
1287 0 45 if ${*$self;}->{'SOCKS'}{'Debug'}
1288 41 4 defined ${*$self;}->{'SOCKS'}{'Resolve'} ? :
1303 2 43 $ver ? :
16 29 unless $request = $self->_socks_read($ver ? 7 : 8, ++$reads)
1306 27 2 unless ($ver)
1313 29 0 length $request == 4 ? :
1319 3 26 unless length($c = $self->_socks_read(1, ++$reads))
1322 0 26 if ($c ne "\000") { }
1330 0 26 if ($debug and not $self->_debugged(++$debugs))
1343 22 4 if ($resolve and $dstaddr =~ /^0\.0\.0\.[1-9]/)
1348 7 180 unless length($c = $self->_socks_read(1, ++$reads))
1351 165 15 if ($c ne "\000") { }
1359 0 15 if ($debug and not $self->_debugged(++$debugs))
1367 0 19 if ($debug and not $self->_debugged(++$debugs))
1371 4 15 if (defined ${*$self;}->{'SOCKS'}{'UserAuth'})
1372 0 4 unless (&{${*$self;}->{'SOCKS'}{'UserAuth'};}($userid))
1385 0 19 if ($ver != 4)
1401 0 18 if ${*$self;}->{'SOCKS'}{'Debug'}
1404 0 18 unless (defined $reply and defined $host and defined $port)
1417 0 18 unless my $bndaddr = inet_aton($host)
1420 0 18 unless $rc = $self->_socks_send(pack('CCna*', 0, $reply, $port, $bndaddr), ++$sends)
1423 0 18 if ($debug and not $self->_debugged(++$debugs))
1424 0 0 length $bndaddr == 4 ? :
1439 22 4 if (not exists ${*$self;}->{'SOCKS'}{'RequireAuth'}) { }
1453 4 0 if ($self->_connect)
1466 18 28 if (${*$self;}->{'SOCKS'}{'Version'} == 4) { }
1485 0 0 unless (defined ${*$self;}->{'SOCKS'}{'TCP'})
1490 0 0 if ${*$self;}->{'SOCKS'}{'Debug'}
1491 0 0 defined ${*$self;}->{'SOCKS'}{'Resolve'} ? :
1493 0 0 unless defined $peer
1497 0 0 if (ref $peer eq 'ARRAY') { }
1503 0 0 unless (($dstport, $dstaddr, $dstaddr_type) = eval { do { unpack_sockaddr_in($peer), 1 } })
1509 0 0 if ($sndaddr eq '0.0.0.0' and $sndaddr_type == 1 or $sndaddr eq '::' and $sndaddr_type == 4)
1513 0 0 if ($sndaddr_type == 3) { }
1514 0 0 unless ($sndaddr_type, $sndaddr) = _resolve($sndaddr)
1521 0 0 $sndaddr_type == 1 ? :
1524 0 0 if ($dstaddr_type == 3)
1525 0 0 if ($resolve) { }
1529 0 0 unless ($dstaddr_type, $dstaddr) = _resolve($dstaddr)
1534 0 0 $debug ? :
1542 0 0 defined $hlen ? :
1544 0 0 if ($debug)
1550 0 0 if defined $hlen
1551 0 0 defined $hlen ? :
1565 0 0 unless (defined ${*$self;}->{'SOCKS'}{'TCP'})
1569 0 0 if ${*$self;}->{'SOCKS'}{'Debug'}
1571 0 0 unless defined $self->SUPER::recv($_[0], $_[1] + 262, $_[2])
1586 0 0 if ($debug)
1595 0 0 if ($atyp == 3) { }
0 0 elsif ($atyp == 1) { }
0 0 elsif ($atyp == 4) { }
1600 0 0 if ($debug)
1621 0 0 if ($debug)
1630 0 0 if $atyp == 1
1631 0 0 if $atyp == 4
1648 0 331 do { *$self }->{'io_socket_timeout'} ? :
1650 199 0 unless ($blocking or do { *$self }->{'io_socket_timeout'})
1651 59 140 if (${*$self;}->{'SOCKS'}{'queue'}[0][4] >= $numb)
1655 0 140 if (defined ${*$self;}->{'SOCKS'}{'queue'}[0][2])
1661 140 0 if (defined $rc) { }
0 0 elsif ($! == 11 or $! == 11) { }
1662 140 0 if ($rc > 0) { }
1690 0 132 if (do { *$self }->{'io_socket_timeout'} and time - $start >= do { *$self }->{'io_socket_timeout'})
1695 0 132 unless ($selector->can_write(1))
1700 132 0 if ($rc > 0) { }
1703 132 0 if (length $data == 0)
1708 0 0 unless defined $rc
1713 132 0 if $blocking
1729 647 0 unless ($blocking or do { *$self }->{'io_socket_timeout'})
1730 63 584 if (defined ${*$self;}->{'SOCKS'}{'queue'}[0][3][$numb])
1734 6 578 if (defined ${*$self;}->{'SOCKS'}{'queue'}[0][2])
1741 377 210 if (defined $rc) { }
210 0 elsif ($! == 11 or $! == 11) { }
1742 377 0 if ($rc > 0) { }
1751 6 204 if (length $data)
1773 0 245 if (do { *$self }->{'io_socket_timeout'} and time - $start >= do { *$self }->{'io_socket_timeout'})
1778 30 215 unless ($selector->can_read(1))
1783 215 0 if (defined $rc and $rc > 0) { }
1788 0 0 unless defined $rc
1800 0 0 if (${*$self;}->{'SOCKS'}{'queue'}[0][6] >= $debugs)
1809 0 210 if (not @_ or defined $_[0])
1810 0 0 if $IO::Socket::Socks::SOCKS_ERROR == undef
1820 0 1 if (@$multi_ver == 1)
1824 1 0 if (@$multi_ver == 2)
1837 0 28 if $err
1840 28 0 if ($r->{'family'} == 2)
1851 19 0 if $atype == 1
1852 0 0 if $atype == 4
1884 271 1411 defined $num ? :
1901 8 191 unless (defined $num)
1948 0 34 unless eval "use $class; 1"
2000 0 0 $row1_len > $row2_len ? :
2019 0 0 $row1_len > $row2_len ? :