Matthew Horsfall (alh) > Net-RNDC-0.003 > Net::RNDC::Packet

Download:
Net-RNDC-0.003.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 0.003   Source  

NAME ^

Net::RNDC::Packet - RNDC Protocol V1 Packet Parsing and Generation

VERSION ^

version 0.003

SYNOPSIS ^

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";

DESCRIPTION ^

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.

Constructor

new

  my $packet = Net::RNDC::Packet->new(%args);

Arguments:

Methods

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.

TODO ^

SEE ALSO ^

Net::RNDC - Simple RNDC communication.

Net::RNDC::Session - Manage the 4-packet RNDC session

AUTHOR ^

Matthew Horsfall (alh) <WolfSage@gmail.com>

LICENSE ^

You may distribute this code under the same terms as Perl itself.

syntax highlighting: