line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mock::Net::Ping; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
4494
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
5
|
1
|
|
|
1
|
|
32
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
35
|
|
6
|
1
|
|
|
1
|
|
4
|
no warnings 'redefine'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
7
|
1
|
|
|
1
|
|
4
|
use vars qw( $VERSION ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
4
|
use Socket qw( inet_aton ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
856
|
|
10
|
1
|
|
|
1
|
|
7
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
407
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
$VERSION = '0.09'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Override Net::Ping::ping |
15
|
|
|
|
|
|
|
# Any private IP address, localhost and any IP from 127.0.0.0/8 will always pass. |
16
|
|
|
|
|
|
|
# Other hosts and IPs will fail. |
17
|
|
|
|
|
|
|
*Net::Ping::ping = sub |
18
|
|
|
|
|
|
|
{ |
19
|
16
|
|
|
16
|
|
28822
|
my ($self, |
20
|
|
|
|
|
|
|
$host, # Name or IP number of host to ping |
21
|
|
|
|
|
|
|
$timeout, # Seconds after which ping times out |
22
|
|
|
|
|
|
|
) = @_; |
23
|
16
|
|
|
|
|
25
|
my ($ip, # Packed IP number of $host |
24
|
|
|
|
|
|
|
$ret, # The return value |
25
|
|
|
|
|
|
|
$ping_time, # When ping began |
26
|
|
|
|
|
|
|
$address # address of $host |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
16
|
100
|
100
|
|
|
115
|
croak("Usage: \$p->ping(\$host [, \$timeout])") unless @_ == 2 || @_ == 3; |
30
|
14
|
100
|
|
|
|
49
|
$timeout = $self->{"timeout"} unless defined $timeout; |
31
|
14
|
100
|
|
|
|
55
|
croak("Timeout must be greater than 0 seconds") if $timeout <= 0; |
32
|
|
|
|
|
|
|
|
33
|
12
|
100
|
|
|
|
24
|
return unless defined $host; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Dispatch to the appropriate routine. |
36
|
11
|
|
|
|
|
34
|
$ping_time = &Net::Ping::time(); |
37
|
11
|
100
|
|
|
|
114
|
if ( $host eq 'localhost' ) |
|
|
100
|
|
|
|
|
|
38
|
|
|
|
|
|
|
{ |
39
|
4
|
|
|
|
|
7
|
$address = '127.0.0.1'; |
40
|
4
|
|
|
|
|
5
|
$ret = 1; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
elsif ( $host =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/ ) |
43
|
|
|
|
|
|
|
{ |
44
|
6
|
|
|
|
|
45
|
my $packed = inet_aton( $host ); |
45
|
|
|
|
|
|
|
# modified version of regex from http://www.perlmonks.org/?node_id=791164 |
46
|
|
|
|
|
|
|
# ret = 1 if local or private and 0 otherwise |
47
|
6
|
|
|
|
|
24
|
( $ret ) = 0 + ( $packed =~ m{^(?:\x0a|\x7F|\xAC[\x10-\x1F]|\xC0\xA8)} ); |
48
|
6
|
|
|
|
|
12
|
$address = $host; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
else |
51
|
|
|
|
|
|
|
{ |
52
|
1
|
|
|
|
|
2
|
$address = $host; |
53
|
1
|
|
|
|
|
3
|
$ret = 0; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
11
|
100
|
|
|
|
38
|
return wantarray ? ($ret, &Net::Ping::time() - $ping_time, $address) : $ret; |
57
|
|
|
|
|
|
|
}; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
__END__ |