| 1 | package Net::DNS::ToolKit::RR::ISDN; | ||
| 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::ISDN - Resource Record Handler | ||
| 25 | |||
| 26 | =head1 SYNOPSIS | ||
| 27 | |||
| 28 | DO NOT use Net::DNS::ToolKit::RR::ISDN | ||
| 29 | DO NOT require Net::DNS::ToolKit::RR::ISDN | ||
| 30 | |||
| 31 | Net::DNS::ToolKit::RR::ISDN 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->ISDN(\$buffer,$offset); | ||
| 40 | |||
| 41 | Note: the $get->ISDN method is normally called | ||
| 42 | via: @stuff = $get->next(\$buffer,$offset); | ||
| 43 | |||
| 44 | ($newoff,@dnptrs)=$put->ISDN(\$buffer,$offset,\@dnptrs, | ||
| 45 | $name,$type,$class,$ttl,$rdlength,$textdata); | ||
| 46 | |||
| 47 | $NAME,$TYPE,$CLASS,$TTL,$rdlength,$textdata) | ||
| 48 | = $parse->ISDN($name,$type,$class,$ttl,$rdlength, | ||
| 49 | $textdata); | ||
| 50 | |||
| 51 | =head1 DESCRIPTION | ||
| 52 | |||
| 53 | B<Net::DNS::ToolKit::RR:ISDN> appends an ISDN resource record to a DNS packet under | ||
| 54 | construction, recovers an ISDN 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 ISDN RDATA format | ||
| 104 | |||
| 105 | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | ||
| 106 | / ISDN-ADDRESS / | ||
| 107 | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | ||
| 108 | / SUBADDRESS / | ||
| 109 | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | ||
| 110 | |||
| 111 | where: | ||
| 112 | |||
| 113 | ISDN-ADDRESS A character-string wich identifies the ISDN number. | ||
| 114 | SUBADDRESS An optional character-string specifying the subaddress | ||
| 115 | |||
| 116 | =over 4 | ||
| 117 | |||
| 118 | =item * @stuff = $get->ISDN(\$buffer,$offset); | ||
| 119 | |||
| 120 | Get the contents of the resource record. | ||
| 121 | |||
| 122 | USE: @stuff = $get->next(\$buffer,$offset); | ||
| 123 | |||
| 124 | where: @stuff = ( | ||
| 125 | $newoff $name,$type,$class,$ttl,$rdlength, | ||
| 126 | $textdata ); | ||
| 127 | |||
| 128 | All except the last item, B<$textdata>, is provided by | ||
| 129 | the class loader, B<Net::DNS::ToolKit::RR>. The code in this method knows | ||
| 130 | how to retrieve B<$textdata>. | ||
| 131 | |||
| 132 | input: pointer to buffer, | ||
| 133 | offset into buffer | ||
| 134 | returns: offset to next resource, | ||
| 135 | @common RR elements, | ||
| 136 | text string(s) | ||
| 137 | |||
| 138 | =cut | ||
| 139 | |||
| 140 | sub get { | ||
| 141 | my($self,$bp,$offset) = @_; | ||
| 142 | (my $rdend,$offset) = get16($bp,$offset); # get rdlength | ||
| 143 | $rdend += $offset; # end pointer | ||
| 144 | my @tdata; | ||
| 145 | while($offset < $rdend) { | ||
| 146 | my $len = get1char($bp,$offset); | ||
| 147 | (my $string,$offset) = getstring($bp,$offset+1,$len); | ||
| 148 | push @tdata, $string; | ||
| 149 | } | ||
| 150 | return($offset,@tdata); | ||
| 151 | } | ||
| 152 | |||
| 153 | =item * ($newoff,@dnptrs)=$put->ISDN(\$buffer,$offset,\@dnptrs, | ||
| 154 | $name,$type,$class,$ttl,$rdlength,$textdata); | ||
| 155 | |||
| 156 | Append a ISDN record to $buffer. | ||
| 157 | |||
| 158 | where @common = ( | ||
| 159 | $name,$type,$class,$ttl); | ||
| 160 | |||
| 161 | The method will insert the $rdlength and $textdata, then | ||
| 162 | pass through 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 | text string(s). | ||
| 173 | output: offset to next RR, | ||
| 174 | new compressed name pointer array, | ||
| 175 | or empty list () on error. | ||
| 176 | |||
| 177 | Note: Double quotes embedded in the text | ||
| 178 | should be escaped. i.e. \" | ||
| 179 | |||
| 180 | =cut | ||
| 181 | |||
| 182 | sub put { | ||
| 183 | return () unless @_; # always return on error | ||
| 184 | my($self,$bp,$off,$dnp,@textdata) = @_; | ||
| 185 | my $rdlp = $off; # save pointer to rdlength | ||
| 186 | my $doff; | ||
| 187 | return () unless # check for valid offset and get | ||
| 188 | ($off = $doff = put16($bp,$off,0)); # offset to text string | ||
| 189 | foreach(0..$#textdata) { | ||
| 190 | $textdata[$_] =~ s/\\"/"/g; # unescape embedded quotes | ||
| 191 | my $len = length($textdata[$_]); | ||
| 192 | return () if $len > 255; | ||
| 193 | $off = put1char($bp,$off,$len); | ||
| 194 | $off = putstring($bp,$off,\$textdata[$_]); | ||
| 195 | } | ||
| 196 | # rdlength = new offset - previous offset | ||
| 197 | put16($bp,$rdlp, $off - $doff); | ||
| 198 | return($off,@$dnp); | ||
| 199 | } | ||
| 200 | |||
| 201 | =item * (@COMMON,$textdata) = $parse->ISDN(@common,$textdata); | ||
| 202 | |||
| 203 | Converts binary/numeric field data into human readable form. The common RR | ||
| 204 | elements are supplied by the class loader, B<Net::DNS::ToolKit::RR>. | ||
| 205 | For ISDN RR's, this returns the text strings, each surrounded by double quotes. | ||
| 206 | |||
| 207 | input: text string(s) | ||
| 208 | returns: "text string(s)" | ||
| 209 | |||
| 210 | =back | ||
| 211 | |||
| 212 | =cut | ||
| 213 | |||
| 214 | sub parse { | ||
| 215 | shift; # $self | ||
| 216 | my @ret; | ||
| 217 | foreach(@_) { | ||
| 218 | $_ =~ s/"/\\"/g; # escape embedded quotes | ||
| 219 | push @ret, '"'.$_.'"'; | ||
| 220 | } | ||
| 221 | return wantarray ? @ret : $ret[0]; | ||
| 222 | } | ||
| 223 | |||
| 224 | =head1 DEPENDENCIES | ||
| 225 | |||
| 226 | Net::DNS::ToolKit | ||
| 227 | Net::DNS::Codes | ||
| 228 | |||
| 229 | =head1 EXPORT | ||
| 230 | |||
| 231 | none | ||
| 232 | |||
| 233 | =head1 AUTHOR | ||
| 234 | |||
| 235 | Michael Robinton <michael@bizsystems.com> | ||
| 236 | |||
| 237 | =head1 COPYRIGHT | ||
| 238 | |||
| 239 | Copyright 2003 - 2011, Michael Robinton <michael@bizsystems.com> | ||
| 240 | |||
| 241 | Michael Robinton <michael@bizsystems.com> | ||
| 242 | |||
| 243 | All rights reserved. | ||
| 244 | |||
| 245 | This program is free software; you can redistribute it and/or modify | ||
| 246 | it under the terms of either: | ||
| 247 | |||
| 248 | a) the GNU General Public License as published by the Free | ||
| 249 | Software Foundation; either version 2, or (at your option) any | ||
| 250 | later version, or | ||
| 251 | |||
| 252 | b) the "Artistic License" which comes with this distribution. | ||
| 253 | |||
| 254 | This program is distributed in the hope that it will be useful, | ||
| 255 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 256 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either | ||
| 257 | the GNU General Public License or the Artistic License for more details. | ||
| 258 | |||
| 259 | You should have received a copy of the Artistic License with this | ||
| 260 | distribution, in the file named "Artistic". If not, I'll be glad to provide | ||
| 261 | one. | ||
| 262 | |||
| 263 | You should also have received a copy of the GNU General Public License | ||
| 264 | along with this program in the file named "Copying". If not, write to the | ||
| 265 | |||
| 266 | Free Software Foundation, Inc. | ||
| 267 | 59 Temple Place, Suite 330 | ||
| 268 | Boston, MA 02111-1307, USA | ||
| 269 | |||
| 270 | or visit their web page on the internet at: | ||
| 271 | |||
| 272 | http://www.gnu.org/copyleft/gpl.html. | ||
| 273 | |||
| 274 | =head1 See also: | ||
| 275 | |||
| 276 | Net::DNS::Codes(3), Net::DNS::ToolKit(3) | ||
| 277 | |||
| 278 | =cut | ||
| 279 | |||
| 280 | 1; |