Branch Coverage

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


line true false branch
112 1 40 if (ref $proto eq 'HASH')
118 2 17 if (exists $proto->{$k})
121 0 2 if ($k eq 'pingstring')
122 0 2 if ($k eq 'source_verify')
124 0 2 if $k eq 'timeout'
125 0 2 if $k eq 'data_size'
126 0 2 if $k eq 'device'
127 0 2 if $k eq 'tos'
128 1 1 if $k eq 'ttl'
129 0 2 if $k eq 'family'
133 0 1 if (%$proto)
139 2 39 unless $proto
140 1 40 unless $proto =~ /^(icmp|icmpv6|udp|tcp|syn|stream|external)$/
144 22 18 unless defined $timeout
145 1 39 if $timeout <= 0
153 0 39 if ($self->{'host'})
155 0 0 unless my $ip = $self->_resolv($host)
161 0 39 if ($self->{'bind'}) { }
163 0 0 unless my $ip = $self->_resolv($addr)
170 11 28 if ($self->{'proto'} eq 'icmp')
171 2 2 if $ttl and $ttl < 0 || $ttl > 255
176 0 37 if ($family) { }
177 0 0 if ($family =~ /$qr_family/) { }
178 0 0 if ($family =~ /$qr_family4/) { }
187 1 36 if ($self->{'proto'} eq 'icmpv6') { }
194 4 33 $proto eq 'udp' ? :
195 35 2 unless defined $data_size and $proto ne 'tcp'
197 2 35 if $data_size < $min_datasize or $data_size > $Net::Ping::max_datasize
199 2 33 if $self->{'proto'} eq 'udp'
209 35 0 unless exists $self->{'retrans'}
211 35 0 unless exists $self->{'econnrefused'}
214 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') { }
223 0 2 unless socket $self->{'fh'}, 2, 2, $self->{'proto_num'}
229 0 9 unless _isroot()
234 0 9 unless socket $self->{'fh'}, 2, 3, $self->{'proto_num'}
237 2 7 if ($self->{'ttl'})
238 0 2 unless setsockopt $self->{'fh'}, 0, 2, pack('I*', $self->{'ttl'})
246 0 1 if $self->{'family'} and $self->{'family'} != $AF_INET6
252 0 1 unless socket $self->{'fh'}, $AF_INET6, 3, $self->{'proto_num'}
255 0 1 if ($self->{'gateway'})
257 0 0 unless my $ip = $self->_resolv($g)
259 0 0 unless $self->{'family'} eq $AF_INET6
261 0 0 unless $ip->{'family'} eq $AF_INET6
264 0 0 unless setsockopt $self->{'fh'}, $IPPROTO_IPV6, $IPV6_NEXTHOP, &_pack_sockaddr_in($ip)
267 0 1 if (exists $self->{'IPV6_USE_MIN_MTU'})
270 0 0 unless setsockopt $self->{'fh'}, $IPPROTO_IPV6, $IPV6_USE_MIN_MTU, pack('I*', $self->{'IPV6_USE_MIN_MT'})
273 0 1 if (exists $self->{'IPV6_RECVPATHMTU'})
276 0 0 unless setsockopt $self->{'fh'}, $IPPROTO_IPV6, $IPV6_RECVPATHMTU, pack('I*', $self->{'RECVPATHMTU'})
279 0 1 if ($self->{'tos'})
280 0 0 $self->{'family'} == 2 ? :
281 0 0 unless setsockopt $self->{'fh'}, $proto, 1, pack('I*', $self->{'tos'})
284 0 1 if ($self->{'ttl'})
285 0 0 $self->{'family'} == 2 ? :
286 0 0 unless setsockopt $self->{'fh'}, $proto, 2, pack('I*', $self->{'ttl'})
305 0 8 if ($Net::Ping::syn_forking) { }
335 0 0 unless @_ == 2
337 0 0 if defined $self->{'local_addr'} and $self->{'proto'} eq 'udp' || $self->{'proto'} eq 'icmp'
340 0 0 unless defined $ip
343 0 0 if ($self->{'proto'} ne 'udp' and $self->{'proto'} ne 'icmp' and $self->{'proto'} ne 'tcp' and $self->{'proto'} ne 'syn')
358 0 63 if ($_[3] > 0 and $^O eq 'MSWin32') { }
367 0 0 if $gran > $t
369 0 0 if $nfound == -1
371 0 0 if $nfound or not defined $nfound or $t <= 0
379 0 62 if $nfound == -1
391 0 0 defined $self && ref $self ? :
0 0 unless defined($Net::Ping::source_verify = defined $self && ref $self ? shift() : $self)
403 0 14 unless defined($self->{'econnrefused'} = shift())
422 0 0 unless $^O eq 'MSWin32' or $^O eq 'cygwin'
423 0 0 unless eval { do { require Win32 } }
424 0 0 unless defined &Win32::IsAdminUser
429 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/) { }
448 0 0 if ($on) { }
450 0 0 unless ($reachconf)
454 0 0 unless (_isroot())
471 0 0 if (defined $on) { }
477 0 0 $on ? :
479 0 0 unless setsockopt $self->{'fh'}, $IPPROTO_IPV6, $IPV6_USE_MIN_MTU, pack('I*', $self->{'IPV6_USE_MIN_MT'})
493 0 0 if ($on) { }
501 0 0 unless setsockopt $self->{'fh'}, $IPPROTO_IPV6, $IPV6_RECVPATHMTU, pack('I*', $self->{'IPV6_RECVPATHMTU'})
516 3 0 defined $self && ref $self ? :
1 2 unless defined($Net::Ping::hires = defined $self && ref $self ? shift() : $self)
522 108 0 $Net::Ping::hires ? :
535 0 81 if ($^O eq 'MSWin32' or $^O eq 'VMS')
539 0 0 $block ? :
540 0 0 unless ioctl $fh, $f, $v
543 81 0 if ($flags = fcntl($fh, 3, 0)) { }
544 27 54 $block ? :
545 0 81 if (not fcntl($fh, 4, $flags))
570 0 0 if not defined $host and $self->{'host'}
571 0 60 if @_ > 4 or not $host
572 60 0 unless $timeout
573 0 60 if $timeout <= 0
575 0 60 if ($family) { }
576 0 0 if ($family =~ /$qr_family/) { }
577 0 0 if ($family =~ /$qr_family4/) { }
590 0 60 unless defined $ip
594 0 60 if ($self->{'proto'} eq 'external') { }
1 59 elsif ($self->{'proto'} eq 'udp') { }
4 55 elsif ($self->{'proto'} eq 'icmp') { }
1 54 elsif ($self->{'proto'} eq 'icmpv6') { }
28 26 elsif ($self->{'proto'} eq 'tcp') { }
0 26 elsif ($self->{'proto'} eq 'stream') { }
26 0 elsif ($self->{'proto'} eq 'syn') { }
618 1 58 wantarray ? :
629 0 0 if not defined $ip and $self->{'host'}
630 0 0 if not defined $timeout and $self->{'timeout'}
633 0 0 exists $ip->{'addr_in'} ? :
635 0 0 unless eval { do { local(@INC) = @INC; pop @INC if $INC[-1] eq '.'; require Net::Ping::External } }
637 0 0 if $INC[-1] eq '.'
671 4 2 unless $self->{'proto'} eq 'icmp'
673 1 1 unless defined $type
676 1 0 unless $type =~ /^echo|timestamp$/i
712 0 0 if not defined $ip and $self->{'host'}
713 0 0 if not defined $timeout and $self->{'timeout'}
714 0 5 $self->{'message_type'} && $self->{'message_type'} eq 'timestamp' ? :
716 0 5 unless socket $self->{'fh'}, $ip->{'family'}, 3, $self->{'proto_num'}
719 0 5 if (defined $self->{'local_addr'} and not CORE::bind($self->{'fh'}, &_pack_sockaddr_in(0, $self->{'local_addr'})))
727 4 1 if ($ip->{'family'} == 2) { }
728 0 4 if ($timestamp_msg) { }
743 4 1 if ($ip->{'family'} == 2) { }
744 0 4 if ($timestamp_msg) { }
771 0 9 if (not defined $nfound) { }
8 1 elsif ($nfound) { }
785 0 8 if ($from_type == 14) { }
4 4 elsif ($from_type == 0) { }
0 4 elsif ($from_type == 129) { }
786 0 0 if length $recv_msg >= 28
791 4 0 if $ip->{'family'} == 2 and $recv_msg_len == 28
793 0 4 if $ip->{'family'} == $AF_INET6 and $recv_msg_len == 8
801 0 0 if $ip->{'family'} == $AF_INET6 and $recv_msg_len == 8
807 0 4 if length $recv_msg >= 56
813 4 4 if $from_pid != $self->{'pid'}
814 0 4 if $from_seq != $self->{'seq'}
815 4 0 if (not $Net::Ping::source_verify or $self->ntop($from_ip) eq $self->ntop($ip))
816 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) { }
844 0 0 unless 4 == length $addr
869 0 5 if $len_msg % 2
894 0 0 if not defined $ip and $self->{'host'}
895 0 0 if not defined $timeout and $self->{'timeout'}
899 11 16 if (not $self->{'econnrefused'} and $! == 111)
915 0 0 if not defined $ip and $self->{'host'}
916 0 0 if not defined $timeout and $self->{'timeout'}
923 0 28 unless socket $self->{'fh'}, $ip->{'family'}, 1, $self->{'proto_num'}
925 0 28 if (defined $self->{'local_addr'} and not CORE::bind($self->{'fh'}, &_pack_sockaddr_in(0, $self->{'local_addr'})))
942 28 0 if (not connect($self->{'fh'}, $saddr)) { }
943 0 28 if ($! == 111) { }
0 28 elsif ($! != 115 and $^O ne 'MSWin32' || $! != 11) { }
944 0 0 unless $self->{'econnrefused'}
960 0 28 $^O eq 'MSWin32' ? :
964 0 27 unless defined $nfound
966 21 6 if ($nfound and vec $wout, $self->{'fh'}->fileno, 1) { }
971 9 12 if (getpeername $self->{'fh'}) { }
981 0 12 if $! == 11 and $^O =~ /cygwin/i
984 11 1 if not $self->{'econnrefused'} and $! == 111
989 0 6 if ($^O =~ /MSWin32/)
994 0 0 if ($nfound and vec $wexc, $self->{'fh'}->fileno, 1)
1012 0 28 if ($Net::Ping::syn_forking) { }
1021 0 0 unless ($self->{'tcp_chld'})
1022 0 0 unless (defined $self->{'tcp_chld'})
1031 0 0 if (&{$do_connect;}()) { }
1038 0 0 $! <= 255 ? :
1056 0 0 if ($child == $self->{'tcp_chld'}) { }
1057 0 0 if ($self->{'proto'} eq 'stream')
1088 0 15 if ($self->{'proto'} eq 'tcp' and $self->{'tcp_chld'})
1103 0 0 if not defined $timeout and $self->{'timeout'}
1104 0 0 if not defined $pingstring and $self->{'pingstring'}
1165 0 0 unless (defined $self->{'fh'}->fileno)
1166 0 0 unless $self->tcp_connect($ip, $timeout)
1170 0 0 if $self->{'ip'} ne $ip->{'addr_in'}
1186 0 0 unless defined $host
1188 0 0 if ($family) { }
1189 0 0 if ($family =~ /$qr_family/) { }
1190 0 0 if ($family =~ /$qr_family4/) { }
1202 0 0 unless $timeout
1205 0 0 if ($self->{'proto'} eq 'stream')
1206 0 0 if (defined $self->{'fh'}->fileno) { }
1209 0 0 unless $ip
1219 0 0 if ($IP_DONTFRAG)
1221 0 0 unless setsockopt $self->{'fh'}, 0, $IP_DONTFRAG, pack('I*', $i)
1228 0 0 if ($^O eq 'linux')
1230 0 0 unless setsockopt $self->{'fh'}, 0, 10, pack('I*', $i)
1239 0 72 if ($self->{'device'})
1240 0 0 unless setsockopt $self->{'fh'}, 1, 25, pack('Z*', $self->{'device'})
1243 2 70 if ($self->{'tos'})
1244 0 2 unless setsockopt $self->{'fh'}, 0, 1, pack('I*', $self->{'tos'})
1247 0 72 if ($self->{'dontfrag'})
1288 0 1 unless socket $self->{'fh'}, $ip->{'family'}, 2, $self->{'proto_num'}
1291 0 1 if (defined $self->{'local_addr'} and not CORE::bind($self->{'fh'}, &_pack_sockaddr_in(0, $self->{'local_addr'})))
1298 0 1 if ($self->{'connected'}) { }
1299 0 0 if ($self->{'connected'} ne $saddr)
1315 0 1 if ($flush)
1324 1 0 if ($flush or $connect)
1339 1 0 if ($factor > 1)
1341 1 0 if $timeout > $retrans
1348 0 1 if (not defined $nfound) { }
1 0 elsif ($nfound) { }
0 0 elsif ($timeout <= 0) { }
1357 1 0 if (not $from_saddr) { }
1359 1 0 if (not $self->{'econnrefused'} and $! == 111 || $! == 104)
1369 0 0 ref $ip eq 'HASH' ? :
1370 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)
1387 0 0 if (send $self->{'fh'}, $msg, 0) { }
1392 0 0 if (not $self->{'econnrefused'} and $! == 111)
1414 0 26 if ($Net::Ping::syn_forking)
1422 0 26 unless (socket $fh, $ip->{'family'}, 1, $self->{'proto_num'})
1426 0 26 if (defined $self->{'local_addr'} and not CORE::bind($fh, &_pack_sockaddr_in(0, $self->{'local_addr'})))
1437 0 26 if (connect $fh, $saddr) { }
1444 26 0 if ($! == 115 or $^O eq 'MSWin32' and $! == 11) { }
1456 26 0 if ($self->{'stop_time'} < $stop_time)
1471 0 0 if (defined $pid) { }
1472 0 0 if ($pid) { }
1476 0 0 if ($self->{'stop_time'} < $stop_time)
1484 0 0 unless (socket $self->{'fh'}, $ip->{'family'}, 1, $self->{'proto_num'})
1488 0 0 if (defined $self->{'local_addr'} and not CORE::bind($self->{'fh'}, &_pack_sockaddr_in(0, $self->{'local_addr'})))
1520 28 0 if ($self->{'proto'} eq 'syn')
1521 0 28 if ($Net::Ping::syn_forking)
1523 0 0 wantarray ? :
1527 8 20 if (my $host = shift() or $self->{'host'}) { }
1529 0 8 unless defined $host
1530 0 8 if (exists $self->{'bad'}{$host})
1531 0 0 if (not $self->{'econnrefused'} and $self->{'bad'}{$host} and ($! = 111) > 0 and $self->{'bad'}{$host} eq "$!") { }
1545 8 10 if ($entry->[0] eq $host)
1552 0 8 unless defined $host_fd
1566 1 24 if $timeout <= 0.01
1573 68 165 if (vec $wout, $fd, 1)
1576 68 0 if (my $entry = $self->{'syn'}{$fd})
1577 0 68 if ($self->{'bad'}{$entry->[0]})
1586 22 3 if (defined $winner_fd or my $nfound = mselect(undef, $wout = $wbits, undef, $timeout)) { }
3 0 elsif (defined $nfound) { }
1587 0 22 if (defined $winner_fd) { }
1598 22 0 if (my $entry = $self->{'syn'}{$fd}) { }
1603 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]) { }
1621 2 1 if (not $self->{'econnrefused'} and $! == 111 || $! == 11 && $^O =~ /cygwin/i) { }
1633 6 15 wantarray ? :
1643 4 6 if (vec $wbits, $fd, 1)
1665 0 0 if ($host)
1667 0 0 if (my $entry = $self->{'good'}{$host})
1676 0 0 if (keys %{$$self{'syn'};}) { }
1681 0 0 if $timeout < 0.01
1687 0 0 if ($timeout > 0)
1692 0 0 unless (sysread $self->{'fork_rd'}, $_, 16)
1697 0 0 if ($pid) { }
1700 0 0 if (my $entry = $self->{'syn'}{$pid}) { }
1703 0 0 if (not $how or not $self->{'econnrefused'} and $how == 111)
1706 0 0 if ($host and $entry->[0] ne $host)
1723 0 0 if (defined $nfound) { }
1730 0 0 if (my(@synners) = keys %{$$self{'syn'};})
1756 0 3 if ($self->{'proto'} eq 'syn') { }
0 3 elsif ($self->{'proto'} eq 'tcp') { }
0 3 elsif ($self->{'proto'} eq 'external') { }
1769 8 0 if (@_)
1788 0 15 if $error
1796 0 0 unless (defined $host)
1797 0 0 unless (defined $port and $port =~ /^\d+$/)
1833 60 0 if (defined $self->{'family_local'})
1844 59 1 if ($cnt == 0) { }
0 1 elsif ($cnt == 1) { }
1 0 elsif ($cnt >= 2) { }
1852 0 1 if ($name =~ /^\[.*\]:\d{1,5}$/) { }
1864 0 0 if (defined $h{'port'} and !($h{'port'} =~ /^\d{1,5}$/) || $h{'port'} < 1 || $h{'port'} > 65535)
1872 60 0 if ($Socket_VERSION > 1.94) { }
1881 33 27 if (defined $getaddr[0])
1884 32 1 if ($h{'family'} == 2) { }
1895 0 0 if (defined $ret and _inet_ntoa($ret) eq $h{'host'})
1905 27 0 if ($Socket_VERSION >= 1.94) { }
1912 27 0 if (defined $getaddr[0]) { }
1914 27 0 if (defined $address) { }
1918 27 0 if ($h{'family'} == 2) { }
1929 0 0 $family == 2 ? :
1935 0 0 if ($family == $AF_INET6)
1941 0 0 if (defined $gethost[4]) { }
1959 71 4 ref $ip eq 'HASH' ? :
1960 74 1 if (length $addr <= 4) { }
1973 8 0 if ($family == 2 or not defined $family and length $addr <= 16) { }
1986 0 0 if ($Socket_VERSION >= 1.94) { }
1988 0 0 if (defined $address) { }