line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Peep::Host::Pool; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require 5.00503; |
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
5
|
|
|
|
|
|
|
# use warnings; # commented out for 5.005 compatibility |
6
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
7
|
1
|
|
|
1
|
|
6
|
use Socket; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1152
|
|
8
|
|
|
|
|
|
|
require Exporter; |
9
|
1
|
|
|
1
|
|
7
|
use Net::Peep::Log; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
5
|
use vars qw{ @ISA %EXPORT_TAGS @EXPORT_OK @EXPORT $VERSION $AUTOLOAD @Attributes $LOGGER }; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
831
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
14
|
|
|
|
|
|
|
%EXPORT_TAGS = ( 'all' => [ qw( ) ] ); |
15
|
|
|
|
|
|
|
@EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
16
|
|
|
|
|
|
|
@EXPORT = qw( ); |
17
|
|
|
|
|
|
|
$VERSION = do { my @r = (q$Revision: 1.1 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$LOGGER = new Net::Peep::Log; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
24
|
0
|
|
0
|
|
|
|
my $class = ref($self) || $self; |
25
|
0
|
|
|
|
|
|
my $this = {}; |
26
|
0
|
|
|
|
|
|
bless $this, $class; |
27
|
0
|
|
|
|
|
|
$this->{'HOSTS'} = []; |
28
|
0
|
|
|
|
|
|
$this; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
} # end sub new |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub addHost { |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
35
|
0
|
|
0
|
|
|
|
my $host = shift || confess "Cannot add host to host pool: Host not found."; |
36
|
0
|
|
|
|
|
|
push @{$self->{'HOSTS'}}, $host; |
|
0
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
return 1; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
} # end sub addHost |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub hosts { |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
44
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
return wantarray ? @{$self->{'HOSTS'}} : $self->{'HOSTS'}; |
|
0
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
} # end sub hosts |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub getHostByName { |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
52
|
0
|
|
0
|
|
|
|
my $name = shift || confess "Cannot get host by name: No name found."; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my $return = undef; |
55
|
0
|
|
|
|
|
|
for my $host ($self->hosts()) { |
56
|
0
|
0
|
0
|
|
|
|
$return = $host if $host->name() eq $name or $host->name() eq 'localhost'; |
57
|
|
|
|
|
|
|
} |
58
|
0
|
|
|
|
|
|
return $return; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
} # end sub getHostByName |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub getHostByAddr { |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
65
|
0
|
|
0
|
|
|
|
my $addr = shift || confess "Cannot get host by IP address: No address found."; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my $return = undef; |
68
|
0
|
|
|
|
|
|
for my $host ($self->hosts()) { |
69
|
0
|
0
|
0
|
|
|
|
$return = $host if $host->ip() eq $addr or $host->ip() eq '127.0.0.1'; |
70
|
|
|
|
|
|
|
} |
71
|
0
|
|
|
|
|
|
return $return; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
} # end sub getHostByName |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub addHosts { |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
78
|
0
|
|
0
|
|
|
|
my $hosts = shift || confess "Cannot add hosts: No hosts found."; |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
my @hosts = split /\s*,\s*/, $hosts; |
81
|
0
|
|
|
|
|
|
for my $id (@hosts) { |
82
|
0
|
|
|
|
|
|
my $host = new Net::Peep::Host; |
83
|
0
|
0
|
|
|
|
|
if ($host->isIP($id)) { |
84
|
0
|
|
|
|
|
|
$host->ip($id); |
85
|
|
|
|
|
|
|
} else { |
86
|
0
|
|
|
|
|
|
$host->name($id); |
87
|
|
|
|
|
|
|
} |
88
|
0
|
|
|
|
|
|
$self->addHost($host); |
89
|
|
|
|
|
|
|
} |
90
|
0
|
|
|
|
|
|
return 1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
} # end sub addHosts |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub isInHostPool { |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
97
|
0
|
|
0
|
|
|
|
my $nameOrIp = shift || confess "Cannot check whether host is in pool: No host found."; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
my @hosts = $self->hosts(); |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
my $host = new Net::Peep::Host; |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
my $got; |
104
|
0
|
0
|
|
|
|
|
if ($host->isIP($nameOrIp)) { |
105
|
0
|
|
|
|
|
|
$got = $self->getHostByAddr($nameOrIp); |
106
|
|
|
|
|
|
|
} else { |
107
|
0
|
|
|
|
|
|
$got = $self->getHostByName($nameOrIp); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
0
|
0
|
|
|
|
|
return $got ? 1 : 0; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
} # end sub isInHostPool |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub areInHostPool { |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
117
|
0
|
|
|
|
|
|
my @hosts = @_; |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
my $host = new Net::Peep::Host; |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
my $return = 0; |
122
|
0
|
|
|
|
|
|
for my $nameOrIp (@hosts) { |
123
|
0
|
|
|
|
|
|
my $got; |
124
|
0
|
0
|
|
|
|
|
if ($self->isIP($nameOrIp)) { |
125
|
0
|
|
|
|
|
|
$got = $self->getHostByAddr($nameOrIp); |
126
|
|
|
|
|
|
|
} else { |
127
|
0
|
|
|
|
|
|
$got = $self->getHostByName($nameOrIp); |
128
|
|
|
|
|
|
|
} |
129
|
0
|
0
|
|
|
|
|
$return++ if $got; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
return $return; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
} # end areInHostPool |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
1; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
__END__ |