Michael Robinton > Net-DNS-ToolKit > Net::DNS::ToolKit::RR::Template

Download:
Net-DNS-ToolKit-0.48.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 0.02   Source  

NAME ^

Net::DNS::ToolKit::RR::Template - template for resource records

SYNOPSIS ^

This file is a template from which to create new resource record manipulation methods. While these modules may be loaded directly for testing, they are intended to be loaded by the class loader Net::DNS::ToolKit::RR. The SYNOPSIS section of specific RR documentation should begin with the caveat:

edit this text to conform to your RR method

  DO NOT use Net::DNS::ToolKit::RR::XYZ
  DO NOT require Net::DNS::ToolKit::RR::XYZ

  Net::DNS::ToolKit::RR::XYZ is autoloaded by 
  class Net::DNS::ToolKit::RR and its methods
  are instantiated in a 'special' manner.

  use Net::DNS::ToolKit::RR;
  ($get,$put,$parse) = new Net::DNS::ToolKit::RR;

  ($newoff,$name,$type,$class,$ttl,$rdlength,
        $rdata,...) = $get->XYZ(\$buffer,$offset);

  Note: the $get->XYZ method is normally called
  via:  @stuff = $get->next(\$buffer,$offset);

  ($newoff,@dnptrs)=$put->XYZ(\$buffer,$offset,\@dnptrs,
        $name,$type,$class,$ttl,$rdata,...);

  $NAME,$TYPE,$CLASS,$TTL,$rdlength,$RDATA) 
    = $parse->XYZ($name,$type,$class,$ttl,$rdlength,
        $rdata,...);

DESCRIPTION ^

Net::DNS::ToolKit::RR:XYZ appends an XYZ resource record to a DNS packet under construction, recovers an XYZ resource record from a packet being decoded, and converts the numeric/binary portions of the resource record to human readable form.

Description from RFC1035.txt or other specification document.

edit this text to conform to your RR method

See: Net::DNS::ToolKit::RR::A and Net::DNS::ToolKit::RR::SOA for examples.

Each RR module contains three methods which provide the RR specific content manipulation. The data common to all resource modules is handled from within the class loader prior to handing the request over the the specific resource record method. Because of this, the DESCRIPTION of the method action is somewhat misleading. As an example, lets dissect the 'parse' method:

  $NAME,$TYPE,$CLASS,$TTL,$rdlength,$RDATA,...) 
    = $parse->XYZ($name,$type,$class,$ttl,$rdlength,
        $rdata,...);

The common elements for all resource records are:

  $name,$type,$class,$ttl,$rdlength

These are handled by the class loader and the local method actually only receives a request to provide the '$rdata' portion. While the description of the method as called from the user program is as above, the implementation looks like this for and 'A' resource record. The $rdata is handled as follows:

  $IPaddr = $classloader->A($netaddr);

  sub parse {
    shift;      # $self
    inet_ntoa($netaddr);
  }

As you can see, all that is passed to the 'parse' method is the $rdata portion of the request. 'parse' returns the ascii 'dotquad' IP address.

The actual DESCRIPTION from Net::DNS::ToolKit::RR::A follows with annotation about the CODE and what is passed to all resource methods from the class loader.

The rest of this Template example is taken DIRECTLY from Net::DNS::ToolKit::RR::A, with comments added for clarity and to show the CODE.

CODE for THIS MODULE ^

The code in this module (for an 'A' resource record) without the comments is pretty compact and looks like this:

  package Net::DNS::ToolKit::RR::A;

  use strict;
  use Carp;
  # The functions needed for 'A' records
  # are 'put16', 'getIPv4', putIPv4, inet_aton,
  # and inet_ntoa.  Other RR types will need 
  # different and/or additional functions. 

  use Net::DNS::ToolKit qw(
        put16
        getIPv4
        putIPv4
        inet_aton
        inet_ntoa
  );
  use Net::DNS::Codes qw(:constants);
  use vars qw($VERSION);
  require Socket;

  $VERSION = do { my @r = (q$Revision: 0.01 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };

  =head1 NAME
  B<Net::DNS::ToolKit::RR::A>

  =head1 SYNOPSIS
        (removed for brevity)

  =head1 DESCRIPTION
        (removed for brevity)

  =over 4

  =item * @stuff = $get->A(\$buffer,$offset);
        (removed for brevity)

  =cut

  sub get {
    my($self,$bp,$offset) = @_;
    $offset += INT16SZ; # don't need rdlength
    my($netaddr,$newoff) = getIPv4($bp,$offset);
    return ($newoff,$netaddr);
  }

  =item * ($newoff,@dnptrs)=$put->A(\$buffer,$offset,\@dnptrs,
        @common, $rdlength,$netaddr);  
        (removed for brevity)

  sub put {
    return () unless @_;        # always return on error
    my($self,$bp,$off,$dnp,$netaddr) = @_;
    return () unless  
        ($off = put16($bp,$off,NS_INADDRSZ));
    return(putIPv4($bp,$off,$netaddr), @$dnp);
  }

  =cut


  =item * (@COMMON,$IPaddr)=$parse->A(@common,$netaddr);
        (removed for brevity)

  =cut

  sub parse {
    shift;      # $self
    inet_ntoa(shift);
  }

TEST ROUTINES ^

See: t/Template.t in this distribution.

See: t/NS.t in the Net::DNS::Toolkit distribution for an example of a test routine that is more complex as well as embedded debugging routines which are commented out.

And.... what follows...

DEPENDENCIES ^

        Net::DNS::ToolKit
        Net::DNS::Codes
        any others you require
        for your new RR extension

EXPORT ^

        none

AUTHOR ^

Your Name <your@emailaddy.com>

COPYRIGHT ^

Portions copyright 2003, Michael Robinton <michael@bizsystems.com>

Copyright 20xx, Your Name <your@emailaddy.com>

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

See also: ^

Net::DNS::Codes(3), Net::DNS::ToolKit(3), Net::DNS::ToolKit::RR::A(3)

syntax highlighting: