Net::DNS::RR(3)

πŸ’… Net::DNS::RR(3) β€” the DNS resource record base class, bestie

okay so this is the Net::DNS::RR(3) page from the User Contributed Perl Documentation, and it's literally the base class for every DNS Resource Record object ever, so like… main character energy fr fr. Let's get into it ✨


🌸 NAME 🌸

Net::DNS::RR β€” DNS resource record base class. that's it, that's the whole vibe πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

        use Net::DNS;

        $rr = Net::DNS::RR->new('example.com IN AAAA 2001:DB8::1');

        $rr = Net::DNS::RR->new(
                        owner   => 'example.com',
                        type    => 'AAAA',
                        address => '2001:DB8::1'
                        );

like, you can build one from a string OR from a hash. pick your fighter πŸ’…


πŸ’– DESCRIPTION πŸ’–

So Net::DNS::RR is the base class for DNS Resource Record (RR) objects. that's the whole job. also, go look at the manual pages for each specific RR type because that's where the actual per-type tea is β˜•


✨ METHODS ✨

WARNING!!! please please PLEASE do not assume the RR objects you get back from a query are of any particular type. you must always check the object type before you call any of its methods. if you call an unknown method you'll get an error message and execution will be terminated. not cute. not slay. just check the type first, okay? 🫢

πŸ’œ new (from string)

        $aaaa   = Net::DNS::RR->new('host.example.com. 86400 AAAA 2001:DB8::1');
        $mx     = Net::DNS::RR->new('example.com. 7200 MX 10 mailhost.example.com.');
        $cname  = Net::DNS::RR->new('www.example.com 300 IN CNAME host.example.com');
        $txt    = Net::DNS::RR->new('txt.example.com 3600 HS TXT "text data"');

Returns an object of the appropriate RR type, or a Net::DNS::RR object if the type isn't implemented. The attribute values get extracted from whatever string you passed in. The syntax of the argument string follows the RFC1035 spec for zone files, and it's compatible with the result that the string method returns πŸ‘‘

The owner and RR type are required; all the other stuff is optional. omitting the optional fields is genuinely useful for creating the empty RDATA sections you need for certain dynamic update operations. see the Net::DNS::Update manual page for more examples πŸŽ€

Also! all names are interpreted as fully qualified domain names. the trailing dot (.) is optional β€” lowkey a serve 🌈

🧚 new (from hash)

        $rr = Net::DNS::RR->new(%hash);

        $rr = Net::DNS::RR->new(
                        owner   => 'host.example.com',
                        ttl     => 86400,
                        class   => 'IN',
                        type    => 'AAAA',
                        address => '2001:DB8::1'
                        );

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

Returns an object of the appropriate RR type, or a Net::DNS::RR object if the type isn't implemented. consult the relevant manual pages for how to use the type-specific attributes πŸ”

owner and RR type are required; everything else is optional. and again, omitting the optional attributes is useful for creating the empty RDATA sections that certain dynamic update operations need ✨

πŸ“ decode

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

Decodes a DNS resource record at the specified location inside a DNS packet πŸ•΅οΈβ€β™€οΈ

The argument list is: a reference to the buffer containing the packet data, plus an offset indicating where the resource record begins. Any remaining arguments get passed as opaque data to subordinate decoders and do not form part of the published interface. iykyk 🌸

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. like, if the data's a mess it WILL yell at you 😭

πŸ”₯ 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 get 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 form of embedded domain names is to be used. no array? uncompressed canonical form. that's the message πŸ’…

πŸŽ€ print

        $rr->print;

Prints the resource record to the currently selected output filehandle. it calls the string method to get the formatted RR representation πŸ–¨οΈ

πŸ‘‘ string

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

Returns a string representation of the RR using the master file format mandated by RFC1035. all domain names are fully qualified with a trailing dot. ⚠️ this differs from the RR attribute methods, which omit the trailing dot β€” so don't get it twisted, bestie πŸ’…

πŸ’€ plain

        $plain = $rr->plain;

Returns a simplified single-line representation of the RR. this makes it easier to interact with programs like nsupdate that have rudimentary parsers 🫢

πŸ¦‹ token

        @token = $rr->token;

Returns a token list representation of the RR zone file string 🧚

🌈 generic

        $generic = $rr->generic;

Returns the generic RR representation defined in RFC3597. this makes it easier to create zone files containing RRs that outdated nameservers and provisioning software don't recognise πŸ’…

🌸 owner name

        $name = $rr->owner;

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 = Net::DNS::RR->new( type => NULL, rdata => 'arbitrary' );

Resource record data section, viewed as opaque octets.

🧚 rdstring

        $rdstring = $rr->rdstring;

Returns a string representation of the RR-specific data.

⭐ rdlength

        $rdlength = $rr->rdlength;

Returns the uncompressed length of the encoded RR-specific data πŸ“


πŸ”₯ Sorting of RR arrays πŸ”₯

So sorting of RR arrays is done by Net::DNS::rrsort() β€” go read the docs for Net::DNS. This package provides class methods to set the comparator function used for a particular RR, based on its attributes πŸ‘‘

πŸ’… set_rrsort_func

        my $function = sub {    ## numerically ascending order
                $Net::DNS::a->{'preference'} <=> $Net::DNS::b->{'preference'};
                };

        Net::DNS::RR::MX->set_rrsort_func( 'preference', $function );

        Net::DNS::RR::MX->set_rrsort_func( 'default_sort', $function );

set_rrsort_func() must be called as a class method. The first argument is the attribute name that the sorting happens on. If you specify "default_sort", then that's the sort algorithm used when get_rrsort_func() is called without an RR attribute as its argument 🎯

The second argument is a reference to a comparator function that uses the global variables $a and $b in the Net::DNS package. During sorting, $a and $b will contain references to objects of the class whose set_rrsort_func() was called. so the sorting function above only gets applied to Net::DNS::RR::MX objects πŸ‘‘

Also fun fact: the example above is literally the sorting function implemented in MX 🌟

🫢 get_rrsort_func

        $function = Net::DNS::RR::MX->get_rrsort_func('preference');
        $function = Net::DNS::RR::MX->get_rrsort_func();

get_rrsort_func() returns a reference to the comparator function πŸ’–


  • Copyright (c)1997-2001 Michael Fuhr.
  • Portions Copyright (c)2002,2003 Chris Reinhardt.
  • Portions Copyright (c)2005-2007 Olaf Kolkman.
  • Portions Copyright (c)2007,2012 Dick Franks.

All rights reserved. 🫢


πŸ’€ LICENSE πŸ’€

Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the original copyright notices appear in all copies and that both copyright notice and this permission notice appear in supporting documentation, and that the name of the author not be used in advertising or publicity pertaining to distribution of the software without specific prior written permission. πŸ“œ

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. πŸ’…


πŸ¦‹ SEE ALSO πŸ¦‹


okay that's the whole page, you ate that πŸ’…βœ¨ this was Net::DNS::RR(3) brought to you by perl v5.42.0, dated 2026-09-02 β€” mwah, go forth and resolve some records bestie πŸŽ€πŸ¦‹πŸ’–

πŸ“¦ where this page comes from