Net/Prober/ping.pm untested

filter: Statementstmt 0.0% 0 / 24 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 37 CC 4 SCAR 24.0
CC
4
Cov
0%
probe
20.0
defaults
2.0
BEGIN
2.0
CRAP 11.0
1 package Net::Prober::ping;
2 $Net::Prober::ping::VERSION = '0.16';
3 use strict;
4 use warnings;
5 use base 'Net::Prober::Probe::Base';
6  
7 sub defaults {
8 return {
9 host => undef,
10 port => undef,
11 timeout => undef,
12 # icmp requires root privileges, but we don't use tcp
13 # because it may incorrectly report hosts as down
14 proto => 'icmp',
15 size => undef,
16 };
17 }
18  
19 sub probe {
20 my ($self, $args) = @_;
21  
22 my ($host, $port, $timeout, $proto, $size) =
23 $self->parse_args($args, qw(host port timeout proto size));
24  
25 #my ($host, $port, $timeout, $proto, $size) =
26 # @{$probe}{qw(host port timeout proto size)};
27  
28 my $pinger = Net::Ping->new($proto, $timeout);
29 $pinger->hires();
30  
31 if (defined $port) {
32 if ($proto eq 'icmp') {
33 Carp::croak("Ping on port $port with icmp protocol is not implemented");
34 }
35 $pinger->port_number($port);
36 }
37  
38 my ($ok, $elapsed, $ip) = $pinger->ping($host);
39 $pinger->close();
40  
41 my $result = {
42 ok => $ok ? 1 : 0,
43 time => $elapsed,
44 ip => $ip,
45 };
46  
47 return $result;
48 }
49  
50 1;
51  
52 __END__