| 1 | package Net::DNS::ToolKit::RR::RT; | ||
| 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::RT - Resource Record Handler | ||
| 20 | |||
| 21 | =head1 SYNOPSIS | ||
| 22 | |||
| 23 | DO NOT use Net::DNS::ToolKit::RR::RT | ||
| 24 | DO NOT require Net::DNS::ToolKit::RR::RT | ||
| 25 | |||
| 26 | Net::DNS::ToolKit::RR::RT 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,$intermed) = $get->RT(\$buffer,$offset); | ||
| 35 | |||
| 36 | Note: the $get->RT method is normally called | ||
| 37 | via: @stuff = $get->next(\$buffer,$offset); | ||
| 38 | |||
| 39 | ($newoff,@dnptrs)=$put->RT(\$buffer,$offset,\@dnptrs, | ||
| 40 | $name,$type,$class,$ttl,$pref,$intermed); | ||
| 41 | |||
| 42 | $NAME,$TYPE,$CLASS,$TTL,$rdlength,$pref,$RTDNAME) | ||
| 43 | = $parse->RT($name,$type,$class,$ttl,$rdlength, | ||
| 44 | $pref,$intermed); | ||
| 45 | |||
| 46 | =head1 DESCRIPTION | ||
| 47 | |||
| 48 | B<Net::DNS::ToolKit::RR:RT> appends an RT resource record to a DNS packet | ||
| 49 | under construction, recovers an RT 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 | RFC 1183 RT RDATA format | ||
| 99 | |||
| 100 | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | ||
| 101 | | PREFERENCE | | ||
| 102 | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | ||
| 103 | / INTERMEDIATE / | ||
| 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 which | ||
| 114 | will serve as an intermediate in reaching the | ||
| 115 | host specified by the owner. | ||
| 116 | |||
| 117 | =over 4 | ||
| 118 | |||
| 119 | =item * @stuff = $get->RT(\$buffer,$offset); | ||
| 120 | |||
| 121 | Get the contents of the resource record. | ||
| 122 | |||
| 123 | USE: @stuff = $get->next(\$buffer,$offset); | ||
| 124 | |||
| 125 | where: @stuff = ( | ||
| 126 | $newoff $name,$type,$class,$ttl,$rdlength, | ||
| 127 | $pref,$intermed ); | ||
| 128 | |||
| 129 | All except the last two items, B<$pref, $intermed>, are provided by | ||
| 130 | the class loader, B<Net::DNS::ToolKit::RR>. The code in this method knows | ||
| 131 | how to retrieve B<$pref, $intermed>. | ||
| 132 | |||
| 133 | input: pointer to buffer, | ||
| 134 | offset into buffer | ||
| 135 | returns: offset to next resource, | ||
| 136 | @common RR elements, | ||
| 137 | preference, | ||
| 138 | mail host domain name | ||
| 139 | |||
| 140 | =cut | ||
| 141 | |||
| 142 | sub get { | ||
| 143 | my($self,$bp,$offset) = @_; | ||
| 144 | $offset += INT16SZ; # don't need rdlength | ||
| 145 | (my $pref,$offset) = get16($bp,$offset); | ||
| 146 | ($offset, my $intermed) = dn_expand($bp,$offset); | ||
| 147 | return ($offset,$pref,$intermed); | ||
| 148 | } | ||
| 149 | |||
| 150 | =item * ($newoff,@dnptrs)=$put->RT(\$buffer,$offset,\@dnptrs, | ||
| 151 | $name,$type,$class,$ttl,$pref,$intermed); | ||
| 152 | |||
| 153 | Append an RT record to $buffer. | ||
| 154 | |||
| 155 | where @common = ( | ||
| 156 | $name,$type,$class,$ttl); | ||
| 157 | |||
| 158 | The method will insert the $rdlength, $pref and $intermed, then | ||
| 159 | return the updated pointer to the array of compressed names | ||
| 160 | |||
| 161 | The class loader, B<Net::DNS::ToolKit::RR>, 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 | preference, | ||
| 170 | mail host domain name | ||
| 171 | output: offset to next RR, | ||
| 172 | new compressed name pointer array, | ||
| 173 | or empty list () on error. | ||
| 174 | |||
| 175 | =cut | ||
| 176 | |||
| 177 | sub put { | ||
| 178 | return () unless @_; # always return on error | ||
| 179 | my($self,$bp,$off,$dnp,$pref,$intermed) = @_; | ||
| 180 | my $rdlp = $off; # save pointer to rdlength | ||
| 181 | my $doff; # data offset | ||
| 182 | return () unless # check for valid offset and get | ||
| 183 | ($doff = put16($bp,$off,0)) && # offset for preference | ||
| 184 | ($off = put16($bp,$doff,$pref)) && | ||
| 185 | (@_ = dn_comp($bp,$off,\$intermed,$dnp)); | ||
| 186 | |||
| 187 | # new offset is first item in @_ | ||
| 188 | # rdlength = new offset - previous offset | ||
| 189 | put16($bp,$rdlp, $_[0] - $doff); | ||
| 190 | return(@_); | ||
| 191 | } | ||
| 192 | |||
| 193 | =item * (@COMMON,$pref,$RTDNAME) = $parse->RT(@common,$pref,$intermed); | ||
| 194 | |||
| 195 | Converts binary/numeric field data into human readable form. The common RR | ||
| 196 | elements are supplied by the class loader, B<Net::DNS::ToolKit::RR>. | ||
| 197 | For RT RR's, this returns $intermed terminated with '.' | ||
| 198 | |||
| 199 | input: preference, | ||
| 200 | RT Domain Name | ||
| 201 | returns: preference | ||
| 202 | RT Domain Name. | ||
| 203 | |||
| 204 | =back | ||
| 205 | |||
| 206 | =cut | ||
| 207 | |||
| 208 | sub parse { | ||
| 209 | my($self,$pref,$intermed) = @_; | ||
| 210 | return ($pref,$intermed.'.'); | ||
| 211 | } | ||
| 212 | |||
| 213 | =head1 DEPENDENCIES | ||
| 214 | |||
| 215 | Net::DNS::ToolKit | ||
| 216 | Net::DNS::Codes | ||
| 217 | |||
| 218 | =head1 EXPORT | ||
| 219 | |||
| 220 | none | ||
| 221 | |||
| 222 | =head1 AUTHOR | ||
| 223 | |||
| 224 | Michael Robinton <michael@bizsystems.com> | ||
| 225 | |||
| 226 | =head1 COPYRIGHT | ||
| 227 | |||
| 228 | Copyright 2003 - 2011, Michael Robinton <michael@bizsystems.com> | ||
| 229 | |||
| 230 | Michael Robinton <michael@bizsystems.com> | ||
| 231 | |||
| 232 | All rights reserved. | ||
| 233 | |||
| 234 | This program is free software; you can redistribute it and/or modify | ||
| 235 | it under the terms of either: | ||
| 236 | |||
| 237 | a) the GNU General Public License as published by the Free | ||
| 238 | Software Foundation; either version 2, or (at your option) any | ||
| 239 | later version, or | ||
| 240 | |||
| 241 | b) the "Artistic License" which comes with this distribution. | ||
| 242 | |||
| 243 | This program is distributed in the hope that it will be useful, | ||
| 244 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 245 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either | ||
| 246 | the GNU General Public License or the Artistic License for more details. | ||
| 247 | |||
| 248 | You should have received a copy of the Artistic License with this | ||
| 249 | distribution, in the file named "Artistic". If not, I'll be glad to provide | ||
| 250 | one. | ||
| 251 | |||
| 252 | You should also have received a copy of the GNU General Public License | ||
| 253 | along with this program in the file named "Copying". If not, write to the | ||
| 254 | |||
| 255 | Free Software Foundation, Inc. | ||
| 256 | 59 Temple Place, Suite 330 | ||
| 257 | Boston, MA 02111-1307, USA | ||
| 258 | |||
| 259 | or visit their web page on the internet at: | ||
| 260 | |||
| 261 | http://www.gnu.org/copyleft/gpl.html. | ||
| 262 | |||
| 263 | =head1 See also: | ||
| 264 | |||
| 265 | Net::DNS::Codes(3), Net::DNS::ToolKit(3) | ||
| 266 | |||
| 267 | =cut | ||
| 268 | |||
| 269 | 1; |