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

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