Net::DNS::Packet (3)
Leading comments
Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) Standard preamble: ========================================================================
NAME
Net::DNS::Packet - DNS protocol packetSYNOPSIS
use Net::DNS::Packet; $query = new Net::DNS::Packet( 'example.com', 'MX', 'IN' ); $reply = $resolver->send( $query );
DESCRIPTION
A Net::DNS::Packet object represents aMETHODS
new
$packet = new Net::DNS::Packet( 'example.com' ); $packet = new Net::DNS::Packet( 'example.com', 'MX', 'IN' ); $packet = new Net::DNS::Packet();
If passed a domain, type, and class, new() creates a Net::DNS::Packet object which is suitable for making a
If called with an empty argument list, new() creates an empty packet.
$packet = new Net::DNS::Packet( \$data ); $packet = new Net::DNS::Packet( \$data, 1 ); # debug
If passed a reference to a scalar containing
Returns undef if unable to create a packet object.
Decoding errors, including data corruption and truncation, are collected in the $@ ($EVAL_ERROR) variable.
( $packet, $length ) = new Net::DNS::Packet( \$data );
If called in array context, returns a packet object and the number of octets successfully decoded.
Note that the number of RRs in each section of the packet may differ from the corresponding header value if the data has been truncated or corrupted during transmission.
data
$data = $packet->data; $data = $packet->data( $size );
Returns the packet data in binary format, suitable for sending as a query or update request to a nameserver.
Truncation may be specified using a non-zero optional size argument.
header
$header = $packet->header;
Constructor method which returns a Net::DNS::Header object which represents the header section of the packet.
EDNS extended header
$edns = $packet->edns; $version = $edns->version; $size = $edns->size;
Auxiliary function edns() provides access to
reply
$reply = $query->reply( $UDPmax );
Constructor method which returns a new reply packet.
The optional UDPsize argument is the maximum
question, zone
@question = $packet->question;
Returns a list of Net::DNS::Question objects representing the question section of the packet.
In dynamic update packets, this section is known as zone() and specifies the
answer, pre, prerequisite
@answer = $packet->answer;
Returns a list of Net::DNS::RR objects representing the answer section of the packet.
In dynamic update packets, this section is known as pre() or prerequisite() and specifies the RRs or RRsets which must or must not preexist.
authority, update
@authority = $packet->authority;
Returns a list of Net::DNS::RR objects representing the authority section of the packet.
In dynamic update packets, this section is known as update() and specifies the RRs or RRsets to be added or deleted.
additional
@additional = $packet->additional;
Returns a list of Net::DNS::RR objects representing the additional section of the packet.
$packet->print;
Prints the packet data on the standard output in an
string
print $packet->string;
Returns a string representation of the packet.
answerfrom
print "packet received from ", $packet->answerfrom, "\n";
Returns the
answersize
print "packet size: ", $packet->answersize, " bytes\n";
Returns the size of the packet in bytes as it was received from a nameserver. User-created packets will return undef for this method (use length($packet->data) instead).
push
$ancount = $packet->push( prereq => $rr ); $nscount = $packet->push( update => $rr ); $arcount = $packet->push( additional => $rr ); $nscount = $packet->push( update => $rr1, $rr2, $rr3 ); $nscount = $packet->push( update => @rr );
Adds RRs to the specified section of the packet.
Returns the number of resource records in the specified section.
unique_push
$ancount = $packet->unique_push( prereq => $rr ); $nscount = $packet->unique_push( update => $rr ); $arcount = $packet->unique_push( additional => $rr ); $nscount = $packet->unique_push( update => $rr1, $rr2, $rr3 ); $nscount = $packet->unique_push( update => @rr );
Adds RRs to the specified section of the packet provided that the RRs are not already present in the same section.
Returns the number of resource records in the specified section.
pop
my $rr = $packet->pop( 'pre' ); my $rr = $packet->pop( 'update' ); my $rr = $packet->pop( 'additional' );
Removes a single
sign_tsig
$query = Net::DNS::Packet->new( 'www.example.com', 'A' ); $query->sign_tsig( 'Khmac-sha512.example.+165+01018.private', fudge => 60 ); $reply = $res->send( $query ); $reply->verify( $query ) || die $reply->verifyerr;
Attaches a
The
If you wish to create a
$tsig = Net::DNS::RR->new( name => 'tsig.example', type => 'TSIG', algorithm => 'custom-algorithm', key => '<base64 key text>', sig_function => sub { my ($key, $data) = @_; ... } ); $query->sign_tsig( $tsig );
The historical simplified syntax is still available, but additional options can not be specified.
$packet->sign_tsig( $key_name, $key );
The response to an inbound request is signed by presenting the request in place of the key parameter.
$response = $request->reply; $response->sign_tsig( $request, @options );
Multi-packet transactions are signed by chaining the sign_tsig() calls together as follows:
$opaque = $packet1->sign_tsig( 'Kexample.+165+13281.private' ); $opaque = $packet2->sign_tsig( $opaque ); $packet3->sign_tsig( $opaque );
The opaque intermediate object references returned during multi-packet signing are not intended to be accessed by the end-user application. Any such access is expressly forbidden.
Note that a
verify and verifyerr
$packet->verify() || die $packet->verifyerr; $reply->verify( $query ) || die $reply->verifyerr;
Verify
$opaque = $packet1->verify( $query ) || die $packet1->verifyerr; $opaque = $packet2->verify( $opaque ); $verifed = $packet3->verify( $opaque ) || die $packet3->verifyerr;
The opaque intermediate object references returned during multi-packet verify() will be undefined (Boolean false) if verification fails. Access to the object itself, if it exists, is expressly forbidden. Testing at every stage may be omitted, which results in a
sign_sig0
$update = new Net::DNS::Update('example.com'); $update->push( update => rr_add('foo.example.com A 10.1.2.3')); $update->sign_sig0('Kexample.com+003+25317.private');
Execution will be terminated if Net::DNS::RR::SIG is not available.
verify SIG0
$packet->verify( $keyrr ) || die $packet->verifyerr; $packet->verify( [$keyrr, ...] ) || die $packet->verifyerr;
Verify
truncate
The truncate method takes a maximum length as argument and then tries to truncate the packet and set theThe minimum maximum length that is honoured is 512 octets.
COPYRIGHT
Copyright (c)1997-2002 Michael Fuhr.Portions Copyright (c)2002-2004 Chris Reinhardt.
Portions Copyright (c)2002-2009 Olaf Kolkman
Portions Copyright (c)2007-2013 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.