Net::DNS::RR(3)

NAME
Net::DNS::RR - DNS Resource Record base class

SYNOPSIS
    use Net::DNS;

    $rr = new Net::DNS::RR('example.com IN A 192.0.2.99');

    $rr = new Net::DNS::RR(
            name    => 'example.com',
            type    => 'A',
            address => '192.0.2.99'
            );

DESCRIPTION
Net::DNS::RR is the base class for DNS Resource Record (RR) objects. See also the manual pages for each specific RR type.

METHODS
WARNING!!! Do not assume the RR objects you receive from a query are of a particular type -- always check the object type before calling any of its methods. If you call an unknown method, you will get an error message and execution will be terminated.

  new (from string)
    $a     = new Net::DNS::RR('host.example.com. 86400 A 192.0.2.1');
    $mx    = new Net::DNS::RR('example.com. 7200 MX 10 mailhost.example.com.');
    $cname = new Net::DNS::RR('www.example.com 300 IN CNAME host.example.com');
    $txt   = new Net::DNS::RR('txt.example.com 3600 HS TXT "text data"');

Returns an RR object of the appropriate type, or a "Net::DNS::RR"
object if the type is not implemented.    The attribute values are
extracted from the string passed by the user. The syntax of the argument string follows the RFC1035 specification for zone files, and is compatible with the result returned by the string method.

The name and RR type are required; all other information is optional. If omitted, the TTL defaults to 0 and the RR class defaults to IN. Omitting the optional fields is useful for creating the empty RDATA sections required for certain dynamic update operations. See the "Net::DNS::Update" manual page for additional examples.

All names are interpreted as fully qualified domain names. The trailing dot (.) is optional.

RR owner names in in-addr.arpa or ip6.arpa namespaces may be specified using appropriate RFC4291 or RFC4632 IP address/prefix notation.

  new (from hash)
    $rr = new Net::DNS::RR(
            name    => 'host.example.com',
            ttl     => 86400,
            class   => 'IN',
            type    => 'A',
            address => '192.0.2.1'
            );

    $rr = new Net::DNS::RR(
            name    => 'txt.example.com',
            type    => 'TXT',
            txtdata => [ 'one', 'two' ]
            );

Returns an RR object of the appropriate type, or a "Net::DNS::RR"
object if the type is not implemented.    See the manual pages for
each RR type to see what fields the type requires.

The "name" and "type" fields are required; all others are optional. If omitted, "ttl" defaults to 0 and "class" defaults to IN. Omitting the optional fields is useful for creating the empty RDATA sections required for certain dynamic update operations.

  decode
    ( $rr, $next ) = decode Net::DNS::RR( \$data, $offset, @opaque );

Decodes a DNS resource record at the specified location within a DNS packet.

The argument list consists of a reference to the buffer containing the packet data and offset indicating where resource record begins. Remaining arguments, if any, are passed as opaque data to subordinate decoders.

Returns a "Net::DNS::RR" object and the offset of the next record in the packet.

An exception is raised if the data buffer contains insufficient or corrupt data.

Any remaining arguments are passed as opaque data to subordinate decoders and do not form part of the published interface.

  encode
    $data = $rr->encode( $offset, @opaque );

Returns the "Net::DNS::RR" in binary format suitable for inclusion in a DNS packet buffer.

The offset indicates the intended location within the packet data where the "Net::DNS::RR" is to be stored.

Any remaining arguments are opaque data which are passed intact to subordinate encoders.

  canonical
    $data = $rr->canonical;

Returns the "Net::DNS::RR" in canonical binary format suitable for DNSSEC signature validation.

The absence of the associative array argument signals to subordinate encoders that the canonical uncompressed lower case form of embedded domain names is to be used.

  name
    $name = $rr->name;

Returns the owner name of the record.

  type
    $type = $rr->type;

Returns the record type.

  class
    $class = $rr->class;

Resource record class.

  ttl
    $ttl = $rr->ttl;
    $ttl = $rr->ttl(3600);

Resource record time to live in seconds.

  rdata
    $rr = new Net::DNS::RR( type => NULL, rdata => 'arbitrary' );

Resource record data section when viewed as opaque octets.

  print
    $rr->print;

Prints the record to the standard output. Calls the string method to get the RR string representation.

  string
    print $rr->string, "\n";

Returns a string representation of the RR using the zone file format described in RFC1035. All domain names are fully qualified with trailing dot. This differs from RR attribute methods, which omit the trailing dot.

  rdstring
    $rdstring = $rr->rdstring;

Returns a string representation of the RR-specific data.

Sorting of RR arrays
Sorting of RR arrays is done by Net::DNS::rrsort(), see documentation for Net::DNS. This package provides class methods to set the sorting functions used for a particular RR based on its attributes.

  set_rrsort_func
    Net::DNS::RR::SRV->set_rrsort_func('priority',
                               sub {
                                   my ($a,$b)=($Net::DNS::a,$Net::DNS::b);
                                   $a->priority <=> $b->priority
                                   ||
                                   $b->weight <=> $a->weight
                     }

    Net::DNS::RR::SRV->set_rrsort_func('default_sort',
                               sub {
                                   my ($a,$b)=($Net::DNS::a,$Net::DNS::b);
                                   $a->priority <=> $b->priority
                                   ||
                                   $b->weight <=> $a->weight
                     }

set_rrsort_func needs to be called as a class method. The first argument is the attribute name on which the sorting will need to take place. If you specify "default_sort" then that is the sort algorithm that will be used in the case that rrsort() is called without an RR attribute as argument.

The second argument is a reference to a comparison function that uses the global variables $a and $b in the "from Net::DNS"(!!)package. During sorting, the variables $a and $b will contain references to objects of the class from which you called the set_prop_sort. In other words, you can rest assured that the above sorting function will only be applied to Net::DNS::RR::SRV objects.

The above example is the sorting function implemented in SRV.

COPYRIGHT
Copyright (c)1997-2002 Michael Fuhr.

Portions Copyright (c)2002-2004 Chris Reinhardt.

Portions Copyright (c)2005-2007 Olaf Kolkman.

Portions Copyright (c)2007,2012 Dick Franks.

All rights reserved.

This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO
perl, Net::DNS, Net::DNS::Question, Net::DNS::Packet, Net::DNS::Update, RFC1035 Section 4.1.3, RFC1123, RFC3597