blib/lib/Net/DNS/ToolKit/RR/AFSDB.pm untested

filter: Statementstmt 0.0% 0 / 29 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 53 CC 3 SCAR 16.7
CC
3
Cov
0%
put
12.0
get
2.0
parse
2.0
CRAP 5.3
1 package Net::DNS::ToolKit::RR::AFSDB;
2  
3 use strict;
4 #use warnings;
5  
6 use Net::DNS::ToolKit qw(
7 get16
8 put16
9 dn_comp
10 dn_expand
11 );
12 use Net::DNS::Codes qw(:constants);
13 use vars qw($VERSION);
14  
15 $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::AFSDB - Resource Record Handler
20  
21 =head1 SYNOPSIS
22  
23 DO NOT use Net::DNS::ToolKit::RR::AFSDB
24 DO NOT require Net::DNS::ToolKit::RR::AFSDB
25  
26 Net::DNS::ToolKit::RR::AFSDB 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 $subtype,$hostname) = $get->AFSDB(\$buffer,$offset);
35  
36 Note: the $get->AFSDB method is normally called
37 via: @stuff = $get->next(\$buffer,$offset);
38  
39 ($newoff,@dnptrs)=$put->AFSDB(\$buffer,$offset,\@dnptrs,
40 $name,$type,$class,$ttl,$subtype,$hostname);
41  
42 $NAME,$TYPE,$CLASS,$TTL,$rdlength,$subtype,$AFSDBDNAME)
43 = $parse->AFSDB($name,$type,$class,$ttl,$rdlength,
44 $subtype,$hostname);
45  
46 =head1 DESCRIPTION
47  
48 B<Net::DNS::ToolKit::RR:AFSDB> appends an AFSDB resource record to a DNS packet
49 under construction, recovers an AFSDB resource record from a packet being decoded, and
50 converts the numeric/binary portions of the resource record to human
51 readable form.
52  
53 Description from RFC1035.txt
54  
55 3.2.1. Format
56  
57 All RRs have the same top level format shown below:
58  
59 1 1 1 1 1 1
60 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
61 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
62 | NAME |
63 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
64 | TYPE |
65 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
66 | CLASS |
67 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
68 | TTL |
69 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
70 | RDLENGTH |
71 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--|
72 | RDATA |
73 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
74  
75 NAME an owner name, i.e., the name of the node to which this
76 resource record pertains.
77  
78 TYPE two octets containing one of the RR TYPE codes.
79  
80 CLASS two octets containing one of the RR CLASS codes.
81  
82 TTL a 32 bit signed integer that specifies the time interval
83 that the resource record may be cached before the source
84 of the information should again be consulted. Zero
85 values are interpreted to mean that the RR can only be
86 used for the transaction in progress, and should not be
87 cached. For example, SOA records are always distributed
88 with a zero TTL to prohibit caching. Zero values can
89 also be used for extremely volatile data.
90  
91 RDLENGTH an unsigned 16 bit integer that specifies the length
92 in octets of the RDATA field.
93  
94 RDATA a variable length string of octets that describes the
95 resource. The format of this information varies
96 according to the TYPE and CLASS of the resource record.
97  
98 Description from RFC1183.txt
99  
100 1. AFSDB RDATA format
101  
102 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
103 | SUBTYPE |
104 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
105 / HOSTNAME /
106 / /
107 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
108  
109 where:
110  
111 AFSDB has the following format:
112  
113 <owner> <ttl> <class> AFSDB <subtype> <hostname>
114  
115 Both RDATA fields are required in all AFSDB RRs. The <subtype> field
116 is a 16 bit integer. The <hostname> field is a domain name of a host
117 that has a server for the cell named by the owner name of the RR.
118  
119 The format of the AFSDB RR is class insensitive. AFSDB records cause
120 type A additional section processing for <hostname>. This, in fact,
121 is the rationale for using a new type code, rather than trying to
122 build the same functionality with TXT RRs.
123  
124 Note that the format of AFSDB in a master file is identical to MX.
125 For purposes of the DNS itself, the subtype is merely an integer.
126 The present subtype semantics are discussed below, but changes are
127 possible and will be announced in subsequent RFCs.
128  
129 =over 4
130  
131 =item * @stuff = $get->AFSDB(\$buffer,$offset);
132  
133 Get the contents of the resource record.
134  
135 USE: @stuff = $get->next(\$buffer,$offset);
136  
137 where: @stuff = (
138 $newoff $name,$type,$class,$ttl,$rdlength,
139 $subtype,$hostname );
140  
141 All except the last two items, B<$subtype, $hostname>, are provided by
142 the class loader, B<Net::DNS::ToolKit::RR>. The code in this method knows
143 how to retrieve B<$subtype, $hostname>.
144  
145 input: pointer to buffer,
146 offset into buffer
147 returns: offset to next resource,
148 @common RR elements,
149 subtype,
150 host domain name
151  
152 =cut
153  
154 sub get {
155 my($self,$bp,$offset) = @_;
156 $offset += INT16SZ; # don't need rdlength
157 (my $subtype,$offset) = get16($bp,$offset);
158 ($offset, my $hostname) = dn_expand($bp,$offset);
159 return ($offset,$subtype,$hostname);
160 }
161  
162 =item * ($newoff,@dnptrs)=$put->AFSDB(\$buffer,$offset,\@dnptrs,
163 $name,$type,$class,$ttl,$subtype,$hostname);
164  
165 Append an AFSDB record to $buffer.
166  
167 where @common = (
168 $name,$type,$class,$ttl);
169  
170 The method will insert the $rdlength, $subtype and $hostname, then
171 return the updated pointer to the array of compressed names
172  
173 The class loader, B<Net::DNS::ToolKit::RR>, inserts the @common elements and
174 returns updated @dnptrs. This module knows how to insert its RDATA and
175 calculate the $rdlength.
176  
177 input: pointer to buffer,
178 offset (normally end of buffer),
179 pointer to compressed name array,
180 @common RR elements,
181 subtype
182 host domain name
183 output: offset to next RR,
184 new compressed name pointer array,
185 or empty list () on error.
186  
187 =cut
188  
189 sub put {
190 return () unless @_; # always return on error
191 my($self,$bp,$off,$dnp,$subtype,$hostname) = @_;
192 my $rdlp = $off; # save pointer to rdlength
193 my $doff; # data offset
194 return () unless # check for valid offset and get
195 ($doff = put16($bp,$off,0)) && # offset for subtype
196 ($off = put16($bp,$doff,$)) &&
197 (@_ = dn_comp($bp,$off,\$hostname,$dnp));
198  
199 # new offset is first item in @_
200 # rdlength = new offset - previous offset
201 put16($bp,$rdlp, $_[0] - $doff);
202 return(@_);
203 }
204  
205 =item * (@COMMON,$subtype,$AFSDBDNAME) = $parse->AFSDB(@common,$subtype,$hostname);
206  
207 Converts binary/numeric field data into human readable form. The common RR
208 elements are supplied by the class loader, B<Net::DNS::ToolKit::RR>.
209 For AFSDB RR's, this returns $hostname terminated with '.'
210  
211 input: subtype,
212 AFSDB Domain Name
213 returns: subtype
214 AFSDB Domain Name.
215  
216 =back
217  
218 =cut
219  
220 sub parse {
221 my($self,$subtype,$hostname) = @_;
222 return ($subtype,$hostname.'.');
223 }
224  
225 =head1 DEPENDENCIES
226  
227 Net::DNS::ToolKit
228 Net::DNS::Codes
229  
230 =head1 EXPORT
231  
232 none
233  
234 =head1 AUTHOR
235  
236 Michael Robinton <michael@bizsystems.com>
237  
238 =head1 COPYRIGHT
239  
240 Copyright 2003 - 2011, Michael Robinton <michael@bizsystems.com>
241
242 Michael Robinton <michael@bizsystems.com>
243  
244 All rights reserved.
245  
246 This program is free software; you can redistribute it and/or modify
247 it under the terms of either:
248  
249 a) the GNU General Public License as published by the Free
250 Software Foundation; either version 2, or (at your option) any
251 later version, or
252  
253 b) the "Artistic License" which comes with this distribution.
254  
255 This program is distributed in the hope that it will be useful,
256 but WITHOUT ANY WARRANTY; without even the implied warranty of
257 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either
258 the GNU General Public License or the Artistic License for more details.
259  
260 You should have received a copy of the Artistic License with this
261 distribution, in the file named "Artistic". If not, I'll be glad to provide
262 one.
263  
264 You should also have received a copy of the GNU General Public License
265 along with this program in the file named "Copying". If not, write to the
266  
267 Free Software Foundation, Inc.
268 59 Temple Place, Suite 330
269 Boston, MA 02111-1307, USA
270  
271 or visit their web page on the internet at:
272  
273 http://www.gnu.org/copyleft/gpl.html.
274  
275 =head1 See also:
276  
277 Net::DNS::Codes(3), Net::DNS::ToolKit(3)
278  
279 =cut
280  
281 1;