line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
7
|
|
|
7
|
|
93035
|
use strict; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
227
|
|
2
|
7
|
|
|
7
|
|
28
|
use warnings; |
|
7
|
|
|
|
|
7
|
|
|
7
|
|
|
|
|
271
|
|
3
|
|
|
|
|
|
|
package Test::RequiresInternet; |
4
|
|
|
|
|
|
|
$Test::RequiresInternet::VERSION = '0.04'; |
5
|
|
|
|
|
|
|
# ABSTRACT: Easily test network connectivity |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
7
|
|
|
7
|
|
3741
|
use Socket; |
|
7
|
|
|
|
|
22225
|
|
|
7
|
|
|
|
|
5135
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub import { |
11
|
6
|
100
|
|
6
|
|
45
|
skip_all("NO_NETWORK_TESTING") if env("NO_NETWORK_TESTING"); |
12
|
|
|
|
|
|
|
|
13
|
5
|
|
|
|
|
7
|
my $namespace = shift; |
14
|
|
|
|
|
|
|
|
15
|
5
|
|
|
|
|
6
|
my $argc = scalar @_; |
16
|
5
|
50
|
|
|
|
34
|
if ( $argc == 0 ) { |
|
|
100
|
|
|
|
|
|
17
|
0
|
|
|
|
|
0
|
push @_, 'www.google.com', 80; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
elsif ( $argc % 2 != 0 ) { |
20
|
1
|
|
|
|
|
7
|
die "Must supply server and a port pairs. You supplied " . (join ", ", @_) . "\n"; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
4
|
|
|
|
|
9
|
while ( @_ ) { |
24
|
5
|
|
|
|
|
10
|
my $host = shift; |
25
|
5
|
|
|
|
|
6
|
my $port = shift; |
26
|
|
|
|
|
|
|
|
27
|
5
|
|
|
|
|
9
|
local $@; |
28
|
|
|
|
|
|
|
|
29
|
5
|
|
|
|
|
7
|
eval {make_socket($host, $port)}; |
|
5
|
|
|
|
|
11
|
|
30
|
|
|
|
|
|
|
|
31
|
5
|
100
|
|
|
|
3795
|
if ( $@ ) { |
32
|
2
|
|
|
|
|
8
|
skip_all("$@"); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub make_socket { |
38
|
5
|
|
|
5
|
0
|
10
|
my ($host, $port) = @_; |
39
|
|
|
|
|
|
|
|
40
|
5
|
|
|
|
|
5
|
my $portnum; |
41
|
5
|
100
|
|
|
|
25
|
if ($port =~ /\D/) { |
42
|
2
|
|
|
|
|
1129
|
$portnum = getservbyname($port, "tcp"); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
else { |
45
|
3
|
|
|
|
|
5
|
$portnum = $port; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
5
|
100
|
|
|
|
24
|
die "Could not find a port number for $port\n" if not $portnum; |
49
|
|
|
|
|
|
|
|
50
|
4
|
100
|
|
|
|
109382
|
my $iaddr = inet_aton($host) or die "no host: $host\n"; |
51
|
|
|
|
|
|
|
|
52
|
3
|
|
|
|
|
24
|
my $paddr = sockaddr_in($portnum, $iaddr); |
53
|
3
|
|
|
|
|
650
|
my $proto = getprotobyname("tcp"); |
54
|
|
|
|
|
|
|
|
55
|
3
|
50
|
|
|
|
120
|
socket(my $sock, PF_INET, SOCK_STREAM, $proto) or die "socket: $!\n"; |
56
|
3
|
50
|
|
|
|
55879
|
connect($sock, $paddr) or die "connect: $!\n"; |
57
|
3
|
50
|
|
|
|
237
|
close ($sock) or die "close: $!\n"; |
58
|
|
|
|
|
|
|
|
59
|
3
|
|
|
|
|
36
|
1; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub env { |
63
|
6
|
100
|
|
6
|
0
|
42
|
exists $ENV{$_[0]} && $ENV{$_[0]} eq '1' |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub skip_all { |
67
|
3
|
|
|
3
|
0
|
8
|
my $reason = shift; |
68
|
3
|
|
|
|
|
906
|
print "1..0 # Skipped: $reason"; |
69
|
3
|
|
|
|
|
2165
|
exit 0; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
__END__ |