blib/lib/Net/DNS/ToolKit/RR/SRV.pm

filter: Statementstmt 100% 33 / 33 Branchbran 50.0% 2 / 4 Conditioncond 33.3% 4 / 12 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 3 totaltotal 71.8% 46 / 64 CC 7 SCAR 18.1
CC
7
Cov
80%
put
10.5
BEGIN
1.0
BEGIN
1.0
CRAP 6.1
« blib/lib/Net/DNS/ToolKit/RR/X25.pm ↑ Summary blib/lib/Net/DNS/ToolKit.pm »
1 package Net::DNS::ToolKit::RR::SRV;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 #use warnings;
5  
6 1 ▶use Net::DNS::ToolKit qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
7 get16
8 put16
9 dn_comp
10 dn_expand
11 1 );
12 1 ▶use Net::DNS::Codes qw(:constants);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 $VERSION = do { my @r = (q$Revision: 0.03 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
16  
17 =head1 NAME
18  
19 Net::DNS::ToolKit::RR::SRV - Resource Record Handler
20  
21 =head1 SYNOPSIS
22  
23 DO NOT use Net::DNS::ToolKit::RR::SRV
24 DO NOT require Net::DNS::ToolKit::RR::SRV
25  
26 Net::DNS::ToolKit::RR::SRV is autoloaded by
27 class Net::DNS::ToolKit::RR and its methods
28 are instantiated in a 'special' manner.
29  
30 use Net::DNS::ToolKit::RR;
31 ($get,$put,$parse) = new Net::DNS::ToolKit::RR;
32  
33 ($newoff,$name,$type,$class,$ttl,$rdlength,
34 $priority,$weight,$port,$target) = $get->SRV(\$buffer,$offset);
35  
36 Note: the $get->SRV method is normally called
37 via: @stuff = $get->next(\$buffer,$offset);
38  
39 ($newoff,@dnptrs)=$put->SRV(\$buffer,$offset,\@dnptrs,
40 $name,$type,$class,$ttl,$rdlength,
41 $priority,$weight,$port,$target);
42  
43 ($NAME,$TYPE,$CLASS,$TTL,$rdlength,$priority,$weight,$port,$target)
44 = $parse->SRV($name,$type,$class,$ttl,$rdlength,
45 $priority,$weight,$port,$target);
46  
47 =head1 DESCRIPTION
48  
49 B<Net::DNS::ToolKit::RR:SRV> appends an SRV resource record to a DNS packet
50 under construction, recovers an SRV resource record from a packet being decoded, and
51 converts the numeric/binary portions of the resource record to human
52 readable form.
53  
54 Description from RFC2782.txt
55  
56 All RRs have the same top level format shown below:
57  
58 1 1 1 1 1 1
59 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
60 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
61 | _SERVICE._PROTO.NAME |
62 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
63 | TYPE |
64 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
65 | CLASS |
66 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
67 | TTL |
68 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
69 | RDLENGTH |
70 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
71 | PRIORITY |
72 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
73 | WEIGHT |
74 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
75 | PORT |
76 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
77 | TARGET |
78 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
79  
80 _Service._Proto.Name TTL Class SRV Priority Weight Port Target
81  
82  
83 SERVICE The symbolic name of the desired service, as defined in
84 Assigned Numbers [STD 2] or locally. An underscore (_) is
85 prepended to the service identifier to avoid collisions with
86 DNS labels that occur in nature.
87 Some widely used services, notably POP, don't have a single
88 universal name. If Assigned Numbers names the service
89 indicated, that name is the only name which is legal for SRV
90 lookups. The Service is case insensitive.
91  
92 PROTO The symbolic name of the desired protocol, with an underscore
93 (_) prepended to prevent collisions with DNS labels that occur
94 in nature. _TCP and _UDP are at present the most useful values
95 for this field, though any name defined by Assigned Numbers or
96 locally may be used (as for Service). The Proto is case
97 insensitive.
98  
99 NAME The domain this RR refers to. The SRV RR is unique in that the
100 name one searches for is not this name; the example near the end
101 shows this clearly.
102  
103 TYPE two octets containing one of the RR TYPE codes.
104  
105 CLASS two octets containing one of the RR CLASS codes.
106  
107 TTL a 32 bit signed integer that specifies the time interval
108 that the resource record may be cached before the source
109 of the information should again be consulted. Zero
110 values are interpreted to mean that the RR can only be
111 used for the transaction in progress, and should not be
112 cached. For example, SOA records are always distributed
113 with a zero TTL to prohibit caching. Zero values can
114 also be used for extremely volatile data.
115  
116 RDLENGTH an unsigned 16 bit integer that specifies the length
117 in octets of the followin RDATA field.
118  
119 PRIORITY The priority of this target host. A client MUST attempt to
120 contact the target host with the lowest-numbered priority it can
121 reach; target hosts with the same priority SHOULD be tried in an
122 order defined by the weight field. The range is 0-65535. This
123 is a 16 bit unsigned integer in network byte order.
124  
125 WEIGHT A server selection mechanism. The weight field specifies a
126 relative weight for entries with the same priority. Larger
127 weights SHOULD be given a proportionately higher probability of
128 being selected. The range of this number is 0-65535. This is a
129 16 bit unsigned integer in network byte order. Domain
130 administrators SHOULD use Weight 0 when there isn't any server
131 selection to do, to make the RR easier to read for humans (less
132 noisy). In the presence of records containing weights greater
133 than 0, records with weight 0 should have a very small chance of
134 being selected.
135  
136 In the absence of a protocol whose specification calls for the
137 use of other weighting information, a client arranges the SRV
138 RRs of the same Priority in the order in which target hosts,
139 specified by the SRV RRs, will be contacted. The following
140 algorithm SHOULD be used to order the SRV RRs of the same
141 priority:
142  
143 To select a target to be contacted next, arrange all SRV RRs
144 (that have not been ordered yet) in any order, except that all
145 those with weight 0 are placed at the beginning of the list.
146  
147 Compute the sum of the weights of those RRs, and with each RR
148 associate the running sum in the selected order. Then choose a
149 uniform random number between 0 and the sum computed
150 (inclusive), and select the RR whose running sum value is the
151 first in the selected order which is greater than or equal to
152 the random number selected. The target host specified in the
153 selected SRV RR is the next one to be contacted by the client.
154 Remove this SRV RR from the set of the unordered SRV RRs and
155 apply the described algorithm to the unordered SRV RRs to select
156 the next target host. Continue the ordering process until there
157 are no unordered SRV RRs. This process is repeated for each
158 Priority.
159  
160 PORT The port on this target host of this service. The range is 0-
161 65535. This is a 16 bit unsigned integer in network byte order.
162 This is often as specified in Assigned Numbers but need not be.
163  
164 TARGET The domain name of the target host. There MUST be one or more
165 address records for this name, the name MUST NOT be an alias (in
166 the sense of RFC 1034 or RFC 2181). Implementors are urged, but
167 not required, to return the address record(s) in the Additional
168 Data section. Unless and until permitted by future standards
169 action, name compression is not to be used for this field.
170  
171 A Target of "." means that the service is decidedly not
172 available at this domain.
173  
174 =over 4
175  
176 =item * @stuff = $get->SRV(\$buffer,$offset);
177  
178 Get the contents of the resource record.
179  
180 USE: @stuff = $get->next(\$buffer,$offset);
181  
182 where: @stuff = (
183 $newoff $name,$type,$class,$ttl,$rdlength,
184 $priority,$weight,$port,$target);
185  
186 All except the last four items, B<$priority,$weight,$port,$target>, are
187 provided by the class loader, B<Net::DNS::ToolKit::RR>. The code in this
188 method knows how to retrieve B<$priority,$weight,$port,$target>.
189  
190 input: pointer to buffer,
191 offset into buffer
192 returns: offset to next resource,
193 @common RR elements,
194 priority
195 weight
196 port
197 target name
198  
199 =cut
200  
201 1 ▶sub get {
Subroutine get: called CC=1 SCAR=0.0
Pod undocumented
202 1 my($self,$bp,$offset) = @_;
203 1 $offset += INT16SZ; # don't need rdlength
204 1 (my $priority,$offset) = get16($bp,$offset);
205 1 (my $weight,$offset) = get16($bp,$offset);
206 1 (my $port,$offset) = get16($bp,$offset);
207 1 ($offset, my $target) = dn_expand($bp,$offset);
208 1 return ($offset,$priority,$weight,$port,$target);
209 }
210  
211 =item * ($newoff,@dnptrs)=$put->SRV(\$buffer,$offset,\@dnptrs,
212 $name,$type,$class,$ttl,$subtype,$hostname);
213  
214 Append an SRV record to $buffer.
215  
216 where @common = (
217 $name,$type,$class,$ttl);
218  
219 The method will insert the $rdlength, $subtype and $hostname, then
220 return the updated pointer to the array of compressed names
221  
222 The class loader, B<Net::DNS::ToolKit::RR>, inserts the @common elements and
223 returns updated @dnptrs. This module knows how to insert its RDATA and
224 calculate the $rdlength.
225  
226 input: pointer to buffer,
227 offset (normally end of buffer),
228 pointer to compressed name array,
229 @common RR elements,
230 priority
231 weight
232 port
233 target name
234 output: offset to next RR,
235 new pointer array,
236 or empty list () on error.
237  
238 =cut
239  
240 1 ▶sub put {
Subroutine put: called CC=7 SCAR=23.6
Pod undocumented
241 1 ▶ return () unless @_; # always return on error
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 1 1
242 1 my($self,$bp,$off,$dnp,$priority,$weight,$port,$target) = @_;
243 #print "$priority, $weight, $port, $target\n";
244 1 my $rdlp = $off; # save pointer to rdlength
245 1 local *tgt = \$target;
246 1 my $doff; # rdata offset
247 1 ▶ return () unless # check for valid offset and get
Branch: 1 branch
BranchTrueFalseTotal
unless $doff = put16($bp, $off, 0) and $off = put16($bp, $doff, $priority) and $off = put16($bp, $off, $weight) and $off = put16($bp, $off, $port) and @_ = &dn_comp($bp, $off, \$target) 0 1 1
Condition33%4/12
$doff = put16($bp, $off, 0) and $off = put16($bp, $doff, $priority) and $off = put16($bp, $off, $weight) and $off = put16($bp, $off, $port) and @_ = &dn_comp($bp, $off, \$target)
!ll&&!rl&&r
001
$doff = put16($bp, $off, 0) and $off = put16($bp, $doff, $priority) and $off = put16($bp, $off, $weight) and $off = put16($bp, $off, $port)
!ll&&!rl&&r
001
$doff = put16($bp, $off, 0) and $off = put16($bp, $doff, $priority) and $off = put16($bp, $off, $weight)
!ll&&!rl&&r
001
$doff = put16($bp, $off, 0) and $off = put16($bp, $doff, $priority)
!ll&&!rl&&r
001
MC/DC0%0/5
$doff = put16($bp, $off, 0) and $off = put16($bp, $doff, $priority) and $off = put16($bp, $off, $weight) and $off = put16($bp, $off, $port) and @_ = &dn_comp($bp, $off, \$target)
$doff = put16($bp, $off, 0) $off = put16($bp, $doff, $priority) $off = put16($bp, $off, $weight) $off = put16($bp, $off, $port) @_ = &dn_comp($bp, $off, \$target)
Truth table16%1/6
A and B and C and D and E
A= $doff = put16($bp, $off, 0)B= $off = put16($bp, $doff, $priority)C= $off = put16($bp, $off, $weight)D= $off = put16($bp, $off, $port)E= @_ = &dn_comp($bp, $off, \$target)
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
248 ($doff = put16($bp,$off,0)) && # offset for rdlenth
249 ($off = put16($bp,$doff,$priority)) &&
250 ($off = put16($bp,$off,$weight)) &&
251 ($off = put16($bp,$off,$port)) &&
252 (@_ = dn_comp($bp,$off,\$target));
253  
254 # new offset is first item in @_
255 # rdlength = new offset - previous offset
256 1 put16($bp,$rdlp, $_[0] - $doff);
257 1 return(@_);
258 }
259  
260 =item * (@COMMON,$priority,$weight,$port,$SRVDNAME) = $parse->SRV(@common,$priority,$weight,$target);
261  
262 Converts binary/numeric field data into human readable form. The common RR
263 elements are supplied by the class loader, B<Net::DNS::ToolKit::RR>.
264 For SRV RR's, this returns $hostname terminated with '.'
265  
266 input: priority
267 weight
268 port
269 target name
270 returns: priority
271 weight
272 port
273 SRV Domain Name.
274  
275 =back
276  
277 =cut
278  
279 1 ▶sub parse {
Subroutine parse: called CC=1 SCAR=0.0
Pod undocumented
280 1 my($self,$priority,$weight,$port,$target) = @_;
281 1 return ($priority,$weight,$port,$target.'.');
282 }
283  
284 =head1 DEPENDENCIES
285  
286 Net::DNS::ToolKit
287 Net::DNS::Codes
288  
289 =head1 EXPORT
290  
291 none
292  
293 =head1 AUTHOR
294  
295 Michael Robinton <michael@bizsystems.com>
296  
297 =head1 COPYRIGHT
298  
299 Copyright 2003 - 2013, Michael Robinton <michael@bizsystems.com>
300
301 Michael Robinton <michael@bizsystems.com>
302  
303 All rights reserved.
304  
305 This program is free software; you can redistribute it and/or modify
306 it under the terms of either:
307  
308 a) the GNU General Public License as published by the Free
309 Software Foundation; either version 2, or (at your option) any
310 later version, or
311  
312 b) the "Artistic License" which comes with this distribution.
313  
314 This program is distributed in the hope that it will be useful,
315 but WITHOUT ANY WARRANTY; without even the implied warranty of
316 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either
317 the GNU General Public License or the Artistic License for more details.
318  
319 You should have received a copy of the Artistic License with this
320 distribution, in the file named "Artistic". If not, I'll be glad to provide
321 one.
322  
323 You should also have received a copy of the GNU General Public License
324 along with this program in the file named "Copying". If not, write to the
325  
326 Free Software Foundation, Inc.
327 59 Temple Place, Suite 330
328 Boston, MA 02111-1307, USA
329  
330 or visit their web page on the internet at:
331  
332 http://www.gnu.org/copyleft/gpl.html.
333  
334 =head1 See also:
335  
336 Net::DNS::Codes(3), Net::DNS::ToolKit(3)
337  
338 =cut
339  
340 1 1;
« blib/lib/Net/DNS/ToolKit/RR/X25.pm ↑ Summary blib/lib/Net/DNS/ToolKit.pm »