| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::DNS::RR::SRV::Helper; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
21574
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
35
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
35
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use Exporter; |
|
|
1
|
|
|
|
|
7
|
|
|
|
1
|
|
|
|
|
38
|
|
|
6
|
1
|
|
|
1
|
|
876
|
use Sort::Naturally; |
|
|
1
|
|
|
|
|
4043
|
|
|
|
1
|
|
|
|
|
572
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
9
|
|
|
|
|
|
|
our @EXPORT = qw(SRVorder); |
|
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw(SRVorder); |
|
11
|
|
|
|
|
|
|
our %EXPORT_TAGS = (DEFAULT => [qw(SRVorder)]); |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Net::DNS::RR::SRV::Helper - Orders SRV records by priority and weight for Net::DNS. |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 VERSION |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Version 0.0.0 |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = '0.0.0'; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use Net::DNS; |
|
29
|
|
|
|
|
|
|
use Net::DNS::RR::SRV::Helper; |
|
30
|
|
|
|
|
|
|
use Data::Dumper; |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $query=$res->search("_ldap._tcp.foo.bar", SRV); |
|
33
|
|
|
|
|
|
|
my @answers=$query->answer; |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my @ordered=SRVorder(\@answers); |
|
36
|
|
|
|
|
|
|
if(!defined( $ordered[0] )){ |
|
37
|
|
|
|
|
|
|
print "No usable records were found.\n"; |
|
38
|
|
|
|
|
|
|
}else{ |
|
39
|
|
|
|
|
|
|
print Dumper(\@ordered); |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 EXPORT |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
SRVorder |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head2 SRVorder |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
This takes the returned answer array containing Net::DNS::RR::SRV |
|
51
|
|
|
|
|
|
|
objects and processes them into a new easy to use array of hashes |
|
52
|
|
|
|
|
|
|
ordered by priority and weight. |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
One item is taken and that is the array returned from the answers method. |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Upon a error or no records being present, undef is returned. |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub SRVorder{ |
|
61
|
0
|
|
|
0
|
1
|
|
my @records=@{$_[0]}; |
|
|
0
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
if (!defined($records[0])) { |
|
64
|
0
|
|
|
|
|
|
return undef; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
#used for assemblying this |
|
68
|
0
|
|
|
|
|
|
my %holder; |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
#process each entry |
|
71
|
0
|
|
|
|
|
|
my $int=0; |
|
72
|
0
|
|
|
|
|
|
while (defined($records[$int])) { |
|
73
|
0
|
|
|
|
|
|
my $r=$records[$int]; |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
#gets the various fields for the record |
|
76
|
0
|
|
|
|
|
|
my $priority=$r->priority; |
|
77
|
0
|
|
|
|
|
|
my $weight=$r->weight; |
|
78
|
0
|
|
|
|
|
|
my $port=$r->port; |
|
79
|
0
|
|
|
|
|
|
my $server=$r->target; |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
#makes sure they are all defined, if not skip processing it |
|
82
|
0
|
0
|
0
|
|
|
|
if ( |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
83
|
|
|
|
|
|
|
defined($priority) && |
|
84
|
|
|
|
|
|
|
defined($weight) && |
|
85
|
|
|
|
|
|
|
defined($port) && |
|
86
|
|
|
|
|
|
|
defined($server) |
|
87
|
|
|
|
|
|
|
) { |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
#makes sure the priority hash exists |
|
90
|
0
|
0
|
|
|
|
|
if (!defined($holder{$priority})) { |
|
91
|
0
|
|
|
|
|
|
$holder{$priority}={}; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
#makes sure the weight hash exists |
|
95
|
0
|
0
|
|
|
|
|
if (!defined( $holder{$priority}{$weight} )) { |
|
96
|
0
|
|
|
|
|
|
$holder{$priority}{$weight}={}; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
#makes sure that server hash exists |
|
100
|
0
|
0
|
|
|
|
|
if (!defined( $holder{$priority}{$weight}{$server} )) { |
|
101
|
0
|
|
|
|
|
|
$holder{$priority}{$weight}{$server}={} |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
$holder{$priority}{$weight}{$server}{$port}=1; |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
$int++; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
#the array to return |
|
111
|
0
|
|
|
|
|
|
my @toreturn; |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
#processes it all |
|
114
|
0
|
|
|
|
|
|
my $priInt=0; |
|
115
|
0
|
|
|
|
|
|
my @priorities=nsort(keys(%holder)); |
|
116
|
0
|
|
|
|
|
|
while ( defined($priorities[$priInt]) ) { |
|
117
|
0
|
|
|
|
|
|
my $priority=$priorities[$priInt]; |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
#process the weights for the current priority |
|
120
|
0
|
|
|
|
|
|
my @weights=reverse(nsort(keys( %{$holder{$priority}} ))); |
|
|
0
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
my $wInt=0; |
|
122
|
0
|
|
|
|
|
|
while ( defined($weights[$wInt]) ) { |
|
123
|
0
|
|
|
|
|
|
my $weight=$weights[$wInt]; |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
#process the servers |
|
126
|
0
|
|
|
|
|
|
my @servers=keys( %{ $holder{$priority}{$weight} }); |
|
|
0
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
my $sInt=0; |
|
128
|
0
|
|
|
|
|
|
while (defined( $servers[$sInt] )) { |
|
129
|
0
|
|
|
|
|
|
my $server=$servers[$sInt]; |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
#processes the ports and put the new entry onto the return array |
|
132
|
0
|
|
|
|
|
|
my @ports=keys( %{ $holder{$priority}{$weight}{$server} }); |
|
|
0
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
my $portInt=0; |
|
134
|
0
|
|
|
|
|
|
while (defined($ports[$portInt])) { |
|
135
|
0
|
|
|
|
|
|
my $port=$ports[$portInt]; |
|
136
|
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
my %serverentry; |
|
138
|
0
|
|
|
|
|
|
$serverentry{server}=$server; |
|
139
|
0
|
|
|
|
|
|
$serverentry{port}=$port; |
|
140
|
0
|
|
|
|
|
|
$serverentry{priority}=$priority; |
|
141
|
0
|
|
|
|
|
|
$serverentry{weight}=$weight; |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
#push the server entry onto to the return array |
|
144
|
0
|
|
|
|
|
|
push(@toreturn, \%serverentry); |
|
145
|
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
$portInt++; |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
$sInt++; |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
$wInt++; |
|
153
|
|
|
|
|
|
|
} |
|
154
|
|
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
$priInt++; |
|
156
|
|
|
|
|
|
|
} |
|
157
|
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
return @toreturn; |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 RETURN VALUE |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
The returned value is a array. |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Each item of the array is a hash. |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
The keys listed below are used for the hash. |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head2 server |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
This is the server to use. |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 port |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
This is the port to use for this server. |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head2 priority |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
This is the priority of this server. |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head2 weight |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
This is the weight of this server. |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 AUTHOR |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Zane C. Bowers, C<< >> |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 BUGS |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
|
192
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
|
193
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head1 SUPPORT |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
perldoc Net::DNS::RR::SRV::Helper |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
You can also look for information at: |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=over 4 |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
L |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
L |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
L |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=item * Search CPAN |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
L |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=back |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
Copyright 2010 Zane C. Bowers, all rights reserved. |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
236
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=cut |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
1; # End of Net::DNS::RR::SRV::Helper |