Net::Libdnet::Intf - high level API to access libdnet intf_* functions


Net-Libdnet documentation Contained in the Net-Libdnet distribution.

Index


Code Index:

NAME

Top

Net::Libdnet::Intf - high level API to access libdnet intf_* functions

SYNOPSIS

Top

XXX

DESCRIPTION

Top

XXX

METHODS

Top

new
get
getSrc
getDst
set
loop
getSrcIntfFromDst
getSrcIpFromDst

AUTHOR

Top

Patrice <GomoR> Auffret

COPYRIGHT AND LICENSE

Top


Net-Libdnet documentation Contained in the Net-Libdnet distribution.

#
# $Id: Intf.pm 49 2011-03-13 22:42:45Z gomor $
#
package Net::Libdnet::Intf;
use strict; use warnings;

use base qw(Class::Gomor::Array);

our @AS = qw(
   _handle
);
__PACKAGE__->cgBuildIndices;
__PACKAGE__->cgBuildAccessorsScalar(\@AS);

use Net::Libdnet qw(:intf);
use Net::Libdnet::Entry::Intf;

sub new {
   my $self   = shift->SUPER::new(@_);
   my $handle = dnet_intf_open() or die("Intf::new: unable to open");
   $self->_handle($handle);
   return $self;
}

sub get {
   my $self   = shift,
   my ($intf) = @_;
   my $h = dnet_intf_get($self->_handle, { intf_name => $intf })
      or return;
   return Net::Libdnet::Entry::Intf->newFromHash($h);
}

sub getSrc {
   my $self  = shift,
   my ($src) = @_;
   my $h = dnet_intf_get_src($self->_handle, $src)
      or return;
   return Net::Libdnet::Entry::Intf->newFromHash($h);
}

sub getDst {
   my $self  = shift,
   my ($dst) = @_;
   my $h = dnet_intf_get_dst($self->_handle, $dst)
      or return;
   return Net::Libdnet::Entry::Intf->newFromHash($h);
}

sub getSrcIntfFromDst {
   my $self = shift;
   my ($dst) = @_;
   my $e = $self->getDst($dst) or return;
   return $e->name;
}

sub getSrcIpFromDst {
   my $self = shift;
   my ($dst) = @_;
   my $e = $self->getDst($dst) or return;
   return $e->addr;
}

sub set {
   my $self = shift;
   my ($entry) = @_;
   my $r = dnet_intf_set($self->_handle, $entry)
      or return;
   return $self;
}

sub loop {
   my $self         = shift;
   my ($sub, $data) = @_;
   dnet_intf_loop($self->_handle, $sub, $data || \'');
}

sub DESTROY {
   my $self = shift;
   defined($self->_handle) && dnet_intf_close($self->_handle);
}

1;

__END__