line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
7
|
|
|
7
|
|
109165
|
use strict; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
284
|
|
2
|
7
|
|
|
7
|
|
31
|
use warnings; |
|
7
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
302
|
|
3
|
|
|
|
|
|
|
package Test::RequiresInternet; |
4
|
|
|
|
|
|
|
$Test::RequiresInternet::VERSION = '0.05'; |
5
|
|
|
|
|
|
|
# ABSTRACT: Easily test network connectivity |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
7
|
|
|
7
|
|
4630
|
use Socket; |
|
7
|
|
|
|
|
27009
|
|
|
7
|
|
|
|
|
6529
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub import { |
11
|
6
|
100
|
|
6
|
|
58
|
skip_all("NO_NETWORK_TESTING") if env("NO_NETWORK_TESTING"); |
12
|
|
|
|
|
|
|
|
13
|
5
|
|
|
|
|
10
|
my $namespace = shift; |
14
|
|
|
|
|
|
|
|
15
|
5
|
|
|
|
|
6
|
my $argc = scalar @_; |
16
|
5
|
50
|
|
|
|
32
|
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
|
|
|
|
|
13
|
while ( @_ ) { |
24
|
5
|
|
|
|
|
8
|
my $host = shift; |
25
|
5
|
|
|
|
|
7
|
my $port = shift; |
26
|
|
|
|
|
|
|
|
27
|
5
|
|
|
|
|
6
|
local $@; |
28
|
|
|
|
|
|
|
|
29
|
5
|
|
|
|
|
7
|
eval {make_socket($host, $port)}; |
|
5
|
|
|
|
|
11
|
|
30
|
|
|
|
|
|
|
|
31
|
5
|
100
|
|
|
|
3077
|
if ( $@ ) { |
32
|
2
|
|
|
|
|
9
|
skip_all("$@"); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub make_socket { |
38
|
5
|
|
|
5
|
0
|
8
|
my ($host, $port) = @_; |
39
|
|
|
|
|
|
|
|
40
|
5
|
|
|
|
|
6
|
my $portnum; |
41
|
5
|
100
|
|
|
|
26
|
if ($port =~ /\D/) { |
42
|
2
|
|
|
|
|
1180
|
$portnum = getservbyname($port, "tcp"); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
else { |
45
|
3
|
|
|
|
|
4
|
$portnum = $port; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
5
|
100
|
|
|
|
26
|
die "Could not find a port number for $port\n" if not $portnum; |
49
|
|
|
|
|
|
|
|
50
|
4
|
100
|
|
|
|
170084
|
my $iaddr = inet_aton($host) or die "no host: $host\n"; |
51
|
|
|
|
|
|
|
|
52
|
3
|
|
|
|
|
29
|
my $paddr = sockaddr_in($portnum, $iaddr); |
53
|
3
|
|
|
|
|
821
|
my $proto = getprotobyname("tcp"); |
54
|
|
|
|
|
|
|
|
55
|
3
|
50
|
|
|
|
134
|
socket(my $sock, PF_INET, SOCK_STREAM, $proto) or die "socket: $!\n"; |
56
|
3
|
50
|
|
|
|
27706
|
connect($sock, $paddr) or die "connect: $!\n"; |
57
|
3
|
50
|
|
|
|
214
|
close ($sock) or die "close: $!\n"; |
58
|
|
|
|
|
|
|
|
59
|
3
|
|
|
|
|
24
|
1; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub env { |
63
|
6
|
100
|
|
6
|
0
|
46
|
exists $ENV{$_[0]} && $ENV{$_[0]} eq '1' |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub skip_all { |
67
|
3
|
|
|
3
|
0
|
6
|
my $reason = shift; |
68
|
3
|
|
|
|
|
960
|
print "1..0 # Skipped: $reason"; |
69
|
3
|
|
|
|
|
2444
|
exit 0; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
__END__ |