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

filter: Statementstmt 100% 30 / 30 Branchbran 50.0% 2 / 4 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 3 totaltotal 77.3% 41 / 53 CC 5 SCAR 12.0
CC
5
Cov
85%
put
6.1
BEGIN
1.0
BEGIN
1.0
CRAP 3.3
« blib/lib/Net/DNS/ToolKit/RR/MINFO.pm ↑ Summary blib/lib/Net/DNS/ToolKit/RR.pm »
1 package Net::DNS::ToolKit::RR::MX;
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::MX - Resource Record Handler
20  
21 =head1 SYNOPSIS
22  
23 DO NOT use Net::DNS::ToolKit::RR::MX
24 DO NOT require Net::DNS::ToolKit::RR::MX
25  
26 Net::DNS::ToolKit::RR::MX 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 $pref,$mxdname) = $get->MX(\$buffer,$offset);
35  
36 Note: the $get->MX method is normally called
37 via: @stuff = $get->next(\$buffer,$offset);
38  
39 ($newoff,@dnptrs)=$put->MX(\$buffer,$offset,\@dnptrs,
40 $name,$type,$class,$ttl,$pref,$mxdname);
41  
42 $NAME,$TYPE,$CLASS,$TTL,$rdlength,$pref,$MXDNAME)
43 = $parse->MX($name,$type,$class,$ttl,$rdlength,
44 $pref,$mxdname);
45  
46 =head1 DESCRIPTION
47  
48 B<Net::DNS::ToolKit::RR:MX> appends an MX resource record to a DNS packet
49 under construction, recovers an MX 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 3.3.9. MX RDATA format
99  
100 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
101 | PREFERENCE |
102 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
103 / EXCHANGE /
104 / /
105 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
106  
107 where:
108  
109 PREFERENCE A 16 bit integer which specifies the
110 preference given to this RR among others at the
111 same owner. Lower values are preferred.
112  
113 EXCHANGE A <domain-name> which specifies a host willing
114 to act as a mail exchange for the owner name.
115  
116 MX records cause type A additional section processing for the host
117 specified by EXCHANGE. The use of MX RRs is explained in detail in
118 [RFC-974].
119  
120 =over 4
121  
122 =item * @stuff = $get->MX(\$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 $pref,$mxdname );
131  
132 All except the last two items, B<$pref, $mxdname>, are provided by
133 the class loader, B<Net::DNS::ToolKit::RR>. The code in this method knows
134 how to retrieve B<$pref, $mxdname>.
135  
136 input: pointer to buffer,
137 offset into buffer
138 returns: offset to next resource,
139 @common RR elements,
140 preference,
141 mail host domain name
142  
143 =cut
144  
145 1 ▶sub get {
Subroutine get: called CC=1 SCAR=0.0
Pod undocumented
146 1 my($self,$bp,$offset) = @_;
147 1 $offset += INT16SZ; # don't need rdlength
148 1 (my $pref,$offset) = get16($bp,$offset);
149 1 ($offset, my $mxdname) = dn_expand($bp,$offset);
150 1 return ($offset,$pref,$mxdname);
151 }
152  
153 =item * ($newoff,@dnptrs)=$put->MX(\$buffer,$offset,\@dnptrs,
154 $name,$type,$class,$ttl,$pref,$mxdname);
155  
156 Append an MX record to $buffer.
157  
158 where @common = (
159 $name,$type,$class,$ttl);
160  
161 The method will insert the $rdlength, $pref and $mxdname, then
162 return the updated pointer to the array of compressed names
163  
164 The class loader, B<Net::DNS::ToolKit::RR>, inserts the @common elements and
165 returns updated @dnptrs. This module knows how to insert its RDATA and
166 calculate the $rdlength.
167  
168 input: pointer to buffer,
169 offset (normally end of buffer),
170 pointer to compressed name array,
171 @common RR elements,
172 preference,
173 mail host domain name
174 output: offset to next RR,
175 new compressed name pointer array,
176 or empty list () on error.
177  
178 =cut
179  
180 1 ▶sub put {
Subroutine put: called CC=5 SCAR=18.1
Pod undocumented
181 1 ▶ return () unless @_; # always return on error
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 1 1
182 1 my($self,$bp,$off,$dnp,$pref,$mxdname) = @_;
183 1 my $rdlp = $off; # save pointer to rdlength
184 1 my $doff; # data offset
185 1 ▶ return () unless # check for valid offset and get
Branch: 1 branch
BranchTrueFalseTotal
unless $doff = put16($bp, $off, 0) and $off = put16($bp, $doff, $pref) and @_ = &dn_comp($bp, $off, \$mxdname, $dnp) 0 1 1
Condition33%2/6
$doff = put16($bp, $off, 0) and $off = put16($bp, $doff, $pref) and @_ = &dn_comp($bp, $off, \$mxdname, $dnp)
!ll&&!rl&&r
001
$doff = put16($bp, $off, 0) and $off = put16($bp, $doff, $pref)
!ll&&!rl&&r
001
MC/DC0%0/3
$doff = put16($bp, $off, 0) and $off = put16($bp, $doff, $pref) and @_ = &dn_comp($bp, $off, \$mxdname, $dnp)
$doff = put16($bp, $off, 0) $off = put16($bp, $doff, $pref) @_ = &dn_comp($bp, $off, \$mxdname, $dnp)
Truth table25%1/4
A and B and C
A= $doff = put16($bp, $off, 0)B= $off = put16($bp, $doff, $pref)C= @_ = &dn_comp($bp, $off, \$mxdname, $dnp)
ABCresult
0XX0
10X0
1100
1111
186 ($doff = put16($bp,$off,0)) && # offset for preference
187 ($off = put16($bp,$doff,$pref)) &&
188 (@_ = dn_comp($bp,$off,\$mxdname,$dnp));
189  
190 # new offset is first item in @_
191 # rdlength = new offset - previous offset
192 1 put16($bp,$rdlp, $_[0] - $doff);
193 1 return(@_);
194 }
195  
196 =item * (@COMMON,$pref,$MXDNAME) = $parse->MX(@common,$pref,$mxdname);
197  
198 Converts binary/numeric field data into human readable form. The common RR
199 elements are supplied by the class loader, B<Net::DNS::ToolKit::RR>.
200 For MX RR's, this returns $mxdname terminated with '.'
201  
202 input: preference,
203 MX Domain Name
204 returns: preference
205 MX Domain Name.
206  
207 =back
208  
209 =cut
210  
211 1 ▶sub parse {
Subroutine parse: called CC=1 SCAR=0.0
Pod undocumented
212 1 my($self,$pref,$mxdname) = @_;
213 1 return ($pref,$mxdname.'.');
214 }
215  
216 =head1 DEPENDENCIES
217  
218 Net::DNS::ToolKit
219 Net::DNS::Codes
220  
221 =head1 EXPORT
222  
223 none
224  
225 =head1 AUTHOR
226  
227 Michael Robinton <michael@bizsystems.com>
228  
229 =head1 COPYRIGHT
230  
231 Copyright 2003 - 2011, Michael Robinton <michael@bizsystems.com>
232
233 Michael Robinton <michael@bizsystems.com>
234  
235 All rights reserved.
236  
237 This program is free software; you can redistribute it and/or modify
238 it under the terms of either:
239  
240 a) the GNU General Public License as published by the Free
241 Software Foundation; either version 2, or (at your option) any
242 later version, or
243  
244 b) the "Artistic License" which comes with this distribution.
245  
246 This program is distributed in the hope that it will be useful,
247 but WITHOUT ANY WARRANTY; without even the implied warranty of
248 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either
249 the GNU General Public License or the Artistic License for more details.
250  
251 You should have received a copy of the Artistic License with this
252 distribution, in the file named "Artistic". If not, I'll be glad to provide
253 one.
254  
255 You should also have received a copy of the GNU General Public License
256 along with this program in the file named "Copying". If not, write to the
257  
258 Free Software Foundation, Inc.
259 59 Temple Place, Suite 330
260 Boston, MA 02111-1307, USA
261  
262 or visit their web page on the internet at:
263  
264 http://www.gnu.org/copyleft/gpl.html.
265  
266 =head1 See also:
267  
268 Net::DNS::Codes(3), Net::DNS::ToolKit(3)
269  
270 =cut
271  
272 1 1;
« blib/lib/Net/DNS/ToolKit/RR/MINFO.pm ↑ Summary blib/lib/Net/DNS/ToolKit/RR.pm »