Branch Coverage

blib/lib/Net/Ping.pm
Criterion Covered Total %
branch 220 568 38.7


line true false branch
113 1 40 if (ref $proto eq "HASH")
119 2 17 if (exists $proto->{$k})
122 0 2 if ($k eq "pingstring")
123 0 2 if ($k eq "source_verify")
125 0 2 if $k eq "timeout"
126 0 2 if $k eq "data_size"
127 0 2 if $k eq "device"
128 0 2 if $k eq "tos"
129 1 1 if $k eq "ttl"
130 0 2 if $k eq "family"
134 0 1 if (%$proto)
140 2 39 unless $proto
141 1 40 unless $proto =~ /^(icmp|icmpv6|udp|tcp|syn|stream|external)$/
145 22 18 unless defined $timeout
146 1 39 if $timeout <= 0
154 0 39 if ($self->{'host'})
156 0 0 unless my $ip = $self->_resolv($host)
162 0 39 if ($self->{'bind'}) { }
164 0 0 unless my $ip = $self->_resolv($addr)
171 11 28 if ($self->{'proto'} eq "icmp")
172 2 2 if $ttl and $ttl < 0 || $ttl > 255
177 0 37 if ($family) { }
178 0 0 if ($family =~ /$qr_family/) { }
179 0 0 if ($family =~ /$qr_family4/) { }
188 1 36 if ($self->{'proto'} eq 'icmpv6') { }
195 4 33 $proto eq 'udp' ? :
196 35 2 unless defined $data_size and $proto ne "tcp"
198 2 35 if $data_size < $min_datasize or $data_size > $Net::Ping::max_datasize
200 2 33 if $self->{'proto'} eq "udp"
210 35 0 unless exists $self->{'retrans'}
212 35 0 unless exists $self->{'econnrefused'}
215 2 33 if ($self->{'proto'} eq 'udp') { }
9 24 elsif ($self->{'proto'} eq 'icmp') { }
1 23 elsif ($self->{'proto'} eq 'icmpv6') { }
15 8 elsif ($self->{'proto'} eq 'tcp' or $self->{'proto'} eq 'stream') { }
8 0 elsif ($self->{'proto'} eq 'syn') { }
224 0 2 unless socket $self->{'fh'}, 2, 2, $self->{'proto_num'}
230 0 9 unless _isroot()
235 0 9 unless socket $self->{'fh'}, 2, 3, $self->{'proto_num'}
238 2 7 if ($self->{'ttl'})
239 0 2 unless setsockopt $self->{'fh'}, 0, 2, pack("I*", $self->{'ttl'})
247 0 1 if $self->{'family'} and $self->{'family'} != $AF_INET6
253 0 1 unless socket $self->{'fh'}, $AF_INET6, 3, $self->{'proto_num'}
256 0 1 if ($self->{'gateway'})
258 0 0 unless my $ip = $self->_resolv($g)
260 0 0 unless $self->{'family'} eq $AF_INET6
262 0 0 unless $ip->{'family'} eq $AF_INET6
265 0 0 unless setsockopt $self->{'fh'}, $IPPROTO_IPV6, $IPV6_NEXTHOP, &_pack_sockaddr_in($ip)
268 0 1 if (exists $self->{'IPV6_USE_MIN_MTU'})
271 0 0 unless setsockopt $self->{'fh'}, $IPPROTO_IPV6, $IPV6_USE_MIN_MTU, pack("I*", $self->{'IPV6_USE_MIN_MT'})
274 0 1 if (exists $self->{'IPV6_RECVPATHMTU'})
277 0 0 unless setsockopt $self->{'fh'}, $IPPROTO_IPV6, $IPV6_RECVPATHMTU, pack("I*", $self->{'RECVPATHMTU'})
280 0 1 if ($self->{'tos'})
281 0 0 $self->{'family'} == 2 ? :
282 0 0 unless setsockopt $self->{'fh'}, $proto, 1, pack("I*", $self->{'tos'})
285 0 1 if ($self->{'ttl'})
286 0 0 $self->{'family'} == 2 ? :
287 0 0 unless setsockopt $self->{'fh'}, $proto, 2, pack("I*", $self->{'ttl'})
306 0 8 if ($Net::Ping::syn_forking) { }
336 0 0 unless @_ == 2
338 0 0 if defined $self->{'local_addr'} and $self->{'proto'} eq 'udp' || $self->{'proto'} eq 'icmp'
341 0 0 unless defined $ip
344 0 0 if ($self->{'proto'} ne "udp" and $self->{'proto'} ne "icmp" and $self->{'proto'} ne "tcp" and $self->{'proto'} ne "syn")
359 0 64 if ($_[3] > 0 and $^O eq 'MSWin32') { }
368 0 0 if $gran > $t
370 0 0 if $nfound == -1
372 0 0 if $nfound or not defined $nfound or $t <= 0
380 0 63 if $nfound == -1
392 0 0 defined $self && ref $self ? :
0 0 unless defined($Net::Ping::source_verify = defined $self && ref $self ? shift() : $self)
404 0 14 unless defined($self->{'econnrefused'} = shift())
423 0 0 unless $^O eq "MSWin32" or $^O eq "cygwin"
424 0 0 unless eval { do { require Win32 } }
425 0 0 unless defined &Win32::IsAdminUser
430 0 16 if ($> and $^O ne 'VMS' and $^O ne 'cygwin' or $^O eq 'MSWin32' || $^O eq 'cygwin' and not _IsAdminUser() or $^O eq 'VMS' and `write sys\$output f\$privilege("SYSPRV")` =~ /FALSE/) { }
449 0 0 if ($on) { }
451 0 0 unless ($reachconf)
455 0 0 unless (_isroot())
472 0 0 if (defined $on) { }
478 0 0 $on ? :
480 0 0 unless setsockopt $self->{'fh'}, $IPPROTO_IPV6, $IPV6_USE_MIN_MTU, pack("I*", $self->{'IPV6_USE_MIN_MT'})
494 0 0 if ($on) { }
502 0 0 unless setsockopt $self->{'fh'}, $IPPROTO_IPV6, $IPV6_RECVPATHMTU, pack("I*", $self->{'IPV6_RECVPATHMTU'})
517 3 0 defined $self && ref $self ? :
1 2 unless defined($Net::Ping::hires = defined $self && ref $self ? shift() : $self)
523 109 0 $Net::Ping::hires ? :
536 0 83 if ($^O eq "MSWin32" or $^O eq "VMS")
540 0 0 $block ? :
541 0 0 unless ioctl $fh, $f, $v
544 83 0 if ($flags = fcntl($fh, 3, 0)) { }
545 28 55 $block ? :
546 0 83 if (not fcntl($fh, 4, $flags))
571 0 0 if not defined $host and $self->{'host'}
572 0 61 if @_ > 4 or not $host
573 61 0 unless $timeout
574 0 61 if $timeout <= 0
576 0 61 if ($family) { }
577 0 0 if ($family =~ /$qr_family/) { }
578 0 0 if ($family =~ /$qr_family4/) { }
591 0 61 unless defined $ip
595 0 61 if ($self->{'proto'} eq 'external') { }
1 60 elsif ($self->{'proto'} eq 'udp') { }
4 56 elsif ($self->{'proto'} eq 'icmp') { }
1 55 elsif ($self->{'proto'} eq 'icmpv6') { }
29 26 elsif ($self->{'proto'} eq 'tcp') { }
0 26 elsif ($self->{'proto'} eq 'stream') { }
26 0 elsif ($self->{'proto'} eq 'syn') { }
619 1 59 wantarray ? :
630 0 0 if not defined $ip and $self->{'host'}
631 0 0 if not defined $timeout and $self->{'timeout'}
634 0 0 exists $ip->{'addr_in'} ? :
636 0 0 unless eval { do { local(@INC) = @INC; pop @INC if $INC[-1] eq "."; require Net::Ping::External } }
638 0 0 if $INC[-1] eq "."
673 4 2 unless $self->{'proto'} eq "icmp"
675 1 1 unless defined $type
678 1 0 unless $type =~ /^echo|timestamp$/i
714 0 0 if not defined $ip and $self->{'host'}
715 0 0 if not defined $timeout and $self->{'timeout'}
716 0 5 $self->{'message_type'} && $self->{'message_type'} eq 'timestamp' ? :
718 0 5 unless socket $self->{'fh'}, $ip->{'family'}, 3, $self->{'proto_num'}
721 0 5 if (defined $self->{'local_addr'} and not CORE::bind($self->{'fh'}, &_pack_sockaddr_in(0, $self->{'local_addr'})))
729 4 1 if ($ip->{'family'} == 2) { }
730 0 4 if ($timestamp_msg) { }
745 4 1 if ($ip->{'family'} == 2) { }
746 0 4 if ($timestamp_msg) { }
773 0 9 if (not defined $nfound) { }
8 1 elsif ($nfound) { }
789 8 0 $ip->{'family'} == 2 ? :
791 0 8 if ($from_type == 14) { }
4 4 elsif ($from_type == 0 or $from_type == 129) { }
0 4 elsif ($from_type == 140) { }
792 0 0 if length $recv_msg >= $off + 8
796 4 0 if $recv_msg_len == $off + 8
800 0 0 if $ip->{'family'} == $AF_INET6 and length $recv_msg == 8
803 0 4 if length $recv_msg >= $off + 36
809 4 4 if $from_pid != $self->{'pid'}
810 0 4 if $from_seq != $self->{'seq'}
811 4 0 if (not $Net::Ping::source_verify or $self->ntop($from_ip) eq $self->ntop($ip))
812 4 0 if (not $timestamp_msg and $from_type == 0 || $from_type == 129) { }
0 0 elsif ($timestamp_msg and $from_type == 14) { }
0 0 elsif ($from_type == 3 or $from_type == 1) { }
0 0 elsif ($from_type == 11) { }
840 0 0 unless 4 == length $addr
865 0 5 if $len_msg % 2
890 0 0 if not defined $ip and $self->{'host'}
891 0 0 if not defined $timeout and $self->{'timeout'}
895 12 16 if (not $self->{'econnrefused'} and $! == 111)
911 0 0 if not defined $ip and $self->{'host'}
912 0 0 if not defined $timeout and $self->{'timeout'}
919 0 29 unless socket $self->{'fh'}, $ip->{'family'}, 1, $self->{'proto_num'}
921 0 29 if (defined $self->{'local_addr'} and not CORE::bind($self->{'fh'}, &_pack_sockaddr_in(0, $self->{'local_addr'})))
938 29 0 if (not connect($self->{'fh'}, $saddr)) { }
939 0 29 if ($! == 111) { }
0 29 elsif ($! != 115 and $^O ne 'MSWin32' || $! != 11) { }
940 0 0 unless $self->{'econnrefused'}
956 0 29 $^O eq 'MSWin32' ? :
960 0 28 unless defined $nfound
962 22 6 if ($nfound and vec $wout, $self->{'fh'}->fileno, 1) { }
967 9 13 if (getpeername $self->{'fh'}) { }
977 0 13 if $! == 11 and $^O =~ /cygwin/i
980 12 1 if not $self->{'econnrefused'} and $! == 111
985 0 6 if ($^O =~ /MSWin32/)
990 0 0 if ($nfound and vec $wexc, $self->{'fh'}->fileno, 1)
1008 0 29 if ($Net::Ping::syn_forking) { }
1017 0 0 unless ($self->{'tcp_chld'})
1018 0 0 unless (defined $self->{'tcp_chld'})
1027 0 0 if (&{$do_connect;}()) { }
1034 0 0 $! <= 255 ? :
1052 0 0 if ($child == $self->{'tcp_chld'}) { }
1053 0 0 if ($self->{'proto'} eq "stream")
1084 0 15 if ($self->{'proto'} and $self->{'proto'} eq "tcp" and $self->{'tcp_chld'})
1098 0 0 if not defined $timeout and $self->{'timeout'}
1099 0 0 if not defined $pingstring and $self->{'pingstring'}
1160 0 0 unless (defined $self->{'fh'}->fileno)
1161 0 0 unless $self->tcp_connect($ip, $timeout)
1165 0 0 if $self->{'ip'} ne $ip->{'addr_in'}
1181 0 0 unless defined $host
1183 0 0 if ($family) { }
1184 0 0 if ($family =~ /$qr_family/) { }
1185 0 0 if ($family =~ /$qr_family4/) { }
1197 0 0 unless $timeout
1200 0 0 if ($self->{'proto'} eq "stream")
1201 0 0 if (defined $self->{'fh'}->fileno) { }
1204 0 0 unless $ip
1214 0 0 if ($IP_DONTFRAG)
1216 0 0 unless setsockopt $self->{'fh'}, 0, $IP_DONTFRAG, pack("I*", $i)
1223 0 0 if ($^O eq "linux")
1225 0 0 unless setsockopt $self->{'fh'}, 0, 10, pack("I*", $i)
1234 0 73 if ($self->{'device'})
1235 0 0 unless setsockopt $self->{'fh'}, 1, 25, pack("Z*", $self->{'device'})
1238 2 71 if ($self->{'tos'})
1239 0 2 unless setsockopt $self->{'fh'}, 0, 1, pack("I*", $self->{'tos'})
1242 0 73 if ($self->{'dontfrag'})
1283 0 1 unless socket $self->{'fh'}, $ip->{'family'}, 2, $self->{'proto_num'}
1286 0 1 if (defined $self->{'local_addr'} and not CORE::bind($self->{'fh'}, &_pack_sockaddr_in(0, $self->{'local_addr'})))
1293 0 1 if ($self->{'connected'}) { }
1294 0 0 if ($self->{'connected'} ne $saddr)
1310 0 1 if ($flush)
1319 1 0 if ($flush or $connect)
1334 1 0 if ($factor > 1)
1336 1 0 if $timeout > $retrans
1343 0 1 if (not defined $nfound) { }
1 0 elsif ($nfound) { }
0 0 elsif ($timeout <= 0) { }
1352 1 0 if (not $from_saddr) { }
1354 1 0 if (not $self->{'econnrefused'} and $! == 111 || $! == 104)
1364 0 0 ref $ip eq 'HASH' ? :
1365 0 0 if (not $Net::Ping::source_verify or $from_ip eq $addr_in and $from_port == $self->{'port_num'} and $from_msg eq $msg)
1382 0 0 if (send $self->{'fh'}, $msg, 0) { }
1387 0 0 if (not $self->{'econnrefused'} and $! == 111)
1409 0 26 if ($Net::Ping::syn_forking)
1417 0 26 unless (socket $fh, $ip->{'family'}, 1, $self->{'proto_num'})
1421 0 26 if (defined $self->{'local_addr'} and not CORE::bind($fh, &_pack_sockaddr_in(0, $self->{'local_addr'})))
1432 0 26 if (connect $fh, $saddr) { }
1439 26 0 if ($! == 115 or $^O eq 'MSWin32' and $! == 11) { }
1451 26 0 if ($self->{'stop_time'} < $stop_time)
1466 0 0 if (defined $pid) { }
1467 0 0 if ($pid) { }
1471 0 0 if ($self->{'stop_time'} < $stop_time)
1479 0 0 unless (socket $self->{'fh'}, $ip->{'family'}, 1, $self->{'proto_num'})
1483 0 0 if (defined $self->{'local_addr'} and not CORE::bind($self->{'fh'}, &_pack_sockaddr_in(0, $self->{'local_addr'})))
1515 28 0 if ($self->{'proto'} eq "syn")
1516 0 28 if ($Net::Ping::syn_forking)
1518 0 0 wantarray ? :
1522 8 20 if (my $host = shift() or $self->{'host'}) { }
1524 0 8 unless defined $host
1525 0 8 if (exists $self->{'bad'}{$host})
1526 0 0 if (not $self->{'econnrefused'} and $self->{'bad'}{$host} and ($! = 111) > 0 and $self->{'bad'}{$host} eq "$!") { }
1540 8 15 if ($entry->[0] eq $host)
1547 0 8 unless defined $host_fd
1561 5 20 if $timeout <= "0.01"
1568 68 171 if (vec $wout, $fd, 1)
1571 68 0 if (my $entry = $self->{'syn'}{$fd})
1572 0 68 if ($self->{'bad'}{$entry->[0]})
1581 22 3 if (defined $winner_fd or my $nfound = mselect(undef, $wout = $wbits, undef, $timeout)) { }
3 0 elsif (defined $nfound) { }
1582 0 22 if (defined $winner_fd) { }
1593 22 0 if (my $entry = $self->{'syn'}{$fd}) { }
1598 0 22 if (not $self->{'econnrefused'} and $self->{'bad'}{$entry->[0]} and ($! = 111) > 0 and $self->{'bad'}{$entry->[0]} eq "$!") { }
19 3 elsif (getpeername $entry->[2]) { }
1616 2 1 if (not $self->{'econnrefused'} and $! == 111 || $! == 11 && $^O =~ /cygwin/i) { }
1628 6 15 wantarray ? :
1638 4 6 if (vec $wbits, $fd, 1)
1660 0 0 if ($host)
1662 0 0 if (my $entry = $self->{'good'}{$host})
1671 0 0 if (keys %{$$self{'syn'};}) { }
1676 0 0 if $timeout < "0.01"
1682 0 0 if ($timeout > 0)
1687 0 0 unless (sysread $self->{'fork_rd'}, $_, 16)
1692 0 0 if ($pid) { }
1695 0 0 if (my $entry = $self->{'syn'}{$pid}) { }
1698 0 0 if (not $how or not $self->{'econnrefused'} and $how == 111)
1701 0 0 if ($host and $entry->[0] ne $host)
1718 0 0 if (defined $nfound) { }
1725 0 0 if (my(@synners) = keys %{$$self{"syn"};})
1751 0 3 if ($self->{'proto'} eq 'syn') { }
0 3 elsif ($self->{'proto'} eq 'tcp') { }
0 3 elsif ($self->{'proto'} eq 'external') { }
1764 8 0 if (@_)
1783 0 15 if $error
1791 0 0 unless (defined $host)
1792 0 0 unless (defined $port and $port =~ /^\d+$/)
1828 61 0 if (defined $self->{'family_local'})
1839 60 1 if ($cnt == 0) { }
0 1 elsif ($cnt == 1) { }
1 0 elsif ($cnt >= 2) { }
1847 0 1 if ($name =~ /^\[.*\]:\d{1,5}$/) { }
1859 0 0 if (defined $h{'port'} and !($h{'port'} =~ /^\d{1,5}$/) || $h{'port'} < 1 || $h{'port'} > 65535)
1867 61 0 if ($Socket_VERSION > 1.94) { }
1876 33 28 if (defined $getaddr[0])
1879 32 1 if ($h{'family'} == 2) { }
1890 0 0 if (defined $ret and _inet_ntoa($ret) eq $h{'host'})
1900 28 0 if ($Socket_VERSION >= 1.94) { }
1907 28 0 if (defined $getaddr[0]) { }
1909 28 0 if (defined $address) { }
1913 28 0 if ($h{'family'} == 2) { }
1924 0 0 $family == 2 ? :
1930 0 0 if ($family == $AF_INET6)
1936 0 0 if (defined $gethost[4]) { }
1954 72 4 ref $ip eq 'HASH' ? :
1955 75 1 if (length $addr <= 4) { }
1968 8 0 if ($family == 2 or not defined $family and length $addr <= 16) { }
1981 0 0 if ($Socket_VERSION >= 1.94) { }
1983 0 0 if (defined $address) { }