File Coverage

blib/lib/Net/DNS/ToolKit/RR/NS.pm
Criterion Covered Total %
statement 23 23 100.0
branch 2 4 50.0
condition 1 3 33.3
subroutine 7 7 100.0
pod 0 3 0.0
total 33 40 82.5


line stmt bran cond sub pod time code
1             package Net::DNS::ToolKit::RR::NS;
2              
3 6     6   960 use strict;
  6         11  
  6         230  
4             #use warnings;
5              
6 6         381 use Net::DNS::ToolKit qw(
7             put16
8             dn_comp
9             dn_expand
10 6     6   29 );
  6         10  
11 6     6   34 use Net::DNS::Codes qw(:constants);
  6         9  
  6         1701  
12 6     6   55 use vars qw($VERSION);
  6         12  
  6         1924  
13              
14             $VERSION = do { my @r = (q$Revision: 0.03 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
15              
16             =head1 NAME
17              
18             Net::DNS::ToolKit::RR::NS - Resource Record Handler
19              
20             =head1 SYNOPSIS
21              
22             DO NOT use Net::DNS::ToolKit::RR::NS
23             DO NOT require Net::DNS::ToolKit::RR::NS
24              
25             Net::DNS::ToolKit::RR::NS is autoloaded by
26             class Net::DNS::ToolKit::RR and its methods
27             are instantiated in a 'special' manner.
28              
29             use Net::DNS::ToolKit::RR;
30             ($get,$put,$parse) = new Net::DNS::ToolKit::RR;
31              
32             ($newoff,$name,$type,$class,$ttl,$rdlength,
33             $nsdname) = $get->NS(\$buffer,$offset);
34              
35             Note: the $get->NS method is normally called
36             via: @stuff = $get->next(\$buffer,$offset);
37              
38             ($newoff,@dnptrs)=$put->NS(\$buffer,$offset,\@dnptrs,
39             $name,$type,$class,$ttl,$nsdname);
40              
41             $NAME,$TYPE,$CLASS,$TTL,$rdlength,$NSDNAME)
42             = $parse->NS($name,$type,$class,$ttl,$rdlength,
43             $nsdname);
44              
45             =head1 DESCRIPTION
46              
47             B appends an NS resource record to a DNS packet under
48             construction, recovers an NS resource record from a packet being decoded, and
49             converts the numeric/binary portions of the resource record to human
50             readable form.
51              
52             Description from RFC1035.txt
53              
54             3.2.1. Format
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             | NAME |
62             +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
63             | TYPE |
64             +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
65             | CLASS |
66             +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
67             | TTL |
68             +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
69             | RDLENGTH |
70             +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--|
71             | RDATA |
72             +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
73              
74             NAME an owner name, i.e., the name of the node to which this
75             resource record pertains.
76              
77             TYPE two octets containing one of the RR TYPE codes.
78              
79             CLASS two octets containing one of the RR CLASS codes.
80              
81             TTL a 32 bit signed integer that specifies the time interval
82             that the resource record may be cached before the source
83             of the information should again be consulted. Zero
84             values are interpreted to mean that the RR can only be
85             used for the transaction in progress, and should not be
86             cached. For example, SOA records are always distributed
87             with a zero TTL to prohibit caching. Zero values can
88             also be used for extremely volatile data.
89              
90             RDLENGTH an unsigned 16 bit integer that specifies the length
91             in octets of the RDATA field.
92              
93             RDATA a variable length string of octets that describes the
94             resource. The format of this information varies
95             according to the TYPE and CLASS of the resource record.
96              
97             3.3.11. NS RDATA format
98              
99             +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
100             / NSDNAME /
101             / /
102             +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
103              
104             where:
105              
106             NSDNAME A which specifies a host which should be
107             authoritative for the specified class and domain.
108              
109             NS records cause both the usual additional section processing to locate
110             a type A record, and, when used in a referral, a special search of the
111             zone in which they reside for glue information.
112              
113             The NS RR states that the named host should be expected to have a zone
114             starting at owner name of the specified class. Note that the class may
115             not indicate the protocol family which should be used to communicate
116             with the host, although it is typically a strong hint. For example,
117             hosts which are name servers for either Internet (IN) or Hesiod (HS)
118             class information are normally queried using IN class protocols.
119              
120             =over 4
121              
122             =item * @stuff = $get->NS(\$buffer,$offset);
123              
124             Get the contents of the resource record.
125              
126             USE: @stuff = $get->next(\$buffer,$offset);
127              
128             where: @stuff = (
129             $newoff $name,$type,$class,$ttl,$rdlength,
130             $nsdname );
131              
132             All except the last item, B<$nsdname>, is provided by
133             the class loader, B. The code in this method knows
134             how to retrieve B<$nsdname>.
135              
136             input: pointer to buffer,
137             offset into buffer
138             returns: offset to next resource,
139             @common RR elements,
140             NS Domain Name
141              
142             =cut
143              
144             sub get {
145 6     6 0 2225 my($self,$bp,$offset) = @_;
146 6         39 $offset += NS_INT16SZ; # skip over rdlength
147 6         170 dn_expand($bp,$offset);
148             }
149              
150             =item * ($newoff,@dnptrs)=$put->NS(\$buffer,$offset,\@dnptrs,
151             $name,$type,$class,$ttl,$nsdname);
152              
153             Append an NS record to $buffer.
154              
155             where @common = (
156             $name,$type,$class,$ttl);
157              
158             The method will insert the $rdlength and $nsdname, then
159             pass through the updated pointer to the array of compressed names
160              
161             The class loader, B, inserts the @common elements and
162             returns updated @dnptrs. This module knows how to insert its RDATA and
163             calculate the $rdlength.
164              
165             input: pointer to buffer,
166             offset (normally end of buffer),
167             pointer to compressed name array,
168             @common RR elements,
169             NS Domain Name
170             output: offset to next RR,
171             new compressed name pointer array,
172             or empty list () on error.
173              
174             =cut
175              
176             sub put {
177 6 50   6 0 2149 return () unless @_; # always return on error
178 6         20 my($self,$bp,$off,$dnp,$nsdname) = @_;
179 6         12 my $rdlp = $off; # save pointer to rdlength
180 6 50 33     142 return () unless # check for valid offset and get
181             ($off = put16($bp,$off,0)) && # offset to name space
182             (@_ = dn_comp($bp,$off,\$nsdname,$dnp));
183             # new offset is first item in @_
184             # rdlength = new offset - previous offset
185 6         30 put16($bp,$rdlp, $_[0] - $off);
186 6         48 return @_;
187             }
188              
189             =item * (@COMMON,$NSDNAME) = $parse->NS(@common,$nsdname);
190              
191             Converts binary/numeric field data into human readable form. The common RR
192             elements are supplied by the class loader, B.
193             For NS RR's, this returns $nsdname terminated with '.'
194              
195             input: NS Domain Name
196             returns: NS Domain Name.
197              
198             =back
199              
200             =cut
201              
202             sub parse {
203 12     12 0 2130 shift; # $self
204 12         47 return ((shift).'.');
205             }
206              
207             =head1 DEPENDENCIES
208              
209             Net::DNS::ToolKit
210             Net::DNS::Codes
211              
212             =head1 EXPORT
213              
214             none
215              
216             =head1 AUTHOR
217              
218             Michael Robinton
219              
220             =head1 COPYRIGHT
221              
222             Copyright 2003 - 2011, Michael Robinton
223            
224             Michael Robinton
225              
226             All rights reserved.
227              
228             This program is free software; you can redistribute it and/or modify
229             it under the terms of either:
230              
231             a) the GNU General Public License as published by the Free
232             Software Foundation; either version 2, or (at your option) any
233             later version, or
234              
235             b) the "Artistic License" which comes with this distribution.
236              
237             This program is distributed in the hope that it will be useful,
238             but WITHOUT ANY WARRANTY; without even the implied warranty of
239             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either
240             the GNU General Public License or the Artistic License for more details.
241              
242             You should have received a copy of the Artistic License with this
243             distribution, in the file named "Artistic". If not, I'll be glad to provide
244             one.
245              
246             You should also have received a copy of the GNU General Public License
247             along with this program in the file named "Copying". If not, write to the
248              
249             Free Software Foundation, Inc.
250             59 Temple Place, Suite 330
251             Boston, MA 02111-1307, USA
252              
253             or visit their web page on the internet at:
254              
255             http://www.gnu.org/copyleft/gpl.html.
256              
257             =head1 See also:
258              
259             Net::DNS::Codes(3), Net::DNS::ToolKit(3)
260              
261             =cut
262              
263             1;