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 / OPT.pm < prev    next >
Encoding:
Perl POD Document  |  2004-01-09  |  6.0 KB  |  231 lines

  1. package Net::DNS::RR::OPT;
  2. #
  3. # $Id: OPT.pm,v 2.101 2004/01/04 04:31:10 ctriv Exp $
  4. #
  5.  
  6. use strict;
  7. use vars qw(@ISA $VERSION %extendedrcodesbyname %extendedrcodesbyval $EDNSVERSION);
  8.  
  9. use Socket;
  10. use Net::DNS;
  11. use Carp;
  12.  
  13. @ISA     = qw(Net::DNS::RR);
  14. $VERSION = (qw$Revision: 2.101 $)[1];
  15.  
  16. $EDNSVERSION = 0;
  17.  
  18. %extendedrcodesbyname = (
  19.     "ONLY_RDATA" => 0,        # No name specified see 4.6 of 2671 
  20.     "UNDEF1"     => 1,
  21.     "UNDEF2"     => 2,
  22.     "UNDEF3"     => 3,
  23.     "UNDEF4"     => 4,
  24.     "UNDEF5"     => 5,
  25.     "UNDEF6"     => 6,
  26.     "UNDEF7"     => 7,
  27.     "UNDEF8"     => 8,
  28.     "UNDEF9"     => 9,
  29.     "UNDEF10"    => 10,
  30.     "UNDEF11"    => 11,
  31.     "UNDEF12"    => 12,
  32.     "UNDEF13"    => 13,
  33.     "UNDEF14"    => 14,
  34.     "UNDEF15"    => 15,
  35.     "BADVERS"    => 16,        # RFC 2671
  36. );
  37. %extendedrcodesbyval = reverse %extendedrcodesbyname;
  38.  
  39.  
  40.  
  41. sub new {
  42.     my ($class, $self, $data, $offset) = @_;
  43.  
  44.     $self->{"name"} = "" ;   # should allway be "root"
  45.  
  46.     if ($self->{"rdlength"} > 0) {
  47.         $self->{"optioncode"}   = unpack("n", substr($$data, $offset, 2));
  48.         $self->{"optionlength"} = unpack("n", substr($$data, $offset+2, 2));
  49.         $self->{"optiondata"}   = unpack("n", substr($$data, $offset+4, $self->{"optionlength"}));
  50.     }
  51.  
  52.     $self->{"_rcode_flags"}  = pack("N",$self->{"ttl"});
  53.     
  54.     $self->{"extendedrcode"} = unpack("C", substr($self->{"_rcode_flags"}, 0, 1));
  55.     $self->{"ednsversion"}   = unpack("C", substr($self->{"_rcode_flags"}, 1, 1));
  56.     $self->{"ednsflags"}     = unpack("n", substr($self->{"_rcode_flags"}, 2, 2));
  57.     
  58.     
  59.     return bless $self, $class;
  60. }
  61.  
  62.  
  63.  
  64.  
  65.  
  66. sub new_from_string {
  67.     my ($class, $self ) = @_;
  68.     
  69.     # There is no such thing as an OPT RR in a ZONE file. 
  70.     # Not implemented!
  71.     croak "You should not try to create a OPT RR from a string\nNot implemented";
  72.     return bless $self, $class;
  73. }
  74.  
  75.  
  76.  
  77. sub new_from_hash {
  78.     my ($class, $self ) = @_;
  79.     
  80.     $self->{"name"} = "" ;   # should allway be "root"
  81.     # Setting the MTU smaller then 512 does not make sense 
  82.     # should we test for a maximum here?
  83.     if ($self->{"class"} eq "IN" || $self->{"class"} < 512) {
  84.         $self->{"class"} = 512;    # Default value...
  85.     }
  86.     
  87.     $self->{"extendedrcode"} = 0 unless exists $self->{"extendedrcode"};
  88.     
  89.     $self->{"ednsflags"}   = 0 unless exists $self->{"ednsflags"};
  90.     $self->{"ednsversion"} =  $Net::DNS::RR::OPT::EDNSVERSION unless exists $self->{"ednsversion"};
  91.     $self->{"ttl"}= unpack ("N", 
  92.         pack("C", $self->{"extendedrcode"}) .
  93.         pack("C", $self->{"ednsversion"})  .
  94.         pack("n", $self->{"ednsflags"})
  95.     );
  96.     
  97.     if (exists  $self->{"optioncode"}) {
  98.         $self->{"optiondata"}   = "" if ! exists  $self->{"optiondata"};
  99.         $self->{"optionlength"} = length $self->{"optiondata"}
  100.     }
  101.     
  102.     return bless $self, $class;
  103.  
  104. }
  105.  
  106.  
  107.  
  108.  
  109. sub string {
  110.    my $self = shift;
  111.    return
  112.     "; EDNS Version "     . $self->{"ednsversion"} . 
  113.     "\t UDP Packetsize: " .  $self->{"class"} . 
  114.     "\n; EDNS-RCODE:\t"   . $self->{"extendedrcode"} .
  115.     " (" . $extendedrcodesbyval{ $self->{"extendedrcode"} }. ")" .
  116.     "\n; EDNS-FLAGS:\t"   . sprintf("0x%04x", $self->{"ednsflags"}) .
  117.     "\n";
  118. }
  119.  
  120.  
  121. sub rdatastr {
  122.     return '; Parsing of OPT rdata is not yet implemented';
  123. }
  124.  
  125.  
  126. sub rr_rdata {
  127.     my $self = shift;
  128.     my $rdata;
  129.     
  130.     if (exists $self->{"optioncode"}) {
  131.         $rdata  = pack("n", $self->{"optioncode"});
  132.         $rdata .= pack("n", $self->{"optionlength"}); 
  133.         $rdata .= $self->{"optiondata"}
  134.     } else {
  135.         $rdata = "";
  136.     }
  137.     
  138.     return $rdata;
  139. }
  140.  
  141.  
  142. 1;
  143. __END__
  144.  
  145. =head1 NAME
  146.  
  147. Net::DNS::RR::OPT - DNS OPT
  148.  
  149. =head1 SYNOPSIS
  150.  
  151. C<use Net::DNS::RR>;
  152.  
  153. =head1 DESCRIPTION
  154.  
  155. Class for EDNS pseudo resource record OPT.
  156.  
  157. =head1 METHODS
  158.  
  159. This object should only be used inside the Net::DNS classes itself.
  160.  
  161. =head2 new
  162.  
  163. Since "OPT" is a pseudo record and should not be stored in
  164. masterfiles; Therefore we have not implemented a method to create this
  165. RR from string.
  166.  
  167. One may create the object from a hash. See RFC 2671 for details for
  168. the meaning of the hash keys.
  169.  
  170.  $rr= new Net::DNS::RR {
  171.     name => "",     # Ignored and set to ""
  172.     type => "OPT",
  173.     class => 1024,    # sets UDP payload size
  174.     extendedrcode =>  0x00,    # sets the extended RCODE 1 octets
  175.     ednsflags     =>  0x0000,  # sets the ednsflags (2octets)
  176.     optioncode   =>   0x0      # 2 octets
  177.     optiondata   =>   0x0      # optionlength octets
  178.  }
  179.  
  180. The ednsversion is set to 0 for now. The ttl value is determined from
  181. the extendedrcode, the ednsversion and the ednsflag.
  182. The rdata is constructed from the optioncode and optiondata
  183. see section 4.4 of RFC 2671
  184.  
  185. If optioncode is left undefined then we do not expect any RDATA.
  186.  
  187. The defaults are no rdata.
  188.  
  189.  
  190. =head1 TODO
  191.  
  192. - This class is tailored to use with dnssec.
  193.  
  194. - Do some range checking on the input.
  195.  
  196. - This class probably needs subclasses once OPTION codes start to be defined.
  197.  
  198. - look at use of extended labels
  199.  
  200. =head1 COPYRIGHT
  201.  
  202. Copyright (c) 2001, 2002  RIPE NCC.  Author Olaf M. Kolkman
  203.  
  204. All Rights Reserved
  205.  
  206. Permission to use, copy, modify, and distribute this software and its
  207. documentation for any purpose and without fee is hereby granted,
  208. provided that the above copyright notice appear in all copies and that
  209. both that copyright notice and this permission notice appear in
  210. supporting documentation, and that the name of the author not be
  211. used in advertising or publicity pertaining to distribution of the
  212. software without specific, written prior permission.
  213.  
  214.  
  215. THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  216. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
  217. AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
  218. DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
  219. AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  220. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  221.  
  222. Based on, and contains, code by Copyright (c) 1997-2002 Michael Fuhr.
  223.  
  224. =head1 SEE ALSO
  225.  
  226. L<perl(1)>, L<Net::DNS>, L<Net::DNS::Resolver>, L<Net::DNS::Packet>,
  227. L<Net::DNS::Header>, L<Net::DNS::Question>, L<Net::DNS::RR>,
  228. RFC 2435 Section 3
  229.  
  230. =cut
  231.