Net::RNDC::Packet - RNDC Protocol V1 Packet Parsing and Generation
version 0.003
To send an RNDC command and get a response:
use IO::Socket::INET;
use Net::RNDC::Packet;
my $buff;
my $key = 'aabc';
my $c = IO::Socket::INET->new(
PeerAddr => '127.0.0.1:953',
) or die "Failed to create a socket: $@ ($!)";
# Send opener packet
my $pkt = Net::RNDC::Packet->new(
key => $key,
);
$c->send($pkt->data);
# Read nonce response
$c->recv($buff, 4096);
$pkt->parse($buff);
# Send command request with nonce
my $nonce = $pkt->{data}->{_ctrl}{_nonce};
my $cmd = Net::RNDC::Packet->new(
key => $key,
nonce => $nonce,
data => {type => 'status'},
);
$c->send($cmd->data);
# Read final response
$c->recv($buff, 4096);
$cmd->parse($buff);
my $resp = $cmd->{data}{_data}{text} || 'command success';
print "$resp\n";
This package provides low-level RNDC V1 protocol parsing and generation. It
allows full control over the data in the sent/received packets.
Currently this is provided by hacking at "$pkt->{data}",
setter/getter methods will be forthcoming.
new
my $packet = Net::RNDC::Packet->new(%args);
Arguments:
- •
- key - The Base64 encoded HMAC-MD5 key to sign/verify packets
with.
- •
- data - A hashref of data to put in the request of the packet.
Currently, BIND only understand commands in the "type" key. For
example:
data => { type => 'status' },
- •
- nonce - The nonce data returned from the remote nameserver. Located
in the parsed packet in the _ctrl section:
nonce => $packet->{data}->{_ctrl}{_nonce},
data
my $binary = $packet->data;
Generates a binary representation of the packet, suitable for sending over the
wire.
parse
if ($packet->parse($binary)) { ... }
Parses data from the wire and populates the current packet with the information,
as well as verifies the data with the provided
key that was passed to
the constructor. Returns 1 on success, 0 on failure. Check "error"
if there's a failure.
error
my $err = $packet->error;
Returns a string error, if any, after packet parsing or generation failed.
- •
- Methods for modifying the different data parts of an RNDC message
Net::RNDC - Simple RNDC communication.
Net::RNDC::Session - Manage the 4-packet RNDC session
Matthew Horsfall (alh) <WolfSage@gmail.com>
You may distribute this code under the same terms as Perl itself.