home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / RR.pm < prev    next >
Encoding:
Perl POD Document  |  2004-02-10  |  17.3 KB  |  790 lines

  1. package Net::DNS::RR;
  2. #
  3. # $Id: RR.pm,v 2.105 2004/02/09 23:28:31 ctriv Exp $
  4. #
  5. use strict;
  6. use vars qw($VERSION $AUTOLOAD);
  7.  
  8. use Carp;
  9. use Net::DNS;
  10. use Net::DNS::RR::Unknown;
  11.  
  12. $VERSION = (qw$Revision: 2.105 $)[1];
  13.  
  14. =head1 NAME
  15.  
  16. Net::DNS::RR - DNS Resource Record class
  17.  
  18. =head1 SYNOPSIS
  19.  
  20. C<use Net::DNS::RR>
  21.  
  22. =head1 DESCRIPTION
  23.  
  24. C<Net::DNS::RR> is the base class for DNS Resource Record (RR) objects.
  25. See also the manual pages for each RR type.
  26.  
  27. =head1 METHODS
  28.  
  29. B<WARNING!!!>  Don't assume the RR objects you receive from a query
  30. are of a particular type -- always check an object's type before calling
  31. any of its methods.  If you call an unknown method, you'll get a nasty
  32. warning message and C<Net::DNS::RR> will return C<undef> to the caller.
  33.  
  34. =cut
  35. #' Stupid Emacs (I Don't even USE emacs!) '
  36.  
  37. # %RR needs to be available within the scope of the BEGIN block.
  38. # $RR_REGEX is a global just to be on the safe side.  
  39. # %_LOADED is used internally for autoloading the RR subclasses.
  40. use vars qw(%RR %_LOADED $RR_REGEX);
  41.  
  42. BEGIN {
  43.  
  44.     %RR = map { $_ => 1 } qw(
  45.         A
  46.         AAAA
  47.         AFSDB
  48.         CNAME
  49.         CERT
  50.         DNAME
  51.         EID
  52.         HINFO
  53.         ISDN
  54.         LOC
  55.         MB
  56.         MG
  57.         MINFO
  58.         MR
  59.         MX
  60.         NAPTR
  61.         NIMLOC
  62.         NS
  63.         NSAP
  64.         NULL
  65.         PTR
  66.         PX
  67.         RP
  68.         RT
  69.         SOA
  70.         SRV
  71.         TKEY
  72.         TSIG
  73.         TXT
  74.         X25
  75.         OPT
  76.     );
  77.  
  78.     #  Only load DNSSEC if available
  79.     # 
  80.  
  81.     eval { require Net::DNS::RR::SIG; };
  82.  
  83.     unless ($@) {
  84.         $RR{'SIG'} = 1;
  85.     
  86.         eval { require Net::DNS::RR::NXT; };
  87.         
  88.         unless ($@) {
  89.             $RR{'NXT'}    = 1;
  90.         } else {
  91.             die $@;
  92.         }
  93.         
  94.         eval { require Net::DNS::RR::KEY; };
  95.         
  96.         unless ($@) {
  97.             $RR{'KEY'} = 1;
  98.         } else {
  99.             die $@;
  100.         }
  101.  
  102.          eval { require Net::DNS::RR::DS; };
  103.  
  104.          unless ($@) {
  105.             $RR{'DS'} = 1;
  106.  
  107.         } else {
  108.             die $@;
  109.         }
  110.  
  111.          eval { require Net::DNS::RR::RRSIG; };
  112.  
  113.          unless ($@) {
  114.             $RR{'RRSIG'} = 1;
  115.             # If RRSIG is available so should the other DNSSEC types
  116.             eval { require Net::DNS::RR::NSEC; };
  117.             unless ($@) {
  118.               $RR{'NSEC'} = 1;
  119.             } else {
  120.             die $@;
  121.           }
  122.             eval { require Net::DNS::RR::DNSKEY; };
  123.             unless ($@) {
  124.               $RR{'DNSKEY'} = 1;
  125.             } else {
  126.               die $@;
  127.             }
  128.         } 
  129.  
  130.     }
  131. }
  132.  
  133. sub build_regex {
  134.     my $classes = join('|', keys %Net::DNS::classesbyname, 'CLASS\\d+');
  135.  
  136.     # Longest ones go first, so the regex engine will match AAAA before A.
  137.     my $types   = join('|', sort { length $b <=> length $a } keys %Net::DNS::typesbyname);
  138.  
  139.     $types .= '|TYPE\\d+';
  140.                 
  141.     $RR_REGEX   = " ^ 
  142.                     \\s*
  143.                     (\\S+) # name anything non-space will do 
  144.                     \\s*                
  145.                     (\\d+)?           
  146.                     \\s*
  147.                     ($classes)?
  148.                     \\s*
  149.                     ($types)?
  150.                     \\s*
  151.                     (.*)
  152.                     \$";
  153.  
  154. #    print STDERR "Regex: $RR_REGEX\n";
  155. }
  156.  
  157.  
  158. =head2 new (from string)
  159.  
  160.  $a     = Net::DNS::RR->new("foo.example.com. 86400 A 10.1.2.3");
  161.  $mx    = Net::DNS::RR->new("example.com. 7200 MX 10 mailhost.example.com.");
  162.  $cname = Net::DNS::RR->new("www.example.com 300 IN CNAME www1.example.com");
  163.  $txt   = Net::DNS::RR->new("baz.example.com 3600 HS TXT 'text record'");
  164.  
  165. Returns a C<Net::DNS::RR> object of the appropriate type and
  166. initialized from the string passed by the user.  The format of the
  167. string is that used in zone files, and is compatible with the string
  168. returned by C<< Net::DNS::RR->string >>.
  169.  
  170. The name and RR type are required; all other information is optional.
  171. If omitted, the TTL defaults to 0 and the RR class defaults to IN.
  172. Omitting the optional fields is useful for creating the empty RDATA
  173. sections required for certain dynamic update operations.  See the
  174. C<Net::DNS::Update> manual page for additional examples.
  175.  
  176. All names must be fully qualified.  The trailing dot (.) is optional.
  177.  
  178. =head2 new (from hash)
  179.  
  180.  $rr = Net::DNS::RR->new(
  181.      name    => "foo.example.com",
  182.      ttl     => 86400,
  183.      class   => "IN",
  184.      type    => "A",
  185.      address => "10.1.2.3",
  186.  );
  187.  
  188.  $rr = Net::DNS::RR->new(
  189.      name => "foo.example.com",
  190.      type => "A",
  191.  );
  192.  
  193. Returns an RR object of the appropriate type, or a C<Net::DNS::RR>
  194. object if the type isn't implemented.  See the manual pages for
  195. each RR type to see what fields the type requires.
  196.  
  197. The C<Name> and C<Type> fields are required; all others are optional.
  198. If omitted, C<TTL> defaults to 0 and C<Class> defaults to IN.  Omitting
  199. the optional fields is useful for creating the empty RDATA sections
  200. required for certain dynamic update operations.
  201.  
  202. The fields are case-insensitive, but starting each with uppercase
  203. is recommended.
  204.  
  205. =cut
  206.  
  207. #' Stupid Emacs
  208.  
  209.  
  210. sub new {
  211.     if (@_ == 8 && ref $_[6]) {
  212.         return new_from_data(@_);
  213.     }
  214.     
  215.     if (@_ == 2 || @_ == 3) {
  216.         return new_from_string(@_);
  217.     }
  218.     
  219.     return new_from_hash(@_);
  220. }
  221.  
  222.  
  223. sub new_from_data {
  224.     my $class = shift;
  225.     my ($name, $rrtype, $rrclass, $ttl, $rdlength, $data, $offset) = @_;
  226.  
  227.     my $self = {
  228.         'name'        => $name,
  229.         'type'        => $rrtype,
  230.         'class'        => $rrclass,
  231.         'ttl'        => $ttl,
  232.         'rdlength'    => $rdlength,
  233.         'rdata'        => substr($$data, $offset, $rdlength),
  234.  
  235.     };
  236.  
  237.  
  238.     if ($RR{$rrtype}) {
  239.         my $subclass = $class->_get_subclass($rrtype);
  240.         return $subclass->new($self, $data, $offset);
  241.     } else {
  242.         return Net::DNS::RR::Unknown->new($self, $data, $offset);
  243.     }
  244.  
  245. }
  246.  
  247. sub new_from_string {
  248.     my ($class, $rrstring, $update_type) = @_;
  249.  
  250.     build_regex() unless $RR_REGEX;
  251.     
  252.     # strip out comments
  253.     $rrstring   =~ s/;.*//g;
  254.     
  255.     ($rrstring =~ m/$RR_REGEX/xso) || 
  256.         confess qq|qInternal Error: "$rrstring" did not match RR pat.\nPlease report this to the author!\n|;
  257.  
  258.     my $name    = $1;
  259.     my $ttl     = $2 || 0;
  260.     my $rrclass = $3 || '';
  261.  
  262.  
  263.     my $rrtype  = $4 || '';
  264.     my $rdata   = $5 || '';
  265.  
  266.     $rdata =~ s/\s+$// if $rdata;
  267.     $name  =~ s/\.$//  if $name;
  268.  
  269.  
  270.     # RFC3597 tweaks
  271.     # This converts to known class and type if specified as TYPE###
  272.     $rrtype  = Net::DNS::typesbyval(Net::DNS::typesbyname($rrtype))      if $rrtype  =~ m/^TYPE\d+/;
  273.     $rrclass = Net::DNS::classesbyval(Net::DNS::classesbyname($rrclass)) if $rrclass =~ m/^CLASS\d+/;
  274.  
  275.  
  276.     if (!$rrtype && $rrclass && $rrclass eq 'ANY') {
  277.         $rrtype  = 'ANY';
  278.         $rrclass = 'IN';
  279.     } elsif (!$rrclass) {
  280.         $rrclass = 'IN';
  281.     }
  282.  
  283.     $rrtype ||= 'ANY';
  284.     
  285.  
  286.     if ($update_type) {
  287.         $update_type = lc $update_type;
  288.         
  289.         if ($update_type eq 'yxrrset') {
  290.             $ttl     = 0;
  291.             $rrclass = 'ANY' unless $rdata;
  292.         } elsif ($update_type eq 'nxrrset') {
  293.             $ttl     = 0;
  294.             $rrclass = 'NONE';
  295.             $rdata   = '';
  296.         } elsif ($update_type eq 'yxdomain') {
  297.             $ttl     = 0;
  298.             $rrclass = 'ANY';
  299.             $rrtype  = 'ANY';
  300.             $rdata   = '';
  301.         } elsif ($update_type eq 'nxdomain') {
  302.             $ttl     = 0;
  303.             $rrclass = 'NONE';
  304.             $rrtype  = 'ANY';
  305.             $rdata   = '';
  306.         } elsif ($update_type =~ /^(rr_)?add$/) {
  307.             $ttl = 86400 unless $ttl;
  308.         } elsif ($update_type =~ /^(rr_)?del(ete)?$/) {
  309.             $ttl     = 0;
  310.             $rrclass = $rdata ? 'NONE' : 'ANY';
  311.         }
  312.     }
  313.  
  314.     # We used to check if $rrtype was defined at this point.  However,
  315.     # we just defaulted it to ANY earlier....
  316.  
  317.     my $self = {
  318.         'name'     => $name,
  319.         'type'     => $rrtype,
  320.         'class'    => $rrclass,
  321.         'ttl'      => $ttl,
  322.         'rdlength' => 0,
  323.         'rdata'    => '',
  324.     };
  325.  
  326.  
  327.     if ($RR{$rrtype} && $rdata !~ m/^\s*\\#/ ) {
  328.         my $subclass = $class->_get_subclass($rrtype);
  329.         
  330.         return $subclass->new_from_string($self, $rdata);
  331.     } elsif ($RR{$rrtype}) {   # A RR type known to Net::DNS starting with \#
  332.         $rdata =~ m/\\\#\s+(\d+)\s+(.*)$/;
  333.  
  334.         my $rdlength = $1;
  335.         my $hexdump  = $2;        
  336.         $hexdump =~ s/\s*//g;
  337.  
  338.         die "$rdata is inconsistent; length does not match content" 
  339.             if length($hexdump) != $rdlength*2;
  340.  
  341.         $rdata = pack('H*', $hexdump);
  342.     
  343.         return Net::DNS::RR->new_from_data(
  344.             $name, 
  345.             $rrtype, 
  346.             $rrclass, 
  347.             $ttl, 
  348.             $rdlength, 
  349.             \$rdata, 
  350.             length($rdata) - $rdlength
  351.         );
  352.     } elsif ($rdata=~/\s*\\\#\s+\d+\s+/) {   
  353.         #We are now dealing with the truly unknown.
  354.         die 'Expected RFC3597 representation of RDATA' 
  355.             unless $rdata =~ m/\\\#\s+(\d+)\s+(.*)$/;
  356.  
  357.         my $rdlength = $1;
  358.         my $hexdump  = $2;        
  359.         $hexdump =~ s/\s*//g;
  360.  
  361.         die "$rdata is inconsistent; length does not match content" 
  362.             if length($hexdump) != $rdlength*2;
  363.  
  364.         $rdata = pack('H*', $hexdump);
  365.  
  366.         return Net::DNS::RR->new_from_data(
  367.             $name,
  368.             $rrtype,
  369.             $rrclass,
  370.             $ttl,
  371.             $rdlength,
  372.             \$rdata,
  373.             length($rdata) - $rdlength
  374.         );
  375.     } else {  
  376.         #God knows how to handle these... bless them in the RR class.
  377.         bless $self, $class;
  378.         return $self
  379.     }
  380.     
  381. }
  382.  
  383. sub new_from_hash {
  384.     my $class    = shift;
  385.     my %tempself = @_;
  386.     my $self     = {};
  387.     
  388.     my ($key, $val);
  389.  
  390.     while (($key, $val) = each %tempself) {
  391.         $self->{lc($key)} = $val;
  392.     }
  393.  
  394.     Carp::croak('RR name not specified')
  395.         unless exists $self->{'name'};
  396.     Carp::croak('RR type not specified')
  397.         unless exists $self->{'type'};
  398.  
  399.     $self->{'ttl'}   ||= 0;
  400.     $self->{'class'} ||= 'IN';
  401.  
  402.     $self->{'rdlength'} = length $self->{'rdata'}
  403.         if $self->{'rdata'};
  404.  
  405.     if ($RR{$self->{'type'}}) {
  406.         my $subclass = $class->_get_subclass($self->{'type'});
  407.        
  408.         if (uc $self->{'type'} ne 'OPT') {
  409.             bless $self, $subclass;
  410.             
  411.             return $self;
  412.         } else {  
  413.             # Special processing of OPT. Since TTL and CLASS are
  414.             # set by other variables. See Net::DNS::RR::OPT 
  415.             # documentation
  416.             return $subclass->new_from_hash($self);
  417.         }
  418.     } else {
  419.          bless $self, $class;
  420.          return $self;
  421.     }
  422. }
  423.  
  424. #
  425. # Some people have reported that Net::DNS dies because AUTOLOAD picks up
  426. # calls to DESTROY.
  427. #
  428. sub DESTROY {}
  429.  
  430. =head2 print
  431.  
  432.     $rr->print;
  433.  
  434. Prints the record to the standard output.  Calls the
  435. B<string> method to get the RR's string representation.
  436.  
  437. =cut
  438. #' someone said that emacs gets screwy here.  Who am I to claim otherwise...
  439.  
  440. sub print {
  441.     my $self = shift;
  442.     print $self->string, "\n";
  443. }
  444.  
  445. =head2 string
  446.  
  447.     print $rr->string, "\n";
  448.  
  449. Returns a string representation of the RR.  Calls the
  450. B<rdatastr> method to get the RR-specific data.
  451.  
  452. =cut
  453.  
  454. sub string {
  455.     my $self = shift;
  456.  
  457.     return join("\t",
  458.         "$self->{'name'}.",
  459.           $self->{'ttl'},
  460.          $self->{'class'},
  461.          $self->{'type'},
  462.          (defined $self->rdatastr and length $self->rdatastr) ? $self->rdatastr : '; no data',
  463.    );
  464. }
  465.  
  466. =head2 rdatastr
  467.  
  468.     $s = $rr->rdatastr;
  469.  
  470. Returns a string containing RR-specific data.  Subclasses will need
  471. to implement this method.
  472.  
  473. =cut
  474.  
  475. sub rdatastr {
  476.     my $self = shift;
  477.     return exists $self->{'rdlength'}
  478.            ? "; rdlength = $self->{'rdlength'}"
  479.            : '';
  480. }
  481.  
  482. =head2 name
  483.  
  484.     $name = $rr->name;
  485.  
  486. Returns the record's domain name.
  487.  
  488. =head2 type
  489.  
  490.     $type = $rr->type;
  491.  
  492. Returns the record's type.
  493.  
  494. =head2 class
  495.  
  496.     $class = $rr->class;
  497.  
  498. Returns the record's class.
  499.  
  500. =cut
  501.  
  502. # Used to AUTOLOAD this, but apparently some versions of Perl (specifically
  503. # 5.003_07, included with some Linux distributions) would return the
  504. # class the object was blessed into, instead of the RR's class.
  505.  
  506. sub class {
  507.     my $self = shift;
  508.  
  509.     if (@_) {
  510.         $self->{'class'} = shift;
  511.     } elsif (!exists $self->{'class'}) {
  512.         Carp::carp('class: no such method');
  513.         return undef;
  514.     }
  515.     return $self->{'class'};
  516. }
  517.     
  518.  
  519. =head2 ttl
  520.  
  521.     $ttl = $rr->ttl;
  522.  
  523. Returns the record's time-to-live (TTL).
  524.  
  525. =head2 rdlength
  526.  
  527.     $rdlength = $rr->rdlength;
  528.  
  529. Returns the length of the record's data section.
  530.  
  531. =head2 rdata
  532.  
  533.     $rdata = $rr->rdata
  534.  
  535. Returns the record's data section as binary data.
  536.  
  537. =cut
  538. #'
  539. sub rdata {
  540.     my $self = shift;
  541.     my $retval = undef;
  542.  
  543.     if (@_ == 2) {
  544.         my ($packet, $offset) = @_;
  545.         $retval = $self->rr_rdata($packet, $offset);
  546.     }
  547.     elsif (exists $self->{'rdata'}) {
  548.         $retval = $self->{'rdata'};
  549.     }
  550.  
  551.     return $retval;
  552. }
  553.  
  554. sub rr_rdata {
  555.     my $self = shift;
  556.     return exists $self->{'rdata'} ? $self->{'rdata'} : '';
  557. }
  558.  
  559. #------------------------------------------------------------------------------
  560. # sub data
  561. #
  562. # This method is called by Net::DNS::Packet->data to get the binary
  563. # representation of an RR.
  564. #------------------------------------------------------------------------------
  565.  
  566. sub data {
  567.     my ($self, $packet, $offset) = @_;
  568.     my $data;
  569.  
  570.  
  571.     # Don't compress TSIG or TKEY names and don't mess with EDNS0 packets
  572.     if (uc($self->{'type'}) eq 'TSIG' || uc($self->{'type'}) eq 'TKEY') {
  573.         my $tmp_packet = Net::DNS::Packet->new('');
  574.         $data = $tmp_packet->dn_comp($self->{'name'}, 0);
  575.     } elsif (uc($self->{'type'}) eq 'OPT') {
  576.         my $tmp_packet = Net::DNS::Packet->new('');
  577.         $data = $tmp_packet->dn_comp('', 0);
  578.     } else {
  579.         $data  = $packet->dn_comp($self->{'name'}, $offset);
  580.     }
  581.  
  582.     my $qtype     = uc($self->{'type'});
  583.     my $qtype_val = ($qtype =~ m/^\d+$/) ? $qtype : Net::DNS::typesbyname($qtype);
  584.     $qtype_val    = 0 if !defined($qtype_val);
  585.  
  586.     my $qclass     = uc($self->{'class'});
  587.     my $qclass_val = ($qclass =~ m/^\d+$/) ? $qclass : Net::DNS::classesbyname($qclass);
  588.     $qclass_val    = 0 if !defined($qclass_val);
  589.     $data .= pack('n', $qtype_val);
  590.     
  591.     # If the type is OPT then class will need to contain a decimal number
  592.     # containing the UDP payload size. (RFC2671 section 4.3)
  593.     if (uc($self->{'type'}) ne 'OPT') {
  594.         $data .= pack('n', $qclass_val);
  595.     } else {
  596.         $data .= pack('n', $self->{'class'});
  597.     }
  598.     
  599.     $data .= pack('N', $self->{'ttl'});
  600.  
  601.     $offset += length($data) + &Net::DNS::INT16SZ;    # allow for rdlength
  602.  
  603.     my $rdata = $self->rdata($packet, $offset);
  604.  
  605.     $data .= pack('n', length $rdata);
  606.     $data .= $rdata;
  607.  
  608.     return $data;
  609. }
  610.  
  611.  
  612.  
  613.  
  614.  
  615. #------------------------------------------------------------------------------
  616. #  This method is called by SIG objects verify method. 
  617. #  It is almost the same as data but needed to get an representation of the
  618. #  packets in wire format withoud domain name compression.
  619. #  It is essential to DNSSEC RFC 2535 section 8
  620. #------------------------------------------------------------------------------
  621.  
  622. sub _canonicaldata {
  623.     my $self = shift;
  624.     my $data='';
  625.     {   
  626.         my @dname= split /\./,lc($self->{'name'});
  627.         for (my $i=0;$i<@dname;$i++){
  628.             $data .= pack ('C',length $dname[$i] );
  629.             $data .= $dname[$i] ;
  630.         }
  631.         $data .= pack ('C','0');
  632.     }
  633.     $data .= pack('n', Net::DNS::typesbyname(uc($self->{'type'})));
  634.     $data .= pack('n', Net::DNS::classesbyname(uc($self->{'class'})));
  635.     $data .= pack('N', $self->{'ttl'});
  636.     
  637.     
  638.     my $rdata = $self->_canonicalRdata;
  639.     
  640.     $data .= pack('n', length $rdata);
  641.     $data .= $rdata;
  642.     return $data;
  643.  
  644.  
  645. }
  646.  
  647. # These are methods that are used in the DNSSEC context...  Some RR
  648. # have domain names in them. Verification works only on RRs with
  649. # uncompressed domain names. (Canonical format as in sect 8 of
  650. # RFC2535) _canonicalRdata is overwritten in those RR objects that
  651. # have domain names in the RDATA and _name2label is used to convert a
  652. # domain name to "wire format"
  653.  
  654. sub _canonicalRdata {
  655.     my $self = shift;
  656.     my $rdata = $self->rr_rdata;
  657.     return $rdata;
  658. }
  659.  
  660.  
  661.  
  662. sub _name2wire   {   
  663.     my ($self,$name)=@_;
  664.  
  665.     my $rdata = '';
  666.     my @dname = split(m/\./, lc $name);
  667.     
  668.     for (@dname) {
  669.         $rdata .= pack('C', length $_);
  670.         $rdata .= $_ ;
  671.     }
  672.     
  673.     $rdata .= pack('C', '0');
  674.     
  675.     return $rdata;
  676. }
  677.  
  678. sub AUTOLOAD {
  679.     my ($self) = @_;  # If we do shift here, it will mess up the goto below.
  680.     
  681.     my ($name) = $AUTOLOAD =~ m/^.*::(.*)$/;
  682.     
  683.     # XXX -- We should test that we do in fact carp on unknown methods.    
  684.     unless (exists $self->{$name}) {
  685.         my $rr_string = $self->string;
  686.         Carp::carp(<<"AMEN");
  687.  
  688. ***
  689. ***  WARNING!!!  The program has attempted to call the method
  690. ***  "$name" for the following RR object:
  691. ***
  692. ***  $rr_string
  693. ***
  694. ***  This object doesn't have a method "$name".  THIS IS A BUG
  695. ***  IN THE CALLING SOFTWARE, which has incorrectly assumed that
  696. ***  the object would be of a particular type.  The calling
  697. ***  software should check the type of each RR object before
  698. ***  calling any of its methods.
  699. ***
  700. ***  Net::DNS has returned undef to the caller.
  701. ***
  702.  
  703. AMEN
  704.         return;
  705.     }
  706.     
  707.     no strict q/refs/;
  708.     
  709.     # Build a method in the class.
  710.     *{$AUTOLOAD} = sub {
  711.         my ($self, $new_val) = @_;
  712.                 
  713.         if (defined $new_val) {
  714.             $self->{$name} = $new_val;
  715.         }
  716.         
  717.         return $self->{$name};
  718.     };
  719.     
  720.     # And jump over to it.
  721.     goto &{$AUTOLOAD};
  722. }
  723.  
  724.  
  725. #
  726. #  Net::DNS::RR->_get_subclass($type)
  727. #
  728. # Return a subclass, after loading a subclass (if needed)
  729. #
  730. sub _get_subclass {
  731.     my ($class, $type) = @_;
  732.     
  733.     return unless $type and $RR{$type};
  734.     
  735.     my $subclass = join('::', $class, $type);
  736.     
  737.     unless ($_LOADED{$subclass}) {
  738.         eval "require $subclass";
  739.         die $@ if $@;
  740.         $_LOADED{$subclass}++;
  741.     }
  742.     
  743.     return $subclass;
  744. }    
  745.         
  746.     
  747. sub STORABLE_freeze {
  748.     my ($self, $cloning) = @_;
  749.  
  750.     return if $cloning;
  751.     
  752.     return ('', {%$self});
  753. }
  754.  
  755. sub STORABLE_thaw {
  756.     my ($self, $cloning, undef, $data) = @_;
  757.  
  758.     %{$self}  = %{$data};
  759.     
  760.     __PACKAGE__->_get_subclass($self->{'type'});
  761.     
  762.     return $self;
  763. }
  764.  
  765. =head1 BUGS
  766.  
  767. This version of C<Net::DNS::RR> does little sanity checking on user-created
  768. RR objects.
  769.  
  770. =head1 COPYRIGHT
  771.  
  772. Copyright (c) 1997-2002 Michael Fuhr. 
  773.  
  774. Portions Copyright (c) 2002-2003 Chris Reinhardt.
  775.  
  776. All rights reserved.  This program is free software; you may redistribute
  777. it and/or modify it under the same terms as Perl itself.
  778.  
  779. EDNS0 extensions by Olaf Kolkman.
  780.  
  781. =head1 SEE ALSO
  782.  
  783. L<perl(1)>, L<Net::DNS>, L<Net::DNS::Resolver>, L<Net::DNS::Packet>,
  784. L<Net::DNS::Update>, L<Net::DNS::Header>, L<Net::DNS::Question>,
  785. RFC 1035 Section 4.1.3
  786.  
  787. =cut
  788.  
  789. 1;
  790.