| 1 | package Net::DNS::ToolKit::RR::TYPE; | ||||||||||
| 2 | |||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | #use warnings; | ||||||||||
| 5 | #use diagnostics; | ||||||||||
| 6 | |||||||||||
| 7 | 6 | ▶ | use Net::DNS::ToolKit qw( | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | get16 | ||||||||||
| 9 | put16 | ||||||||||
| 10 | get1char | ||||||||||
| 11 | put1char | ||||||||||
| 12 | dn_comp | ||||||||||
| 13 | dn_expand | ||||||||||
| 14 | putstring | ||||||||||
| 15 | getstring | ||||||||||
| 16 | 6 | ); | |||||||||
| 17 | 6 | ▶ | use Net::DNS::Codes qw(:constants); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 6 | ▶ | use vars qw($VERSION); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | 6 | $VERSION = do { my @r = (q$Revision: 0.01 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; | |||||||||
| 21 | |||||||||||
| 22 | =head1 NAME | ||||||||||
| 23 | |||||||||||
| 24 | Net::DNS::ToolKit::RR::TYPE - Unknown Resource Record Handler | ||||||||||
| 25 | |||||||||||
| 26 | =head1 SYNOPSIS | ||||||||||
| 27 | |||||||||||
| 28 | DO NOT use Net::DNS::ToolKit::RR::TYPE | ||||||||||
| 29 | DO NOT require Net::DNS::ToolKit::RR::TYPE | ||||||||||
| 30 | |||||||||||
| 31 | Net::DNS::ToolKit::RR::TYPE 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->UnknownType(\$buffer,$offset); | ||||||||||
| 40 | |||||||||||
| 41 | Note: the $get->UnknownType method is normally called | ||||||||||
| 42 | via: @stuff = $get->next(\$buffer,$offset); | ||||||||||
| 43 | |||||||||||
| 44 | ($newoff,@dnptrs)=$put->UnknownType(\$buffer,$offset,\@dnptrs, | ||||||||||
| 45 | $name,$type,$class,$ttl,$rdlength,$textdata); | ||||||||||
| 46 | |||||||||||
| 47 | $NAME,$TYPE,$CLASS,$TTL,$rdlength,$textdata) | ||||||||||
| 48 | = $parse->UnknownType($name,$type,$class,$ttl,$rdlength, | ||||||||||
| 49 | $textdata); | ||||||||||
| 50 | |||||||||||
| 51 | =head1 DESCRIPTION | ||||||||||
| 52 | |||||||||||
| 53 | B<Net::DNS::ToolKit::RR:TYPE> is loaded once for all unknown types and their | ||||||||||
| 54 | methods redirected to the TYPE module. i.e. for TYPE61, this code snippet is | ||||||||||
| 55 | autoloaded. | ||||||||||
| 56 | |||||||||||
| 57 | package NET::DNS::ToolKit::RR::TYPE61 | ||||||||||
| 58 | *get = \&Net::DNS::ToolKit::RR::TYPE::get; | ||||||||||
| 59 | *put = \&Net::DNS::ToolKit::RR::TYPEnn::put; | ||||||||||
| 60 | *parse = \&Net::DNS::ToolKit::RR::TYPEnn::parse; | ||||||||||
| 61 | |||||||||||
| 62 | Description from RFC3597 | ||||||||||
| 63 | |||||||||||
| 64 | 5. Text Representation | ||||||||||
| 65 | |||||||||||
| 66 | In the "type" field of a master file line, an unknown RR type is | ||||||||||
| 67 | represented by the word "TYPE" immediately followed by the decimal RR | ||||||||||
| 68 | type number, with no intervening whitespace. In the "class" field, | ||||||||||
| 69 | an unknown class is similarly represented as the word "CLASS" | ||||||||||
| 70 | immediately followed by the decimal class number. | ||||||||||
| 71 | |||||||||||
| 72 | This convention allows types and classes to be distinguished from | ||||||||||
| 73 | each other and from TTL values, allowing the "[<TTL>] [<class>] | ||||||||||
| 74 | <type> <RDATA>" and "[<class>] [<TTL>] <type> <RDATA>" forms of | ||||||||||
| 75 | [RFC1035] to both be unambiguously parsed. | ||||||||||
| 76 | |||||||||||
| 77 | The RDATA section of an RR of unknown type is represented as a | ||||||||||
| 78 | sequence of white space separated words as follows: | ||||||||||
| 79 | |||||||||||
| 80 | The special token \# (a backslash immediately followed by a hash | ||||||||||
| 81 | sign), which identifies the RDATA as having the generic encoding | ||||||||||
| 82 | defined herein rather than a traditional type-specific encoding. | ||||||||||
| 83 | |||||||||||
| 84 | An unsigned decimal integer specifying the RDATA length in octets. | ||||||||||
| 85 | |||||||||||
| 86 | Zero or more words of hexadecimal data encoding the actual RDATA | ||||||||||
| 87 | field, each containing an even number of hexadecimal digits. | ||||||||||
| 88 | |||||||||||
| 89 | If the RDATA is of zero length, the text representation contains only | ||||||||||
| 90 | the \# token and the single zero representing the length. | ||||||||||
| 91 | |||||||||||
| 92 | i.e. | ||||||||||
| 93 | CLASS32 TYPE731 \# 6 abcd012345 | ||||||||||
| 94 | |||||||||||
| 95 | =over 4 | ||||||||||
| 96 | |||||||||||
| 97 | =item * @stuff = $get->UnknownType(\$buffer,$offset); | ||||||||||
| 98 | |||||||||||
| 99 | Get the contents of the resource record. | ||||||||||
| 100 | |||||||||||
| 101 | USE: @stuff = $get->next(\$buffer,$offset); | ||||||||||
| 102 | |||||||||||
| 103 | where: @stuff = ( | ||||||||||
| 104 | $newoff $name,$type,$class,$ttl,$rdlength, | ||||||||||
| 105 | $TYPEdata ); | ||||||||||
| 106 | |||||||||||
| 107 | All except the last item, B<$textdata>, is provided by | ||||||||||
| 108 | the class loader, B<Net::DNS::ToolKit::RR>. The code in this method knows | ||||||||||
| 109 | how to retrieve B<$TYPEdata>. | ||||||||||
| 110 | |||||||||||
| 111 | input: pointer to buffer, | ||||||||||
| 112 | offset into buffer | ||||||||||
| 113 | returns: offset to next resource, | ||||||||||
| 114 | @common RR elements, | ||||||||||
| 115 | TYPEdata | ||||||||||
| 116 | |||||||||||
| 117 | =cut | ||||||||||
| 118 | |||||||||||
| 119 | 5 | ▶ | sub get { | ||||||||
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 120 | 5 | my($self,$bp,$offset) = @_; | |||||||||
| 121 | 5 | (my $rdend,$offset) = get16($bp,$offset); # get rdlength | |||||||||
| 122 | 5 | (my $string,$offset) = getstring($bp,$offset,$rdend); | |||||||||
| 123 | 5 | return($offset,$string); | |||||||||
| 124 | } | ||||||||||
| 125 | |||||||||||
| 126 | =item * ($newoff,@dnptrs)=$put->UnknownType(\$buffer,$offset,\@dnptrs, | ||||||||||
| 127 | $name,$type,$class,$ttl,$rdlength,$TYPEdata); | ||||||||||
| 128 | |||||||||||
| 129 | Append an unknown record to $buffer. | ||||||||||
| 130 | |||||||||||
| 131 | where @common = ( | ||||||||||
| 132 | $name,$type,$class,$ttl); | ||||||||||
| 133 | |||||||||||
| 134 | The method will insert the $rdlength and $TYPEdata, then | ||||||||||
| 135 | pass through the updated pointer to the array of compressed names | ||||||||||
| 136 | |||||||||||
| 137 | The class loader, B<Net::DNS::ToolKit::RR>, inserts the @common elements and | ||||||||||
| 138 | returns updated @dnptrs. This module knows how to insert its RDATA and | ||||||||||
| 139 | calculate the $rdlength. | ||||||||||
| 140 | |||||||||||
| 141 | input: pointer to buffer, | ||||||||||
| 142 | offset (normally end of buffer), | ||||||||||
| 143 | pointer to compressed name array, | ||||||||||
| 144 | @common RR elements, | ||||||||||
| 145 | TYPEdata | ||||||||||
| 146 | output: offset to next RR, | ||||||||||
| 147 | new compressed name pointer array, | ||||||||||
| 148 | or empty list () on error. | ||||||||||
| 149 | |||||||||||
| 150 | =cut | ||||||||||
| 151 | |||||||||||
| 152 | 1 | ▶ | sub put { | ||||||||
|
Subroutine
put: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||
| 153 | 1 | ▶ | return () unless @_; # always return on error | ||||||||
|
Branch: 1 branch
| |||||||||||
| 154 | 1 | my($self,$bp,$off,$dnp,$TYPEdata) = @_; | |||||||||
| 155 | 1 | my $rdlp = $off; # save pointer to rdlength | |||||||||
| 156 | 1 | my $doff; | |||||||||
| 157 | 1 | ▶ | return () unless # check for valid offset and get | ||||||||
|
Branch: 1 branch
| |||||||||||
| 158 | ($off = $doff = put16($bp,$off,0)); # offset to text string | ||||||||||
| 159 | 1 | my $len = length($TYPEdata); | |||||||||
| 160 | 1 | $off = putstring($bp,$off,\$TYPEdata); | |||||||||
| 161 | # rdlength = new offset - previous offset | ||||||||||
| 162 | 1 | put16($bp,$rdlp, $off - $doff); | |||||||||
| 163 | 1 | return($off,@$dnp); | |||||||||
| 164 | } | ||||||||||
| 165 | |||||||||||
| 166 | =item * (@COMMON,$TYPEdata) = $parse->UnknownType(@common,$TYPEdata); | ||||||||||
| 167 | |||||||||||
| 168 | Converts binary/numeric field data into human readable form. The common RR | ||||||||||
| 169 | elements are supplied by the class loader, B<Net::DNS::ToolKit::RR>. | ||||||||||
| 170 | For UnknownType RR's, this returns the hex string described in RFC3597 | ||||||||||
| 171 | |||||||||||
| 172 | input: unknown binary | ||||||||||
| 173 | returns: hex string | ||||||||||
| 174 | |||||||||||
| 175 | =back | ||||||||||
| 176 | |||||||||||
| 177 | =cut | ||||||||||
| 178 | |||||||||||
| 179 | 6 | ▶ | sub parse { | ||||||||
|
Subroutine
parse: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 180 | 6 | shift; # $self | |||||||||
| 181 | 6 | my $len = length($_[0]); | |||||||||
| 182 | 6 | my $pat = 'H'. $len * 2; | |||||||||
| 183 | 6 | return '\# '. $len .' '. unpack($pat,$_[0]); | |||||||||
| 184 | } | ||||||||||
| 185 | |||||||||||
| 186 | =head1 DEPENDENCIES | ||||||||||
| 187 | |||||||||||
| 188 | Net::DNS::ToolKit | ||||||||||
| 189 | Net::DNS::Codes | ||||||||||
| 190 | |||||||||||
| 191 | =head1 EXPORT | ||||||||||
| 192 | |||||||||||
| 193 | none | ||||||||||
| 194 | |||||||||||
| 195 | =head1 AUTHOR | ||||||||||
| 196 | |||||||||||
| 197 | Michael Robinton <michael@bizsystems.com> | ||||||||||
| 198 | |||||||||||
| 199 | =head1 COPYRIGHT | ||||||||||
| 200 | |||||||||||
| 201 | Copyright 2003 - 2011, Michael Robinton <michael@bizsystems.com> | ||||||||||
| 202 | |||||||||||
| 203 | Michael Robinton <michael@bizsystems.com> | ||||||||||
| 204 | |||||||||||
| 205 | All rights reserved. | ||||||||||
| 206 | |||||||||||
| 207 | This program is free software; you can redistribute it and/or modify | ||||||||||
| 208 | it under the terms of either: | ||||||||||
| 209 | |||||||||||
| 210 | a) the GNU General Public License as published by the Free | ||||||||||
| 211 | Software Foundation; either version 2, or (at your option) any | ||||||||||
| 212 | later version, or | ||||||||||
| 213 | |||||||||||
| 214 | b) the "Artistic License" which comes with this distribution. | ||||||||||
| 215 | |||||||||||
| 216 | This program is distributed in the hope that it will be useful, | ||||||||||
| 217 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||
| 218 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either | ||||||||||
| 219 | the GNU General Public License or the Artistic License for more details. | ||||||||||
| 220 | |||||||||||
| 221 | You should have received a copy of the Artistic License with this | ||||||||||
| 222 | distribution, in the file named "Artistic". If not, I'll be glad to provide | ||||||||||
| 223 | one. | ||||||||||
| 224 | |||||||||||
| 225 | You should also have received a copy of the GNU General Public License | ||||||||||
| 226 | along with this program in the file named "Copying". If not, write to the | ||||||||||
| 227 | |||||||||||
| 228 | Free Software Foundation, Inc. | ||||||||||
| 229 | 59 Temple Place, Suite 330 | ||||||||||
| 230 | Boston, MA 02111-1307, USA | ||||||||||
| 231 | |||||||||||
| 232 | or visit their web page on the internet at: | ||||||||||
| 233 | |||||||||||
| 234 | http://www.gnu.org/copyleft/gpl.html. | ||||||||||
| 235 | |||||||||||
| 236 | =head1 See also: | ||||||||||
| 237 | |||||||||||
| 238 | Net::DNS::Codes(3), Net::DNS::ToolKit(3) | ||||||||||
| 239 | |||||||||||
| 240 | =cut | ||||||||||
| 241 | |||||||||||
| 242 | 6 | 1; | |||||||||