Net-Libdnet-0.99/0000755000175000017500000000000013350211720012602 5ustar gomorgomorNet-Libdnet-0.99/typemap0000644000175000017500000000057413350210754014220 0ustar gomorgomorTYPEMAP Blob * T_PTRREF EthAddr * T_PTRREF EthHandle * T_PTRREF IntfHandle * T_PTRREF ArpHandle * T_PTRREF FwHandle * T_PTRREF RouteHandle * T_PTRREF TunHandle * T_PTRREF IpHandle * T_PTRREF IntfEntry * T_PTRREF ArpEntry * T_PTRREF FwRule * T_PTRREF RouteEntry * T_PTRREF # # This one is for compatibility with perl 5.6.x # const char * T_PV Net-Libdnet-0.99/ubuntu-new.patch0000644000175000017500000000156313350210754015747 0ustar gomorgomorIndex: Libdnet.xs =================================================================== --- Libdnet.xs (revision 41) +++ Libdnet.xs (working copy) @@ -34,7 +34,7 @@ #include "XSUB.h" #include -#include +#include #ifdef DNET_BLOB_H typedef blob_t Blob; Index: Makefile.PL =================================================================== --- Makefile.PL (revision 41) +++ Makefile.PL (working copy) @@ -3,10 +3,10 @@ # use ExtUtils::MakeMaker; -my $libs = qx{dnet-config --libs 2>/dev/null} - || ['-L/lib -L/usr/lib -L/usr/local/lib -ldnet']; +my $libs = qx{dumbnet-config --libs 2>/dev/null} + || ['-L/lib -L/usr/lib -L/usr/local/lib -ldumbnet']; -my $inc = qx{dnet-config --cflags 2>/dev/null} +my $inc = qx{dumbnet-config --cflags 2>/dev/null} || '-I/include -I/usr/include -I/usr/local/include'; WriteMakefile( Net-Libdnet-0.99/META.yml0000644000175000017500000000110013350211717014051 0ustar gomorgomor--- abstract: "binding for Dug Song's libdnet" author: - 'GomoR ' build_requires: ExtUtils::MakeMaker: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010' license: bsd meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Net-Libdnet no_index: directory: - t - inc requires: Class::Gomor: '0' perl: '5.006001' version: '0.99' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Net-Libdnet-0.99/MANIFEST0000644000175000017500000000211313350211720013730 0ustar gomorgomorChanges LICENSE Libdnet.xs MANIFEST Makefile.PL README bin/dnet.pl c/arp_entry.c c/fw_rule.c c/intf_entry.c c/route_entry.c examples/arp-add.pl examples/arp-delete.pl examples/arp-get.pl examples/arp-list.pl examples/eth-send.pl examples/fw-add.pl examples/fw-delete.pl examples/fw-list.pl examples/intf-get-dst.pl examples/intf-get-src.pl examples/intf-get.pl examples/intf-list.pl examples/ip-send.pl examples/route-get.pl examples/route-list.pl examples/tun-open.pl lib/Net/Libdnet.pm lib/Net/Libdnet/Arp.pm lib/Net/Libdnet/Entry/Intf.pm lib/Net/Libdnet/Eth.pm lib/Net/Libdnet/Fw.pm lib/Net/Libdnet/Intf.pm lib/Net/Libdnet/Ip.pm lib/Net/Libdnet/Route.pm lib/Net/Libdnet/Tun.pm standard-new.patch standard-old.patch t/01-module.t t/02-addr.t t/03-arp.t t/04-blob.t t/05-eth.t t/06-fw.t t/07-intf.t t/08-ip.t t/09-rand.t t/10-route.t t/11-entry-intf.t t/20-pod-coverage.t t/21-test-pod.t typemap ubuntu-new.patch ubuntu-old.patch META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Net-Libdnet-0.99/t/0000755000175000017500000000000013350211717013053 5ustar gomorgomorNet-Libdnet-0.99/t/03-arp.t0000644000175000017500000000207113350210754014242 0ustar gomorgomor#!/usr/bin/perl # # $Id$ # use Test; BEGIN{ plan tests => 12 }; use Net::Libdnet; # the tests may destroy your network configuration. # just fake them for those people who did not explicitely require them. if( !$ENV{REAL_TESTS} ){ print STDERR "$0: faking dangerous tests\n"; for( $i=0 ; $i<12 ; $i++ ){ ok(1); }; exit 0; } # gateway to a.root-server.net # configure dummy network $gw = route_get("198.41.0.4"); $if = intf_get_dst($gw); system("ifconfig $if->{name} add 172.16.255.1 netmask 255.255.255.0") && die "system"; ok(arp_get("172.16.255.2"), undef); ok(arp_add(undef, "de:ad:be:af:00:00"), undef); ok(arp_add("172.16.255.2", undef), undef); ok(arp_add(undef, "XXX"), undef); ok(arp_add("XXX", undef), undef); ok(arp_add("172.16.255.2", "de:ad:be:af:00:00"), 1); ok(arp_get(undef), undef); ok(arp_get("XXX"), undef); ok(arp_get("172.16.255.2"), "de:ad:be:af:00:00"); ok(arp_delete(undef), undef); ok(arp_delete("XXX"), undef); ok(arp_delete("172.16.255.2"), 1); # remove dummy configuration system("ifconfig $if->{name} delete 172.16.255.1") && die "system"; Net-Libdnet-0.99/t/07-intf.t0000644000175000017500000000144613350210754014431 0ustar gomorgomor#!/usr/bin/perl # # $Id$ # use Test; BEGIN{ plan tests => 9 }; use Net::Libdnet; # the tests may destroy your network configuration. # just fake them for those people who did not explicitely require them. if( !$ENV{REAL_TESTS} ){ print STDERR "$0: faking dangerous tests\n"; for( $i=0 ; $i<9 ; $i++ ){ ok(1); }; exit 0; } # gateway to a.root-server.net $gw = route_get("198.41.0.4"); ok(intf_get_dst(undef)->{name}, undef); ok(intf_get_dst("XXX")->{name}, undef); $if = intf_get_dst($gw); $name = $if->{name}; $ip = $if->{addr}; $ip =~ s,/.*$,,; ok(defined($name), 1); ok(intf_get(undef)->{name}, undef); ok(intf_get("XXX")->{name}, undef); ok(intf_get($name)->{name}, $name); ok(intf_get_src(undef)->{name}, undef); ok(intf_get_src("XXX")->{name}, undef); ok(intf_get_src($ip)->{name}, $name); Net-Libdnet-0.99/t/02-addr.t0000644000175000017500000000204313350210754014370 0ustar gomorgomor#!/usr/bin/perl # # $Id$ # use Test; BEGIN{ plan tests => 18 }; use Net::Libdnet; # the tests may destroy your network configuration. # just fake them for those people who did not explicitely require them. if( !$ENV{REAL_TESTS} ){ print STDERR "$0: faking dangerous tests\n"; for( $i=0 ; $i<18 ; $i++ ){ ok(1); }; exit 0; } ok(addr_cmp(undef, "1.2.3.4"), undef); ok(addr_cmp("1.2.3.4", undef), undef); ok(addr_cmp("XXX", "1.2.3.4"), undef); ok(addr_cmp("1.2.3.4", "XXX"), undef); ok(addr_cmp("1.2.3.5", "1.2.3.4"), 1); ok(addr_cmp("1.2.3.4", "1.2.3.4"), 0); ok(addr_cmp("1.2.3.4", "1.2.3.5"), -1); ok(addr_cmp("00:00:DE:AD:BE:B0", "00:00:DE:AD:BE:AF"), 1); ok(addr_cmp("00:00:DE:AD:BE:AF", "00:00:DE:AD:BE:AF"), 0); ok(addr_cmp("00:00:DE:AD:BE:AF", "00:00:DE:AD:BE:B0"), -1); ok(addr_bcast(undef), undef); ok(addr_bcast("XXX"), undef); ok(addr_bcast("1.2.3.4"), "1.2.3.4"); ok(addr_bcast("1.2.3.4/16"), "1.2.255.255"); ok(addr_net(undef), undef); ok(addr_net("XXX"), undef); ok(addr_net("1.2.3.4"), "1.2.3.4"); ok(addr_net("1.2.3.4/16"), "1.2.0.0"); Net-Libdnet-0.99/t/01-module.t0000644000175000017500000000013213350210754014737 0ustar gomorgomor#!/usr/bin/perl # # $Id$ # use Test; BEGIN{ plan tests => 1 }; use Net::Libdnet; ok(1); Net-Libdnet-0.99/t/20-pod-coverage.t0000644000175000017500000000101413350210754016026 0ustar gomorgomoreval "use Test::Pod::Coverage tests => 9"; if ($@) { use Test; plan(tests => 1); skip("Test::Pod::Coverage required for testing"); } else { pod_coverage_ok("Net::Libdnet"); pod_coverage_ok("Net::Libdnet::Arp"); pod_coverage_ok("Net::Libdnet::Route"); pod_coverage_ok("Net::Libdnet::Intf"); pod_coverage_ok("Net::Libdnet::Fw"); pod_coverage_ok("Net::Libdnet::Eth"); pod_coverage_ok("Net::Libdnet::Ip"); pod_coverage_ok("Net::Libdnet::Tun"); pod_coverage_ok("Net::Libdnet::Entry::Intf"); } Net-Libdnet-0.99/t/08-ip.t0000644000175000017500000000013213350210754014071 0ustar gomorgomor#!/usr/bin/perl # # $Id$ # use Test; BEGIN{ plan tests => 1 }; use Net::Libdnet; ok(1); Net-Libdnet-0.99/t/04-blob.t0000644000175000017500000000013213350210754014373 0ustar gomorgomor#!/usr/bin/perl # # $Id$ # use Test; BEGIN{ plan tests => 1 }; use Net::Libdnet; ok(1); Net-Libdnet-0.99/t/21-test-pod.t0000644000175000017500000000023113350210754015213 0ustar gomorgomoreval "use Test::Pod 1.00"; if ($@) { use Test; plan(tests => 1); skip("Test::Pod 1.00 required for testing"); } else { all_pod_files_ok(); } Net-Libdnet-0.99/t/11-entry-intf.t0000644000175000017500000000021313350210754015552 0ustar gomorgomoruse Test; BEGIN { plan(tests => 1) } use Net::Libdnet::Entry::Intf; my $e = Net::Libdnet::Entry::Intf->new; defined($e) ? ok(1) : ok(0); Net-Libdnet-0.99/t/06-fw.t0000644000175000017500000000013213350210754014073 0ustar gomorgomor#!/usr/bin/perl # # $Id$ # use Test; BEGIN{ plan tests => 1 }; use Net::Libdnet; ok(1); Net-Libdnet-0.99/t/10-route.t0000644000175000017500000000235013350210754014614 0ustar gomorgomor#!/usr/bin/perl # # $Id$ # use Test; BEGIN{ plan tests => 14 }; use Net::Libdnet; # the tests may destroy your network configuration. # just fake them for those people who did not explicitely require them. if( !$ENV{REAL_TESTS} ){ print STDERR "$0: faking dangerous tests\n"; for( $i=0 ; $i<14 ; $i++ ){ ok(1); }; exit 0; } # gateway to a.root-server.net # configure dummy network $gw = route_get("198.41.0.4"); $if = intf_get_dst($gw); system("ifconfig $if->{name} add 172.16.255.1 netmask 255.255.255.0") && die "system"; arp_add("172.16.255.2", "de:ad:be:af:00:00"); ok(route_add(undef, "172.16.255.2"), undef); ok(route_add("172.16.254.2", undef), undef); ok(route_add("XXX", "172.16.255.2"), undef); ok(route_add("172.16.254.2", "XXX"), undef); ok(route_add("172.16.254.2", "172.16.255.2"), 1); ok(route_get(undef), undef); ok(route_get("XXX"), undef); ok(route_get("172.16.254.2"), "172.16.255.2"); ok(route_get("172.16.253.2"), $gw); ok(route_delete(undef), undef); ok(route_delete("XXX"), undef); ok(route_delete("172.16.254.3"), undef); ok(route_delete("172.16.254.2"), 1); ok(route_get("172.16.254.2"), $gw); # remove dummy configuration arp_delete("172.16.255.2"); system("ifconfig $if->{name} delete 172.16.255.1") && die "system"; Net-Libdnet-0.99/t/09-rand.t0000644000175000017500000000013213350210754014406 0ustar gomorgomor#!/usr/bin/perl # # $Id$ # use Test; BEGIN{ plan tests => 1 }; use Net::Libdnet; ok(1); Net-Libdnet-0.99/t/05-eth.t0000644000175000017500000000013213350210754014236 0ustar gomorgomor#!/usr/bin/perl # # $Id$ # use Test; BEGIN{ plan tests => 1 }; use Net::Libdnet; ok(1); Net-Libdnet-0.99/lib/0000755000175000017500000000000013350211717013356 5ustar gomorgomorNet-Libdnet-0.99/lib/Net/0000755000175000017500000000000013350211717014104 5ustar gomorgomorNet-Libdnet-0.99/lib/Net/Libdnet/0000755000175000017500000000000013350211717015465 5ustar gomorgomorNet-Libdnet-0.99/lib/Net/Libdnet/Entry/0000755000175000017500000000000013350211717016566 5ustar gomorgomorNet-Libdnet-0.99/lib/Net/Libdnet/Entry/Intf.pm0000644000175000017500000001200313350210754020020 0ustar gomorgomor# # $Id: Intf.pm,v 09f6d620bca4 2012/11/02 16:39:39 gomor $ # package Net::Libdnet::Entry::Intf; use strict; use warnings; use base qw(Class::Gomor::Array); our @AS = qw( aliasNum mtu len type name dstAddr linkAddr flags addr ip subnet broadcast cidr ); our @AA = qw( aliasAddrs ); __PACKAGE__->cgBuildIndices; __PACKAGE__->cgBuildAccessorsScalar(\@AS); __PACKAGE__->cgBuildAccessorsArray (\@AA); use Net::Libdnet qw(:consts :obsolete); sub new { my $self = shift->SUPER::new( aliasAddrs => [], @_, ); return $self; } sub newFromHash { my $self = shift->SUPER::new; my ($h) = @_; $self->aliasNum ($h->{intf_alias_num}) if defined($h->{intf_alias_num}); $self->mtu ($h->{intf_mtu}) if defined($h->{intf_mtu}); $self->len ($h->{intf_len}) if defined($h->{intf_len}); $self->type ($h->{intf_type}) if defined($h->{intf_type}); $self->name ($h->{intf_name}) if defined($h->{intf_name}); $self->dstAddr ($h->{intf_dst_addr}) if defined($h->{intf_dst_addr}); $self->linkAddr ($h->{intf_link_addr}) if defined($h->{intf_link_addr}); $self->flags ($h->{intf_flags}) if defined($h->{intf_flags}); $self->aliasAddrs($h->{intf_alias_addrs}) if defined($h->{intf_alias_addrs}); if (defined($h->{intf_addr})) { $self->addr($h->{intf_addr}); $self->subnet(addr_net($h->{intf_addr})); $self->broadcast(addr_bcast($h->{intf_addr})); my ($ip, $cidr) = split('/', $h->{intf_addr}); $self->ip($ip) if defined($ip); $self->cidr($cidr) if defined($cidr); } return $self; } sub tohash { my $self = shift; my %hash; $hash{intf_alias_num} = $self->aliasNum if defined($self->aliasNum); $hash{intf_mtu} = $self->mtu if defined($self->mtu); $hash{intf_len} = $self->len if defined($self->len); $hash{intf_type} = $self->type if defined($self->type); $hash{intf_name} = $self->name if defined($self->name); $hash{intf_dst_addr} = $self->dstAddr if defined($self->dstAddr); $hash{intf_link_addr} = $self->linkAddr if defined($self->linkAddr); $hash{intf_flags} = $self->flags if defined($self->flags); $hash{intf_alias_addrs} = $self->aliasAddrs if defined($self->aliasAddrs); $hash{intf_addr} = $self->addr if defined($self->addr); return \%hash; } # # Courtesy of Net::IPv4Addr # sub cidr2mask { my $self = shift; return unless $self->cidr; my $cidr = $self->cidr; return unless ($cidr > 0 && $cidr < 33); my $bits = '1'x$cidr.'0'x(32 - $cidr); return join(".", unpack('CCCC', pack('B*', $bits))); } # # Courtesy of Net::IPv4Addr # sub mask2cidr { my $self = shift; my ($mask) = @_; return unless $mask; my @toks = split(/\./, $mask); return unless @toks == 4; my $cidr = 0; for (@toks) { my $bits = unpack('B*', pack('C', $_)); $cidr += $bits =~ tr/1/1/; } return $cidr; } sub flags2string { my $self = shift; my $flags = $self->flags; my $buf = ''; if ($flags & DNET_INTF_FLAG_UP) { $buf .= "UP," } if ($flags & DNET_INTF_FLAG_LOOPBACK) { $buf .= "LOOPBACK," } if ($flags & DNET_INTF_FLAG_POINTOPOINT) { $buf .= "POINTOPOINT," } if ($flags & DNET_INTF_FLAG_NOARP) { $buf .= "NOARP," } if ($flags & DNET_INTF_FLAG_BROADCAST) { $buf .= "BROADCAST," } if ($flags & DNET_INTF_FLAG_MULTICAST) { $buf .= "MULTICAST," } $buf =~ s/,$//; return $buf; } sub print { my $self = shift; my $buf = sprintf("%s: flags=0x%02x<%s>", $self->name, $self->flags, $self->flags2string); if ($self->mtu != 0) { $buf .= sprintf(" mtu %d", $self->mtu); } $buf .= sprintf("\n"); if ($self->addr && $self->dstAddr) { $buf .= sprintf("\taddr %s --> %s\n", $self->addr, $self->dstAddr); } elsif ($self->addr) { $buf .= sprintf("\taddr %s\n", $self->addr); } if ($self->ip) { $buf .= sprintf("\tip %s\n", $self->ip); } if ($self->subnet && $self->cidr) { $buf .= sprintf("\tsubnet %s - cidr %s [mask %s]\n", $self->subnet, $self->cidr, $self->cidr2mask); } if ($self->broadcast) { $buf .= sprintf("\tbroadcast %s\n", $self->broadcast); } if ($self->linkAddr) { $buf .= sprintf("\tlinkAddr %s\n", $self->linkAddr); } for ($self->aliasAddrs) { $buf .= sprintf("\talias %s\n", $_); } $buf =~ s/\n$//; return $buf; } 1; __END__ =head1 NAME Net::Libdnet::Entry::Intf - Intf Entry object =head1 SYNOPSIS XXX =head1 DESCRIPTION XXX =head1 METHODS =over 4 =item B =item B =item B =item B =item B =item B =item B =back =head1 AUTHOR Patrice EGomoRE Auffret =head1 COPYRIGHT AND LICENSE You may distribute this module under the terms of the BSD license. See LICENSE file in the source distribution archive. Copyright (c) 2008-2012, Patrice Auffret =cut Net-Libdnet-0.99/lib/Net/Libdnet/Arp.pm0000644000175000017500000000507413350211335016547 0ustar gomorgomor# # $Id: Arp.pm,v c181470c4357 2018/09/18 14:59:41 gomor $ # package Net::Libdnet::Arp; use strict; use warnings; use base qw(Class::Gomor::Array); our @AS = qw( _handle ); __PACKAGE__->cgBuildIndices; __PACKAGE__->cgBuildAccessorsScalar(\@AS); use Net::Libdnet qw(:arp); sub new { my $self = shift->SUPER::new(@_); my $handle = dnet_arp_open() or return; $self->_handle($handle); $self; } sub add { my $self = shift; my ($ip, $mac) = @_; dnet_arp_add($self->_handle, {arp_pa => $ip, arp_ha => $mac}); } sub delete { my $self = shift; my ($dst) = @_; dnet_arp_delete($self->_handle, {arp_pa => $dst}); } sub get { my $self = shift, my ($dst) = @_; my $h = dnet_arp_get($self->_handle, {arp_pa => $dst}); return $h->{arp_ha} if $h; undef; } sub loop { my $self = shift; my ($sub, $data) = @_; dnet_arp_loop($self->_handle, $sub, $data || \''); } sub DESTROY { my $self = shift; defined($self->_handle) && dnet_arp_close($self->_handle); } 1; __END__ =head1 NAME Net::Libdnet::Arp - high level API to access libdnet arp_* functions =head1 SYNOPSIS use Net::Libdnet::Arp; my $h = Net::Libdnet::Arp->new; my $mac = $h->get('10.0.0.1'); my $success = $h->add('10.0.0.1', '00:11:22:33:44:55'); my $success = $h->delete('10.0.0.1', '00:11:22:33:44:55'); my $data; $h->loop(\&arp_print, \$data); sub arp_print { my ($e, $data) = @_; printf("%s at %s\n", $e->{arp_pa}, $e->{arp_ha}); } =head1 DESCRIPTION This modules is a higher level abstraction for libdnet arp_* functions. =head1 METHODS =over 4 =item B () Returns an object to access arp cache table on success, undef otherwise. =item B (scalar) Returns the mac address of specified IP address, undef otherwise. =item B (scalar, scalar) Adds an entry to arp cache table. Returns 1 on success, undef otherwise. First parameter is the IP address, second is the mac address. =item B (scalar, scalar) Deletes an entry from arp cache table. Returns 1 on success, undef otherwise. First parameter is the IP address, second is the mac address. =item B (subref, [ scalarref ]) Calls the specified sub ref for each entry in the arp cache table. The second optional parameter is a scalar ref, to store state information (if any). =back =head1 AUTHOR Patrice EGomoRE Auffret =head1 COPYRIGHT AND LICENSE You may distribute this module under the terms of the BSD license. See LICENSE file in the source distribution archive. Copyright (c) 2008-2012, Patrice Auffret =cut Net-Libdnet-0.99/lib/Net/Libdnet/Ip.pm0000644000175000017500000000230513350210754016373 0ustar gomorgomor# # $Id: Ip.pm,v 09f6d620bca4 2012/11/02 16:39:39 gomor $ # package Net::Libdnet::Ip; use strict; use warnings; use base qw(Class::Gomor::Array); our @AS = qw( _handle ); __PACKAGE__->cgBuildIndices; __PACKAGE__->cgBuildAccessorsScalar(\@AS); use Net::Libdnet qw(:ip); sub new { my $self = shift->SUPER::new(@_); my $handle = dnet_ip_open() or die("Ip::new: unable to open"); $self->_handle($handle); $self; } sub checksum { my $self = shift; my ($buf) = @_; dnet_ip_checksum($buf, length($buf)); } sub send { my $self = shift; my ($buf) = @_; dnet_ip_send($self->_handle, $buf, length($buf)); } sub DESTROY { my $self = shift; defined($self->_handle) && dnet_ip_close($self->_handle); } 1; __END__ =head1 NAME Net::Libdnet::Ip - high level API to access libdnet ip_* functions =head1 SYNOPSIS XXX =head1 DESCRIPTION XXX =head1 METHODS =over 4 =item B =item B =item B =back =head1 AUTHOR Patrice EGomoRE Auffret =head1 COPYRIGHT AND LICENSE You may distribute this module under the terms of the BSD license. See LICENSE file in the source distribution archive. Copyright (c) 2008-2012, Patrice Auffret =cut Net-Libdnet-0.99/lib/Net/Libdnet/Eth.pm0000644000175000017500000000357013350211335016544 0ustar gomorgomor# # $Id: Eth.pm,v c181470c4357 2018/09/18 14:59:41 gomor $ # package Net::Libdnet::Eth; use strict; use warnings; use base qw(Class::Gomor::Array); our @AS = qw( device _handle ); __PACKAGE__->cgBuildIndices; __PACKAGE__->cgBuildAccessorsScalar(\@AS); use Net::Libdnet qw(:eth); sub new { my $self = shift->SUPER::new(@_); my $handle = dnet_eth_open($self->device) or return; $self->_handle($handle); $self; } sub get { my $self = shift; dnet_eth_get($self->_handle); } sub set { my $self = shift; my ($addr) = @_; dnet_eth_set($self->_handle, $addr); } sub send { my $self = shift; my ($buf) = @_; dnet_eth_send($self->_handle, $buf, length($buf)); } sub DESTROY { my $self = shift; defined($self->_handle) && dnet_eth_close($self->_handle); } 1; __END__ =head1 NAME Net::Libdnet::Eth - high level API to access libdnet eth_* functions =head1 SYNOPSIS use Net::Libdnet::Eth; my $h = Net::Libdnet::Eth->new(device => 'eth0'); =head1 DESCRIPTION This modules is a higher level abstraction for libdnet eth_* functions. =head1 METHODS =over 4 =item B (device => scalar) Returns an object to eth layer on success, undef otherwise. You MUST give a network interface to use for sending. =item B () Returns the hardware address associated with used network interface. Returns undef on error. =item B (scalar) Sets the hardware address specified by scalar of used network interface. Returns undef on error. =item B (scalar) Sends the raw data specified by scalar to the network interface. Returns the number of bytes sent on success, undef on error. =back =head1 AUTHOR Patrice EGomoRE Auffret =head1 COPYRIGHT AND LICENSE You may distribute this module under the terms of the BSD license. See LICENSE file in the source distribution archive. Copyright (c) 2008-2012, Patrice Auffret =cut Net-Libdnet-0.99/lib/Net/Libdnet/Route.pm0000644000175000017500000000314413350210754017123 0ustar gomorgomor# # $Id: Route.pm,v 09f6d620bca4 2012/11/02 16:39:39 gomor $ # package Net::Libdnet::Route; use strict; use warnings; use base qw(Class::Gomor::Array); our @AS = qw( _handle ); __PACKAGE__->cgBuildIndices; __PACKAGE__->cgBuildAccessorsScalar(\@AS); use Net::Libdnet qw(:route); sub new { my $self = shift->SUPER::new(@_); my $handle = dnet_route_open() or die("Route::new: unable to open"); $self->_handle($handle); $self; } sub add { my $self = shift; my ($dst, $gateway) = @_; dnet_route_add($self->_handle, {route_dst => $dst, route_gw => $gateway}); } sub delete { my $self = shift; my ($dst, $gateway) = @_; dnet_route_delete($self->_handle, {route_dst => $dst, route_gw => $gateway}); } sub get { my $self = shift, my ($dst) = @_; my $h = dnet_route_get($self->_handle, {route_dst => $dst}); return $h->{route_gw} if $h; undef; } sub loop { my $self = shift; my ($sub, $data) = @_; dnet_route_loop($self->_handle, $sub, $data || \''); } sub DESTROY { my $self = shift; defined($self->_handle) && dnet_route_close($self->_handle); } 1; __END__ =head1 NAME Net::Libdnet::Route - high level API to access libdnet route_* functions =head1 SYNOPSIS XXX =head1 DESCRIPTION XXX =head1 METHODS =over 4 =item B =item B =item B =item B =item B =back =head1 AUTHOR Patrice EGomoRE Auffret =head1 COPYRIGHT AND LICENSE You may distribute this module under the terms of the BSD license. See LICENSE file in the source distribution archive. Copyright (c) 2008-2012, Patrice Auffret =cut Net-Libdnet-0.99/lib/Net/Libdnet/Intf.pm0000644000175000017500000000430113350210754016721 0ustar gomorgomor# # $Id: Intf.pm,v 09f6d620bca4 2012/11/02 16:39:39 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__ =head1 NAME Net::Libdnet::Intf - high level API to access libdnet intf_* functions =head1 SYNOPSIS XXX =head1 DESCRIPTION XXX =head1 METHODS =over 4 =item B =item B =item B =item B =item B =item B =back =over 4 =item B =item B =back =head1 AUTHOR Patrice EGomoRE Auffret =head1 COPYRIGHT AND LICENSE You may distribute this module under the terms of the BSD license. See LICENSE file in the source distribution archive. Copyright (c) 2008-2012, Patrice Auffret =cut Net-Libdnet-0.99/lib/Net/Libdnet/Tun.pm0000644000175000017500000000325313350210754016574 0ustar gomorgomor# # $Id: Tun.pm,v 09f6d620bca4 2012/11/02 16:39:39 gomor $ # package Net::Libdnet::Tun; use strict; use warnings; use base qw(Class::Gomor::Array); our @AS = qw( src dst _mtu _handle ); __PACKAGE__->cgBuildIndices; __PACKAGE__->cgBuildAccessorsScalar(\@AS); use Net::Libdnet qw(:tun); sub _getMtu { my ($src) = @_; my $h = dnet_intf_open() or return; my $intf = dnet_intf_get_src($h, $src) or return; $intf->{intf_mtu} || undef; } sub new { my $self = shift->SUPER::new(@_); my $mtu = _getMtu($self->src) or die("Tun::new: unable to get mtu"); $self->_mtu($mtu); my $handle = dnet_tun_open($self->src, $self->dst, $mtu) or die("Tun::new: unable to open"); $self->_handle($handle); $self; } sub fileno { my $self = shift; dnet_tun_fileno($self->_handle); } sub name { my $self = shift; dnet_tun_name($self->_handle); } sub send { my $self = shift; my ($buf) = @_; dnet_tun_send($self->_handle, $buf, length($buf)); } sub recv { my $self = shift; dnet_tun_recv($self->_handle, $self->_mtu); } sub DESTROY { my $self = shift; defined($self->_handle) && dnet_tun_close($self->_handle); } 1; __END__ =head1 NAME Net::Libdnet::Tun - high level API to access libdnet tun_* functions =head1 SYNOPSIS XXX =head1 DESCRIPTION XXX =head1 METHODS =over 4 =item B =item B =item B =item B =item B =back =head1 AUTHOR Patrice EGomoRE Auffret =head1 COPYRIGHT AND LICENSE You may distribute this module under the terms of the BSD license. See LICENSE file in the source distribution archive. Copyright (c) 2008-2012, Patrice Auffret =cut Net-Libdnet-0.99/lib/Net/Libdnet/Fw.pm0000644000175000017500000000652113350210754016403 0ustar gomorgomor# # $Id: Fw.pm,v 09f6d620bca4 2012/11/02 16:39:39 gomor $ # package Net::Libdnet::Fw; use strict; use warnings; use base qw(Class::Gomor::Array); our @AS = qw( _handle ); __PACKAGE__->cgBuildIndices; __PACKAGE__->cgBuildAccessorsScalar(\@AS); use Net::Libdnet qw(:fw :consts); sub new { my $self = shift->SUPER::new(@_); my $handle = dnet_fw_open() or die("Fw::new: unable to open"); $self->_handle($handle); $self; } # # block out eth1 tcp 127.0.0.1:4000-4100 127.0.0.2:4300-4400 # block out eth1 icmp 127.0.0.1:4000-4100 127.0.0.2:4300-4400 0/0 # sub _to_hash { my ($rule) = @_; my @toks = split(/ +/, $rule); my ($op, $dir, $device, $proto, $src, $dst, $sport, $dport, $type, $code); my $srcOk; for (@toks) { if (/^block$|^allow$/i) { $op = $_ } elsif (/^in$|^out$/i) { $dir = $_ } elsif (/^tcp$|^udp$|^icmp$/) { $proto = $_ } elsif (!$srcOk && /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/) { my @src = split(/:/); $src = $src[0] if defined($src[0]); if (defined($src[1])) { my @port = split(/-/, $src[1]); push @$sport, $port[0] if defined($port[0]); push @$sport, $port[1] if defined($port[1]); } $srcOk++; } elsif ($srcOk && /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/) { my @dst = split(/:/); $dst = $dst[0] if defined($dst[0]); if (defined($dst[1])) { my @port = split(/-/, $dst[1]); push @$dport, $port[0] if defined($port[0]); push @$dport, $port[1] if defined($port[1]); } } else { $device = $_; } } if (defined($op)) { if ($op =~ /block/i) { $op = DNET_FW_OP_BLOCK } elsif ($op =~ /allow/i) { $op = DNET_FW_OP_ALLOW } } if (defined($dir)) { if ($dir =~ /in/i) { $dir = DNET_FW_DIR_IN } elsif ($dir =~ /out/i) { $dir = DNET_FW_DIR_OUT } } if (defined($proto)) { if ($proto =~ /tcp/i) { $proto = 0x06 } elsif ($proto =~ /udp/i) { $proto = 0x11 } elsif ($proto =~ /icmp/i) { $proto = 0x01 } } my $h = { fw_device => $device || 'any', fw_op => $op || DNET_FW_OP_BLOCK, fw_dir => $dir || DNET_FW_DIR_IN, fw_proto => $proto || 0, fw_src => $src || '0.0.0.0/0', fw_dst => $dst || '0.0.0.0/0', fw_sport => $sport || [0, 0], fw_dport => $dport || [0, 0], }; } sub add { my $self = shift; my ($rule) = @_; dnet_fw_add($self->_handle, _to_hash($rule)); } sub delete { my $self = shift; my ($rule) = @_; dnet_fw_delete($self->_handle, _to_hash($rule)); } sub loop { my $self = shift; my ($sub, $data) = @_; dnet_fw_loop($self->_handle, $sub, $data || \''); } sub DESTROY { my $self = shift; defined($self->_handle) && dnet_fw_close($self->_handle); } 1; __END__ =head1 NAME Net::Libdnet::Fw - high level API to access libdnet fw_* functions =head1 SYNOPSIS XXX =head1 DESCRIPTION XXX =head1 METHODS =over 4 =item B =item B =item B =item B =back =head1 AUTHOR Patrice EGomoRE Auffret =head1 COPYRIGHT AND LICENSE You may distribute this module under the terms of the BSD license. See LICENSE file in the source distribution archive. Copyright (c) 2008-2012, Patrice Auffret =cut Net-Libdnet-0.99/lib/Net/Libdnet.pm0000644000175000017500000004410413350211714016023 0ustar gomorgomor# # $Id: Libdnet.pm,v c0d1c989fec0 2018/09/18 15:03:40 gomor $ # # Copyright (c) 2004 Vlad Manilici # Copyright (c) 2008-2012 Patrice Auffret # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package Net::Libdnet; use strict; use warnings; use base qw(Exporter DynaLoader); our $VERSION = '0.99'; our %EXPORT_TAGS = ( obsolete => [qw( addr_cmp addr_bcast addr_net arp_add arp_delete arp_get intf_get intf_get_src intf_get_dst route_add route_delete route_get )], route => [qw( dnet_route_open dnet_route_add dnet_route_delete dnet_route_get dnet_route_loop dnet_route_close )], intf => [qw( dnet_intf_open dnet_intf_get dnet_intf_get_src dnet_intf_get_dst dnet_intf_set dnet_intf_loop dnet_intf_close )], arp => [qw( dnet_arp_open dnet_arp_add dnet_arp_delete dnet_arp_get dnet_arp_loop dnet_arp_close )], fw => [qw( dnet_fw_open dnet_fw_add dnet_fw_delete dnet_fw_loop dnet_fw_close )], tun => [qw( dnet_tun_open dnet_tun_fileno dnet_tun_name dnet_tun_send dnet_tun_recv dnet_tun_close )], eth => [qw( dnet_eth_open dnet_eth_get dnet_eth_set dnet_eth_send dnet_eth_close )], ip => [qw( dnet_ip_open dnet_ip_checksum dnet_ip_send dnet_ip_close )], consts => [qw( DNET_ADDR_TYPE_NONE DNET_ADDR_TYPE_ETH DNET_ADDR_TYPE_IP DNET_ADDR_TYPE_IP6 DNET_FW_OP_ALLOW DNET_FW_OP_BLOCK DNET_FW_DIR_IN DNET_FW_DIR_OUT DNET_INTF_TYPE_OTHER DNET_INTF_TYPE_ETH DNET_INTF_TYPE_LOOPBACK DNET_INTF_TYPE_TUN DNET_INTF_FLAG_UP DNET_INTF_FLAG_LOOPBACK DNET_INTF_FLAG_POINTOPOINT DNET_INTF_FLAG_NOARP DNET_INTF_FLAG_BROADCAST DNET_INTF_FLAG_MULTICAST )], ); our @EXPORT = ( @{$EXPORT_TAGS{consts}}, @{$EXPORT_TAGS{obsolete}}, @{$EXPORT_TAGS{route}}, @{$EXPORT_TAGS{intf}}, @{$EXPORT_TAGS{arp}}, @{$EXPORT_TAGS{fw}}, @{$EXPORT_TAGS{tun}}, @{$EXPORT_TAGS{eth}}, @{$EXPORT_TAGS{ip}}, ); __PACKAGE__->bootstrap($VERSION); use constant DNET_ADDR_TYPE_NONE => 0; use constant DNET_ADDR_TYPE_ETH => 1; use constant DNET_ADDR_TYPE_IP => 2; use constant DNET_ADDR_TYPE_IP6 => 3; use constant DNET_FW_OP_ALLOW => 1; use constant DNET_FW_OP_BLOCK => 2; use constant DNET_FW_DIR_IN => 1; use constant DNET_FW_DIR_OUT => 2; use constant DNET_INTF_TYPE_OTHER => 1; use constant DNET_INTF_TYPE_ETH => 6; use constant DNET_INTF_TYPE_LOOPBACK => 24; use constant DNET_INTF_TYPE_TUN => 53; use constant DNET_INTF_FLAG_UP => 0x01; use constant DNET_INTF_FLAG_LOOPBACK => 0x02; use constant DNET_INTF_FLAG_POINTOPOINT => 0x04; use constant DNET_INTF_FLAG_NOARP => 0x08; use constant DNET_INTF_FLAG_BROADCAST => 0x10; use constant DNET_INTF_FLAG_MULTICAST => 0x20; sub addr_cmp { _obsolete_addr_cmp (@_) } sub addr_bcast { _obsolete_addr_bcast (@_) } sub addr_net { _obsolete_addr_net (@_) } sub arp_add { _obsolete_arp_add (@_) } sub arp_delete { _obsolete_arp_delete (@_) } sub arp_get { _obsolete_arp_get (@_) } sub intf_get { _obsolete_intf_get (@_) } sub intf_get_src { _obsolete_intf_get_src(@_) } sub intf_get_dst { _obsolete_intf_get_dst(@_) } sub route_add { _obsolete_route_add (@_) } sub route_delete { _obsolete_route_delete(@_) } sub route_get { _obsolete_route_get (@_) } 1; __END__ =head1 NAME Net::Libdnet - binding for Dug Song's libdnet =head1 SYNOPSIS # # This will just import every functions and constants # use Net::Libdnet; # # Network interface manipulation # # !!! ADVICE: you should use Net::Libdnet::Intf instead # use Net::Libdnet qw(:intf); my $intf = dnet_intf_open(); my $eth = dnet_intf_get($intf, { intf_name => 'eth0' }); print "IP: ".$eth->{intf_addr}."\n"; print "MAC: ".$eth->{intf_link_addr}."\n"; my $dst = dnet_intf_get_dst($intf, '192.168.0.10'); print "Name: ".$dst->{intf_name}."\n"; print "IP: ".$dst->{intf_addr}."\n"; print "MAC: ".$dst->{intf_link_addr}."\n"; my $src = dnet_intf_get_src($intf, '192.168.0.1'); print "Name: ".$src->{intf_name}."\n"; print "IP: ".$src->{intf_addr}."\n"; print "MAC: ".$src->{intf_link_addr}."\n"; dnet_intf_close($intf); # # Arp cache manipulation # # !!! ADVICE: you should use Net::Libdnet::Arp instead # use Net::Libdnet qw(:arp); my $arp = dnet_arp_open(); my $entry = dnet_arp_get($arp, {arp_pa => '10.0.0.1'}); print "MAC: ".$entry->{arp_ha}."\n"; dnet_arp_add ($arp, {arp_ha => '00:11:22:33:44:55', arp_pa => '10.0.0.10'}); dnet_arp_delete($arp, {arp_ha => '00:11:22:33:44:55', arp_pa => '10.0.0.10'}); dnet_arp_close($arp); # # Route table manipulation # # !!! ADVICE: you should use Net::Libdnet::Route instead # use Net::Libdnet qw(:route); my $route = dnet_route_open(); dnet_route_add ($route, {route_gw => '10.0.0.1', route_dst => '192.168.0.1'}); dnet_route_delete($route, {route_gw => '10.0.0.1', route_dst => '192.168.0.1'}); my $get = dnet_route_get($route, {route_dst => '192.168.0.10'}); print "GW: ".$get->{route_gw}."\n"; dnet_route_close($route); # # Firewall rules manipulation # # !!! ADVICE: you should use Net::Libdnet::Fw instead # use Net::Libdnet qw(:fw :consts); my $fw = dnet_fw_open(); # This is quite complex. This rule blocks TCP as input to 10.0.0.1 # You should really use Net::Libdnet::Fw instead. dnet_fw_add ($fw, {fw_op => FW_DIR_IN, fw_proto => 6, fw_dst => '10.0.0.1'}); dnet_fw_delete($fw, {fw_op => FW_DIR_IN, fw_proto => 6, fw_dst => '10.0.0.1'}); dnet_fw_close($fw); # # Send at IP level # # !!! ADVICE: you should use Net::Libdnet::Ip instead # use Net::Libdnet qw(:ip); my $ip = dnet_ip_open(); my $raw = "\x47\x47\x47\x47"; dnet_ip_send($ip, $raw, length($raw)); dnet_ip_close($ip); # # Send at Ethernet level # # !!! ADVICE: you should use Net::Libdnet::Eth instead # use Net::Libdnet qw(:eth); my $eth = dnet_eth_open('eth0'); dnet_eth_send($eth, $raw, length($raw)); dnet_eth_close($eth); # # Traffic interception # # !!! ADVICE: you should use Net::Libdnet::Tun instead # use Net::Libdnet qw(:tun); my $tun = dnet_tun_open('10.0.0.10', '192.168.0.10', 1500); my $buf = dnet_tun_recv($tun, 1500); # Do stuff with $buf dnet_tun_send($tun, $buf, length($buf)); dnet_tun_close($tun); # # hash refs in dnet format # my $intf = { intf_alias_num => 1, intf_mtu => 1500, intf_len => 112, intf_type => 6, intf_name => 'eth0', intf_dst_addr => undef, intf_link_addr => '00:11:22:33:44:55', intf_flags => 49, intf_addr => '10.100.0.10/24', intf_alias_addrs => [ 'fe80::211:2ff:fe33:4455/64' ] }; my $arp = { arp_pa => '10.100.0.1', arp_ha => '11:22:33:44:55:66' }; my $route = { route_gw => '10.100.0.1', route_dst => '0.0.0.0/0' }; my $fw = { fw_dir => 2, fw_sport => [ 0, 0 ], fw_dport => [ 0, 0 ], fw_src => '0.0.0.0/0', fw_dst => '0.0.0.0/0', fw_proto => 6, fw_device => 'eth0', fw_op => 2 }; =head1 DESCRIPTION Net::Libdnet provides a simplified, portable interface to several low-level networking routines, including network address manipulation, kernel arp cache and route table lookup and manipulation, network firewalling, network interface lookup and manipulation, network traffic interception via tunnel interfaces, and raw IP packet and Ethernet frame transmission. It is intended to complement the functionality provided by libpcap. All the original and obsolete functions return I and print a warning message to the standard error when a problem occurs. The obsolete functions are: B, B, B, B, B, B, B, B, B, B, B, B. These obsolete functions will continue to work, to keep backward compatibility, but should not be used anymore. The new APIs should be preferred. There are two new APIs, one is the low-level one, matching libdnet functions, and the other one is a high-level API, matching a more Perl object oriented programming. This latest one is highly preferred. Net::Libdnet module implements the low-level API. The high-level API is accessible by using the following modules: B, B, B, B, B, B and B. =head1 WHAT IS IMPLEMENTED =over 4 =item B Nothing as of now. =item B
All functions: arp_open, arp_add, arp_delete, arp_get, arp_loop, arp_close. =item B Nothing as of now. =item B All functions: eth_open, eth_get, eth_set, eth_send, eth_close. =item B All functions: fw_open, fw_add, fw_delete, fw_loop, fw_close. =item B All functions: intf_open, intf_get_set, intf_get_dst, intf_set, intf_loop, intf_close. =item B All functions: ip_open, ip_checksum, ip_send, ip_close. Except: ip_add_option. =item B Nothing as of now. =item B Nothing as of now. =item B All functions: route_open, route_add, route_delete, route_get, route_loop, route_close. =item B All functions: tun_open, tun_fileno, tun_name, tun_send, tun_recv, tun_close. =back =head1 SUBROUTINES =over 4 =item B () Opens an interface handle. Returns a handle on success, undef on error. =item B (scalar, hashref) Takes an intf handle, and a hash ref in dnet format as parameters. Returns a hash in dnet format on success, undef on error. =item B (scalar, scalar) Takes an intf handle, and an IP address as parameters. Returns a hash in dnet format on success, undef on error. =item B (scalar, scalar) Takes an intf handle, and an IP address as parameters. Returns a hash in dnet format on success, undef on error. =item B (scalar, scalar) Takes an intf handle, and a hash ref in dnet format as parameters. Returns 1 on success, undef on error. =item B (scalar, subref, scalarref) Takes an intf handle, a subref, and a scalar ref as parameters. Returns 1 on success, undef on error. The subref will be called with an intf hash ref in dnet format, and the scalar ref as parameters. =item B (scalar) Takes an intf handle as parameter. Returns the handle on success, undef on error. =item B () Opens a route handle. Returns a handle on success, undef on error. =item B (scalar, hashref) Takes a route handle, and a hash ref in dnet format as parameters. Returns 1 on success, undef on error. =item B (scalar, hashref) Takes a route handle, and a hash ref in dnet format as parameters. Returns 1 on success, undef on error. =item B (scalar, hashref) Takes a route handle, and a hash ref in dnet format as parameters. Returns a hash ref in dnet format on success, undef on error. =item B (scalar, subref, scalarref) Takes a route handle, a subref, and a scalar ref as parameters. Returns 1 on success, undef on error. The subref will be called with a route hash ref in dnet format, and the scalar ref as parameters. =item B (scalar) Takes a route handle as parameter. Returns the handle on success, undef on error. =item B () Opens an arp handle. Returns a handle on success, undef on error. =item B (scalar, hashref) Takes an arp handle, and a hash ref in dnet format as parameters. Returns 1 on success, undef on error. =item B (scalar, hashref) Takes an arp handle, and a hash ref in dnet format as parameters. Returns 1 on success, undef on error. =item B (scalar, hashref) Takes an arp handle, and a hash ref in dnet format as parameters. Returns a hash ref in dnet format on success, undef on error. =item B (scalar, subref, scalarref) Takes an arp handle, a subref, and a scalar ref as parameters. Returns 1 on success, undef on error. The subref will be called with an arp hash ref in dnet format, and the scalar ref as parameters. =item B (scalar) Takes an arp handle as parameter. Returns the handle on success, undef on error. =item B () Opens a fw handle. Returns a handle on success, undef on error. =item B (scalar, hashref) Takes a fw handle, and a hash ref in dnet format as parameters. Returns 1 on success, undef on error. =item B (scalar, hashref) Takes a fw handle, and a hash ref in dnet format as parameters. Returns 1 on success, undef on error. =item B (scalar, subref, scalarref) Takes a fw handle, a subref, and a scalar ref as parameters. Returns 1 on success, undef on error. The subref will be called with a fw hash ref in dnet format, and the scalar ref as parameters. =item B (scalar) Takes a fw handle as parameter. Returns the handle on success, undef on error. =item B (scalar, scalar, scalar) Creates a tunnel between src and dst IP addresses. Captured packets will have specified size. First argument is the source IP address, second the destination IP address, and the third is the cpature size. Returns a handle on success, undef on error. =item B (scalar) Takes a tun handle as parameter. Returns the file number on success, undef on error. =item B (scalar) Takes a tun handle as parameter. Returns the interface name on success, undef on error. =item B (scalar, scalar, scalar) Takes a tun handle, the raw data to send, and its size as parameters. Returns the number of bytes sent on success, undef on error. =item B (scalar, scalar) Takes a tun handle, and the maximum size to read as parameters. Returns the read buffer on success, undef on error. =item B (scalar) Takes a tun handle as parameter. Returns the handle on success, undef on error. =item B (scalar) Opens an eth handle. Takes an interface name as parameter. Returns a handle on success, undef on error. =item B (scalar) Takes an eth handle as parameter. Returns the hardware address of currently opened eth handle on success, undef on error. =item B (scalar, scalar) Takes an eth handle, and the hardware address to set as parameters. Returns 1 on success, undef on error. =item B (scalar, scalar, scalar) Takes an eth handle, the raw data to send, and its size as parameters. Returns the number of bytes sent on success, undef on error. =item B (scalar) Takes an eth handle as parameter. Returns the handle on success, undef on error. =item B () Opens an ip handle. Returns a handle on success, undef on error. =item B (scalar, scalar) Takes a raw IPv4 frame as the first parameter, and its size as a second parameter. It then updates the frame with the good checksum. Returns nothing. =item B (scalar, scalar, scalar) Takes an ip handle, the raw data to send, and its size as parameters. Returns the number of bytes sent on success, undef on error. =item B (scalar) Takes an ip handle as parameter. Returns the handle on success, undef on error. =back =head1 OBSOLETE FUNCTIONS They should not be used anymore. You have been warned. =over 4 =item B =item B =item B =item B =item B =item B =item B =item B =item B =item B =item B =item B =back =head1 CONSTANTS =over 4 =item B =item B =item B =item B =item B =item B =item B =item B =item B =item B =item B =item B =item B =item B =item B =item B =item B =item B =back =head1 COPYRIGHT AND LICENSE You may distribute this module under the terms of the BSD license. See LICENSE file in the source distribution archive. Copyright (c) 2004, Vlad Manilici Copyright (c) 2008-2012, Patrice Auffret =head1 SEE ALSO L =cut Net-Libdnet-0.99/standard-old.patch0000644000175000017500000000463313350210754016213 0ustar gomorgomorIndex: Makefile.PL =================================================================== --- Makefile.PL (revision 42) +++ Makefile.PL (working copy) @@ -3,10 +3,10 @@ # use ExtUtils::MakeMaker; -my $libs = qx{dumbnet-config --libs 2>/dev/null} - || ['-L/lib -L/usr/lib -L/usr/local/lib -ldumbnet']; +my $libs = qx{dnet-config --libs 2>/dev/null} + || ['-L/lib -L/usr/lib -L/usr/local/lib -ldnet']; -my $inc = qx{dumbnet-config --cflags 2>/dev/null} +my $inc = qx{dnet-config --cflags 2>/dev/null} || '-I/include -I/usr/include -I/usr/local/include'; WriteMakefile( Index: Libdnet.xs =================================================================== --- Libdnet.xs (revision 42) +++ Libdnet.xs (working copy) @@ -34,38 +34,38 @@ #include "XSUB.h" #include -#include +#include -#ifdef DUMBNET_BLOB_H +#ifdef DNET_BLOB_H typedef blob_t Blob; #endif -#ifdef DUMBNET_ETH_H +#ifdef DNET_ETH_H typedef eth_t EthHandle; typedef eth_addr_t EthAddr; #endif -#ifdef DUMBNET_INTF_H +#ifdef DNET_INTF_H typedef intf_t IntfHandle; #endif -#ifdef DUMBNET_ARP_H +#ifdef DNET_ARP_H typedef arp_t ArpHandle; #endif -#ifdef DUMBNET_FW_H +#ifdef DNET_FW_H typedef fw_t FwHandle; #endif -#ifdef DUMBNET_ROUTE_H +#ifdef DNET_ROUTE_H typedef route_t RouteHandle; #endif -#ifdef DUMBNET_TUN_H +#ifdef DNET_TUN_H typedef tun_t TunHandle; #endif -#ifdef DUMBNET_IP_H +#ifdef DNET_IP_H typedef ip_t IpHandle; #endif @@ -866,7 +866,7 @@ # obsolete XS implementation. # -#if defined DUMBNET_INTF_H +#if defined DNET_INTF_H IntfHandle * dnet_intf_open() @@ -981,7 +981,7 @@ #endif -#if defined DUMBNET_ARP_H +#if defined DNET_ARP_H ArpHandle * dnet_arp_open() @@ -1064,7 +1064,7 @@ #endif -#if defined DUMBNET_ROUTE_H +#if defined DNET_ROUTE_H RouteHandle * dnet_route_open() @@ -1148,7 +1148,7 @@ #endif -#if defined DUMBNET_FW_H +#if defined DNET_FW_H FwHandle * dnet_fw_open() @@ -1215,7 +1215,7 @@ #endif -#if defined DUMBNET_TUN_H +#if defined DNET_TUN_H TunHandle * dnet_tun_open(src, dst, size) @@ -1290,7 +1290,7 @@ #endif -#if defined DUMBNET_ETH_H +#if defined DNET_ETH_H EthHandle * dnet_eth_open(device) @@ -1346,7 +1346,7 @@ #endif -#if defined DUMBNET_IP_H +#if defined DNET_IP_H IpHandle * dnet_ip_open() Net-Libdnet-0.99/README0000644000175000017500000000340313350210754013470 0ustar gomorgomorNet::Libdnet ============ DESCRIPTION This is a Perl interface for libdnet. INSTALLATION To install this module type the following: perl Makefile.PL make make test make install Note that "make tests" fakes running the tests. Running them for real is dangerous: you should do this only if you know what you are doing. The real tests require having a configured and connected ethernet interface, with a default route over its (primary, not cloned) IP address. They reversibly modify interface configurations, the ARP table and the routing table. WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! Do not run the real tests unless you are sure you do not harm your configuration or other people! I decline any responsibility whatsoever for what damage you make by running these tests. WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! This being said, you need to set the environment variable REAL_TESTS and have root privileges to run the non-faked tests. UBUNTU/DEBIAN USERS You will have to apply ubuntu-new.patch like the following: $ cd Net-Libdnet-X.YY $ patch -p0 < ubuntu-new.patch To revert back to standard configuration: $ patch -p0 < standard-new.patch If you use an old version of Ubuntu/Debian (don't know which version), you'll have to use ubuntu-old.patch and standard-old.patch files instead. DEPENDENCIES This module requires these other modules and libraries: Perl v5.6.1 libdnet Class::Gomor libdnet may be obtained from http://libdnet.sourceforge.net/. COPYRIGHT AND LICENSE You may distribute this module under the terms of the BSD license. See LICENSE file in the source distribution archive. Copyright (c) 2004, Vlad Manilici Copyright (c) 2008-2012, Patrice Auffret Net-Libdnet-0.99/examples/0000755000175000017500000000000013350211717014426 5ustar gomorgomorNet-Libdnet-0.99/examples/tun-open.pl0000644000175000017500000000060213350210754016526 0ustar gomorgomor#!/usr/bin/perl use strict; use warnings; use Net::Libdnet::Tun; my $h = Net::Libdnet::Tun->new(src => "192.168.0.101", dst => "192.168.0.1"); my $buf = $h->recv; #print unpack('H*', $buf)."\n"; use Net::Frame::Simple; my $fr = Net::Frame::Simple->new( raw => $buf, firstLayer => 'IPv4', ); $fr->unpack; print $fr->print."\n"; my $ret = $h->send($buf); print "RET: $ret\n"; Net-Libdnet-0.99/examples/intf-get-src.pl0000644000175000017500000000033613350210754017267 0ustar gomorgomor#!/usr/bin/perl use strict; use warnings; my $src = shift || die("Pass source IP"); use Net::Libdnet::Intf; my $h = Net::Libdnet::Intf->new; my $info = $h->getSrc($src) or die("FATAL: getSrc"); print $info->print."\n"; Net-Libdnet-0.99/examples/eth-send.pl0000644000175000017500000000023313350210754016470 0ustar gomorgomor#!/usr/bin/perl use strict; use warnings; use Net::Libdnet::Eth; my $h = Net::Libdnet::Eth->new(device => 'eth1'); print $h->get."\n"; $h->send('G'x60); Net-Libdnet-0.99/examples/fw-add.pl0000644000175000017500000000030213350210754016120 0ustar gomorgomor#!/usr/bin/perl use strict; use warnings; my $rule = "@ARGV" || die("Pass rule"); use Net::Libdnet::Fw; my $h = Net::Libdnet::Fw->new; my $s = $h->add($rule); print $s ? "Ok\n" : "Failed\n"; Net-Libdnet-0.99/examples/route-get.pl0000644000175000017500000000033013350210754016672 0ustar gomorgomor#!/usr/bin/perl use strict; use warnings; my $dst = shift || die("Pass dst"); use Net::Libdnet::Route; my $h = Net::Libdnet::Route->new; my $ret = $h->get($dst); $ret ? print "GW: $ret\n" : print "Same subnet\n"; Net-Libdnet-0.99/examples/fw-delete.pl0000644000175000017500000000030513350210754016635 0ustar gomorgomor#!/usr/bin/perl use strict; use warnings; my $rule = "@ARGV" || die("Pass rule"); use Net::Libdnet::Fw; my $h = Net::Libdnet::Fw->new; my $s = $h->delete($rule); print $s ? "Ok\n" : "Failed\n"; Net-Libdnet-0.99/examples/fw-list.pl0000644000175000017500000000032313350210754016346 0ustar gomorgomor#!/usr/bin/perl use strict; use warnings; use Net::Libdnet::Fw; use Data::Dumper; my $h = Net::Libdnet::Fw->new; $h->loop(\&fw_print); sub fw_print { my ($rule, $data) = @_; print Dumper($rule)."\n"; } Net-Libdnet-0.99/examples/route-list.pl0000644000175000017500000000036313350210754017074 0ustar gomorgomor#!/usr/bin/perl use strict; use warnings; use Net::Libdnet::Route; my $h = Net::Libdnet::Route->new; $h->loop(\&route_show); sub route_show { my ($entry, $data) = @_; print "[".$entry->{route_dst}."] -> [".$entry->{route_gw}."]\n"; } Net-Libdnet-0.99/examples/arp-list.pl0000644000175000017500000000035013350210754016514 0ustar gomorgomor#!/usr/bin/perl use strict; use warnings; use Net::Libdnet::Arp; my $h = Net::Libdnet::Arp->new; $h->loop(\&arp_show); sub arp_show { my ($entry, $data) = @_; print "IP: ".$entry->{arp_pa}." MAC: ".$entry->{arp_ha}."\n"; } Net-Libdnet-0.99/examples/arp-get.pl0000644000175000017500000000032313350210754016320 0ustar gomorgomor#!/usr/bin/perl use strict; use warnings; my $ip = shift or die("Pass IP"); use Net::Libdnet::Arp; my $h = Net::Libdnet::Arp->new; my $mac = $h->get($ip); $mac ? print "MAC: $mac\n" : print "Not in cache\n"; Net-Libdnet-0.99/examples/arp-add.pl0000644000175000017500000000037213350210754016275 0ustar gomorgomor#!/usr/bin/perl use strict; use warnings; my $ip = shift or die("Pass IP"); my $mac = shift or die("Pass MAC"); use Net::Libdnet::Arp; my $h = Net::Libdnet::Arp->new; my $success = $h->add($ip, $mac); $success ? print "Ok\n", : print "Failed\n"; Net-Libdnet-0.99/examples/ip-send.pl0000644000175000017500000000016313350210754016322 0ustar gomorgomor#!/usr/bin/perl use strict; use warnings; use Net::Libdnet::Ip; my $h = Net::Libdnet::Ip->new; $h->send('G'x60); Net-Libdnet-0.99/examples/arp-delete.pl0000644000175000017500000000032113350210754017001 0ustar gomorgomor#!/usr/bin/perl use strict; use warnings; my $ip = shift or die("Pass IP"); use Net::Libdnet::Arp; my $h = Net::Libdnet::Arp->new; my $success = $h->delete($ip); $success ? print "Ok\n" : print "Failed\n"; Net-Libdnet-0.99/examples/intf-list.pl0000644000175000017500000000043613350210754016677 0ustar gomorgomor#!/usr/bin/perl use strict; use warnings; use Net::Libdnet::Intf; use Net::Libdnet::Entry::Intf; my $h = Net::Libdnet::Intf->new; $h->loop(\&intf_show); sub intf_show { my ($entry, $data) = @_; my $e = Net::Libdnet::Entry::Intf->newFromHash($entry); print $e->print."\n"; } Net-Libdnet-0.99/examples/intf-get-dst.pl0000644000175000017500000000034313350210754017270 0ustar gomorgomor#!/usr/bin/perl use strict; use warnings; my $dst = shift || die("Pass destination IP"); use Net::Libdnet::Intf; my $h = Net::Libdnet::Intf->new; my $info = $h->getDst($dst) or die("FATAL: getDst"); print $info->print."\n"; Net-Libdnet-0.99/examples/intf-get.pl0000644000175000017500000000033213350210754016476 0ustar gomorgomor#!/usr/bin/perl use strict; use warnings; use Net::Libdnet::Intf; my $intf = shift || die("Pass interface"); my $h = Net::Libdnet::Intf->new; my $info = $h->get($intf) or die("FATAL: get"); print $info->print."\n"; Net-Libdnet-0.99/Libdnet.xs0000644000175000017500000007557313350210754014566 0ustar gomorgomor/* $Id: Libdnet.xs,v 09f6d620bca4 2012/11/02 16:39:39 gomor $ */ /* * Copyright (c) 2004 Vlad Manilici * Copyright (c) 2008-2012 Patrice Auffret * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include #include #ifdef DNET_BLOB_H typedef blob_t Blob; #endif #ifdef DNET_ETH_H typedef eth_t EthHandle; typedef eth_addr_t EthAddr; #endif #ifdef DNET_INTF_H typedef intf_t IntfHandle; #endif #ifdef DNET_ARP_H typedef arp_t ArpHandle; #endif #ifdef DNET_FW_H typedef fw_t FwHandle; #endif #ifdef DNET_ROUTE_H typedef route_t RouteHandle; #endif #ifdef DNET_TUN_H typedef tun_t TunHandle; #endif #ifdef DNET_IP_H typedef ip_t IpHandle; #endif typedef struct intf_entry IntfEntry; typedef struct arp_entry ArpEntry; typedef struct fw_rule FwRule; typedef struct route_entry RouteEntry; #include "c/intf_entry.c" #include "c/arp_entry.c" #include "c/route_entry.c" #include "c/fw_rule.c" static SV * keepSub = (SV *)NULL; static int intf_callback(IntfEntry *entry, SV *data) { dSP; int ret; SV *e = intf_c2sv(entry); ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs(e); XPUSHs(data); PUTBACK; call_sv(keepSub, G_DISCARD); SPAGAIN; FREETMPS; LEAVE; return 0; } static int route_callback(RouteEntry *entry, SV *data) { dSP; int ret; SV *e = route_c2sv(entry); ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs(e); XPUSHs(data); //XPUSHs(sv_setref_pv(sv_newmortal(), "RouteEntryPtr", entry)); //XPUSHs(sv_setref_pv(sv_newmortal(), Nullch, data)); PUTBACK; call_sv(keepSub, G_DISCARD); SPAGAIN; //ret = POPi; FREETMPS; LEAVE; //return ret; return 0; } static int arp_callback(ArpEntry *entry, SV *data) { dSP; int ret; SV *e = arp_c2sv(entry); ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs(e); XPUSHs(data); PUTBACK; call_sv(keepSub, G_DISCARD); SPAGAIN; FREETMPS; LEAVE; return 0; } static int fw_callback(FwRule *rule, SV *data) { dSP; int ret; SV *e = fw_c2sv(rule); ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs(e); XPUSHs(data); PUTBACK; call_sv(keepSub, G_DISCARD); SPAGAIN; FREETMPS; LEAVE; return 0; } HV * intf2hash(struct intf_entry *IeInt){ HV *HvInt, *HvUndef; SV *SvData, *SvKey; char *StrAddr; /* prepare undefined hash */ HvUndef = newHV(); hv_undef(HvUndef); HvInt = newHV(); /* intf_len */ SvKey = newSVpv("len", 0); SvData = newSVnv((double) IeInt->intf_len); if( hv_store_ent(HvInt, SvKey, SvData, 0) == NULL ){ warn("intf2hash: error: intf_len\n"); return HvUndef; } /* intf_name */ SvKey = newSVpv("name", 0); SvData = newSVpv(IeInt->intf_name, 0); if( hv_store_ent(HvInt, SvKey, SvData, 0) == NULL ){ warn("intf2hash: error: int_name\n"); return HvUndef; } /* intf_type */ SvKey = newSVpv("type", 0); SvData = newSVnv((double) IeInt->intf_type); if( hv_store_ent(HvInt, SvKey, SvData, 0) == NULL ){ warn("intf2hash: error: intf_type\n"); return HvUndef; } /* intf_flags */ SvKey = newSVpv("flags", 0); SvData = newSVnv((double) IeInt->intf_flags); if( hv_store_ent(HvInt, SvKey, SvData, 0) == NULL ){ warn("intf2hash: error: intf_flags\n"); return HvUndef; } /* intf_mtu */ SvKey = newSVpv("mtu", 0); SvData = newSVnv((double) IeInt->intf_mtu); if( hv_store_ent(HvInt, SvKey, SvData, 0) == NULL ){ warn("intf2hash: error: intf_mtu\n"); return HvUndef; } /* intf_addr */ SvKey = newSVpv("addr", 0); /* does not allways exist */ StrAddr = addr_ntoa(&(IeInt->intf_addr)); if( StrAddr == NULL ){ SvData = &PL_sv_undef; }else{ SvData = newSVpv(addr_ntoa(&(IeInt->intf_addr)), 0); } if( hv_store_ent(HvInt, SvKey, SvData, 0) == NULL ){ warn("intf2hash: error: intf_addr\n"); return HvUndef; } /* intf_dst_addr */ SvKey = newSVpv("dst_addr", 0); /* does not allways exist */ StrAddr = addr_ntoa(&(IeInt->intf_dst_addr)); if( StrAddr == NULL ){ SvData = &PL_sv_undef; }else{ SvData = newSVpv(addr_ntoa(&(IeInt->intf_dst_addr)), 0); } if( hv_store_ent(HvInt, SvKey, SvData, 0) == NULL ){ warn("intf2hash: error: intf_dst_addr\n"); return HvUndef; } /* intf_link_addr */ SvKey = newSVpv("link_addr", 0); /* does not allways exist */ StrAddr = addr_ntoa(&(IeInt->intf_link_addr)); if( StrAddr == NULL ){ SvData = &PL_sv_undef; }else{ SvData = newSVpv(addr_ntoa(&(IeInt->intf_link_addr)), 0); } if( hv_store_ent(HvInt, SvKey, SvData, 0) == NULL ){ warn("intf2hash: error: intf_link_addr\n"); return HvUndef; } /* XXX skipped the aliases problematic */ return HvInt; } MODULE = Net::Libdnet PACKAGE = Net::Libdnet PROTOTYPES: DISABLE # # The following are obsolete functions, but stills there for compatibility reasons # SV * _obsolete_addr_cmp(SvA, SvB) SV *SvA; SV *SvB; PROTOTYPE: $$ CODE: char *StrA, *StrB; struct addr SadA, SadB; int len; /* we cannot avoid ugly nesting, because return and goto are out of scope */ /* check input */ if( !SvOK(SvA) ){ warn("addr_cmp: undef input (1)\n"); RETVAL = &PL_sv_undef; }else if( !SvOK(SvB) ){ warn("addr_cmp: undef input (2)\n"); RETVAL = &PL_sv_undef; }else{ /* A: SV -> string */ StrA = (char *) SvPV(SvA, len); /* A: string -> struct addr */ if( addr_aton(StrA, &SadA) < 0 ){ warn("addr_cmp: addr_aton: error (1)\n"); RETVAL = &PL_sv_undef; }else{ /* B: SV -> string */ StrB = (char *) SvPV(SvB, len); /* B: string -> struct addr */ if( addr_aton(StrB, &SadB) < 0 ){ warn("addr_cmp: addr_aton: error (2)\n"); RETVAL = &PL_sv_undef; }else{ /* compute output */ RETVAL = newSVnv((double) addr_cmp(&SadA, &SadB)); } } } OUTPUT: RETVAL SV * _obsolete_addr_bcast(SvAd) SV *SvAd; PROTOTYPE: $ CODE: char *StrAd; struct addr SadAd, SadBc; int len; /* check input */ if( !SvOK(SvAd) ){ warn("addr_bcast: undef input\n"); RETVAL = &PL_sv_undef; }else{ /* address: SV -> string */ StrAd = (char *) SvPV(SvAd, len); /* address: string -> struct addr */ if( addr_aton(StrAd, &SadAd) < 0 ){ warn("addr_bcast: addr_aton: error\n"); RETVAL = &PL_sv_undef; /* compute output */ }else if( addr_bcast(&SadAd, &SadBc) < 0 ){ warn("addr_bcast: error\n"); RETVAL = &PL_sv_undef; }else{ /* broadcast: struct addr -> SV */ if( (StrAd = addr_ntoa((struct addr *) &SadBc)) == NULL){ warn("addr_bcast: addr_ntoa: error\n"); RETVAL = &PL_sv_undef; }else{ /* 0 means Perl does strlen() itself */ RETVAL = newSVpv(StrAd, 0); } } } OUTPUT: RETVAL SV * _obsolete_addr_net(SvAd) SV *SvAd; PROTOTYPE: $ CODE: char *StrAd; struct addr SadAd, SadBc; int len; /* check input */ if( !SvOK(SvAd) ){ warn("addr_net: undef input\n"); RETVAL = &PL_sv_undef; }else{ /* address: SV -> string */ StrAd = (char *) SvPV(SvAd, len); /* address: string -> struct addr */ if( addr_aton(StrAd, &SadAd) < 0 ){ warn("addr_net: addr_aton: error\n"); RETVAL = &PL_sv_undef; /* compute output */ }else if( addr_net(&SadAd, &SadBc) < 0 ){ warn("addr_net: error\n"); RETVAL = &PL_sv_undef; }else{ /* broadcast: struct addr -> SV */ if( (StrAd = addr_ntoa((struct addr *) &SadBc)) == NULL){ warn("addr_net: addr_ntoa: error\n"); RETVAL = &PL_sv_undef; }else{ /* 0 means Perl does strlen() itself */ RETVAL = newSVpv(StrAd, 0); } } } OUTPUT: RETVAL SV* _obsolete_arp_add(SvProtoAddr, SvHwAddr) SV *SvProtoAddr; SV *SvHwAddr; PROTOTYPE: $$ CODE: arp_t *AtArp; struct arp_entry SarEntry; struct addr SadAddr; char *StrAddr; int len; /* check input */ if( !SvOK(SvProtoAddr) ){ warn("arp_add: undef input(1)\n"); RETVAL = &PL_sv_undef; }else if( !SvOK(SvHwAddr) ){ warn("arp_add: undef input(2)\n"); RETVAL = &PL_sv_undef; }else{ /* open arp handler */ if( (AtArp = arp_open()) == NULL ){ warn("arp_add: arp_open: error\n"); RETVAL = &PL_sv_undef; }else{ /* protocol address: SV -> string */ StrAddr = (char *) SvPV(SvProtoAddr, len); /* protocol address: string -> struct addr */ if( addr_aton(StrAddr, &SadAddr) < 0 ){ warn("arp_add: addr_aton: error (1)\n"); RETVAL = &PL_sv_undef; }else{ /* protocol address -> arp_entry */ memcpy(&SarEntry.arp_pa, &SadAddr, sizeof(struct addr)); /* hardware address: SV -> string */ StrAddr = (char *) SvPV(SvHwAddr, len); /* hardware address: string -> struct addr */ if( addr_aton(StrAddr, &SadAddr) < 0 ){ warn("arp_add: addr_aton: error (2)\n"); RETVAL = &PL_sv_undef; }else{ memcpy(&SarEntry.arp_ha, &SadAddr, sizeof(struct addr)); /* add to ARP table */ if( arp_add(AtArp, &SarEntry) < 0 ){ warn("arp_add: error\n"); RETVAL = &PL_sv_undef; }else{ RETVAL = newSVnv(1); } } } /* close arp handler */ arp_close(AtArp); } } OUTPUT: RETVAL SV* _obsolete_arp_delete(SvProtoAddr) SV *SvProtoAddr; PROTOTYPE: $ CODE: arp_t *AtArp; struct arp_entry SarEntry; struct addr SadAddr; char *StrAddr; int len; /* check input */ if( !SvOK(SvProtoAddr) ){ warn("arp_delete: undef input\n"); RETVAL = &PL_sv_undef; }else{ /* open arp handler */ if( (AtArp = arp_open()) == NULL ){ warn("arp_get: arp_open: error\n"); RETVAL = &PL_sv_undef; }else{ /* convert input to string */ StrAddr = (char *) SvPV(SvProtoAddr, len); /* convert input to struct addr */ if( addr_aton(StrAddr, &SadAddr) < 0 ){ warn("arp_delete: addr_aton: error\n"); RETVAL = &PL_sv_undef; }else{ memcpy(&SarEntry.arp_pa, &SadAddr, sizeof(struct addr)); /* resolve protocol address with arp */ if( arp_delete(AtArp, &SarEntry) < 0 ){ /* do not warn: a request for a nonexistant address is valid */ RETVAL = &PL_sv_undef; }else{ RETVAL = newSVnv(1); } } /* close arp handler */ arp_close(AtArp); } } OUTPUT: RETVAL SV* _obsolete_arp_get(SvProtoAddr) SV *SvProtoAddr; PROTOTYPE: $ CODE: arp_t *AtArp; struct arp_entry SarEntry; struct addr SadAddr; char *StrAddr; int len; /* check input */ if( !SvOK(SvProtoAddr) ){ warn("arp_get: undef input\n"); RETVAL = &PL_sv_undef; }else{ /* open arp handler */ if( (AtArp = arp_open()) == NULL ){ warn("arp_get: arp_open: error\n"); RETVAL = &PL_sv_undef; }else{ /* convert input to string */ StrAddr = (char *) SvPV(SvProtoAddr, len); /* convert input to struct addr */ if( addr_aton(StrAddr, &SadAddr) < 0 ){ warn("arp_get: addr_aton: error\n"); RETVAL = &PL_sv_undef; }else{ memcpy(&SarEntry.arp_pa, &SadAddr, sizeof(struct addr)); /* resolve protocol address with arp */ if( arp_get(AtArp, &SarEntry) < 0 ){ /* do not warn: a request for a nonexistant address is valid */ RETVAL = &PL_sv_undef; }else{ /* convert output to string */ if( (StrAddr = addr_ntoa( (struct addr *) &SarEntry.arp_ha)) == NULL){ warn("arp_get: addr_ntoa: error\n"); RETVAL = &PL_sv_undef; }else{ /* 0 means Perl does strlen() itself */ RETVAL = newSVpv(StrAddr, 0); } } } /* close arp handler */ arp_close(AtArp); } } OUTPUT: RETVAL HV * _obsolete_intf_get(SvName) SV *SvName; PROTOTYPE: $ CODE: HV *HvUndef; intf_t *ItIntf; struct intf_entry SieEntry; char *StrName; int len; /* prepare undefined hash */ HvUndef = newHV(); hv_undef(HvUndef); /* check input */ if( !SvOK(SvName) ){ warn("intf_get: undef input\n"); RETVAL = HvUndef; }else{ /* open intf handler */ if( (ItIntf = intf_open()) == NULL ){ warn("intf_get: intf_open: error\n"); RETVAL = HvUndef; }else{ /* name: SV -> string */ StrName = (char *) SvPV(SvName, len); /* request interface */ SieEntry.intf_len = sizeof(SieEntry); strncpy(SieEntry.intf_name, StrName, INTF_NAME_LEN); if( intf_get(ItIntf, &SieEntry) < 0 ){ /* cannot warn, since the name may not exist */ RETVAL = HvUndef; }else{ RETVAL = intf2hash(&SieEntry); } /* close intf handler */ intf_close(ItIntf); } } OUTPUT: RETVAL HV * _obsolete_intf_get_src(SvAddr) SV *SvAddr; PROTOTYPE: $ CODE: HV *HvUndef; intf_t *ItIntf; struct intf_entry SieEntry; struct addr SaAddr; char *StrAddr; int len; /* prepare undefined hash */ HvUndef = newHV(); hv_undef(HvUndef); /* check input */ if( !SvOK(SvAddr) ){ warn("intf_get_src: undef input\n"); RETVAL = HvUndef; }else{ /* open intf handler */ if( (ItIntf = intf_open()) == NULL ){ warn("intf_get_src: intf_open: error\n"); RETVAL = HvUndef; }else{ /* addr: SV -> string */ StrAddr = (char *) SvPV(SvAddr, len); /* addr: string -> struct addr */ if( addr_aton(StrAddr, &SaAddr) < 0 ){ warn("intf_get_src: addr_aton: error\n"); RETVAL = HvUndef; }else{ /* request interface */ SieEntry.intf_len = sizeof(SieEntry); if( intf_get_src(ItIntf, &SieEntry, &SaAddr) < 0 ){ /* cannot warn, since the name may not exist */ RETVAL = HvUndef; }else{ RETVAL = intf2hash(&SieEntry); } } /* close intf handler */ intf_close(ItIntf); } } OUTPUT: RETVAL HV * _obsolete_intf_get_dst(SvAddr) SV *SvAddr; PROTOTYPE: $ CODE: HV *HvUndef; intf_t *ItIntf; struct intf_entry SieEntry; struct addr SaAddr; char *StrAddr; int len; /* prepare undefined hash */ HvUndef = newHV(); hv_undef(HvUndef); /* check input */ if( !SvOK(SvAddr) ){ warn("intf_get_dst: undef input\n"); RETVAL = HvUndef; }else{ /* open intf handler */ if( (ItIntf = intf_open()) == NULL ){ warn("intf_get_dst: intf_open: error\n"); RETVAL = HvUndef; }else{ /* addr: SV -> string */ StrAddr = (char *) SvPV(SvAddr, len); /* addr: string -> struct addr */ if( addr_aton(StrAddr, &SaAddr) < 0 ){ warn("intf_get_dst: addr_aton: error\n"); RETVAL = HvUndef; }else{ /* request interface */ SieEntry.intf_len = sizeof(SieEntry); if( intf_get_dst(ItIntf, &SieEntry, &SaAddr) < 0 ){ /* cannot warn, since the name may not exist */ RETVAL = HvUndef; }else{ RETVAL = intf2hash(&SieEntry); } } /* close intf handler */ intf_close(ItIntf); } } OUTPUT: RETVAL SV* _obsolete_route_add(SvDstAddr, SvGwAddr) SV *SvDstAddr; SV *SvGwAddr; PROTOTYPE: $$ CODE: route_t *RtRoute; struct route_entry SrtEntry; struct addr SadAddr; char *StrAddr; int len; /* check input */ if( !SvOK(SvDstAddr) ){ warn("route_add: undef input(1)\n"); RETVAL = &PL_sv_undef; }else if( !SvOK(SvGwAddr) ){ warn("route_add: undef input(2)\n"); RETVAL = &PL_sv_undef; }else{ /* open route handler */ if( (RtRoute = route_open()) == NULL ){ warn("route_add: route_open: error\n"); RETVAL = &PL_sv_undef; }else{ /* destination address: SV -> string */ StrAddr = (char *) SvPV(SvDstAddr, len); /* destination address: string -> struct addr */ if( addr_aton(StrAddr, &SadAddr) < 0 ){ warn("route_add: addr_aton: error (1)\n"); RETVAL = &PL_sv_undef; }else{ /* destination address -> route_entry */ memcpy(&SrtEntry.route_dst, &SadAddr, sizeof(struct addr)); /* gateway address: SV -> string */ StrAddr = (char *) SvPV(SvGwAddr, len); /* gateway address: string -> struct addr */ if( addr_aton(StrAddr, &SadAddr) < 0 ){ warn("route_add: addr_aton: error (2)\n"); RETVAL = &PL_sv_undef; }else{ memcpy(&SrtEntry.route_gw, &SadAddr, sizeof(struct addr)); /* add to route table */ if( route_add(RtRoute, &SrtEntry) < 0 ){ warn("route_add: error\n"); RETVAL = &PL_sv_undef; }else{ RETVAL = newSVnv(1); } } } /* close route handler */ route_close(RtRoute); } } OUTPUT: RETVAL SV* _obsolete_route_delete(SvDstAddr) SV *SvDstAddr; PROTOTYPE: $ CODE: route_t *RtRoute; struct route_entry SrtEntry; struct addr SadAddr; char *StrAddr; int len; /* check input */ if( !SvOK(SvDstAddr) ){ warn("route_delete: undef input\n"); RETVAL = &PL_sv_undef; }else{ /* open route handler */ if( (RtRoute = route_open()) == NULL ){ warn("route_get: route_open: error\n"); RETVAL = &PL_sv_undef; }else{ /* convert input to string */ StrAddr = (char *) SvPV(SvDstAddr, len); /* convert input to struct addr */ if( addr_aton(StrAddr, &SadAddr) < 0 ){ warn("route_delete: addr_aton: error\n"); RETVAL = &PL_sv_undef; }else{ memcpy(&SrtEntry.route_dst, &SadAddr, sizeof(struct addr)); /* remove route */ if( route_delete(RtRoute, &SrtEntry) < 0 ){ /* do not warn: a request for a nonexistant address is valid */ RETVAL = &PL_sv_undef; }else{ RETVAL = newSVnv(1); } } /* close route handler */ route_close(RtRoute); } } OUTPUT: RETVAL SV* _obsolete_route_get(SvDstAddr) SV *SvDstAddr; PROTOTYPE: $ CODE: route_t *RtRoute; struct route_entry SrtEntry; struct addr SadAddr; char *StrAddr; int len; /* check input */ if( !SvOK(SvDstAddr) ){ warn("route_get: undef input\n"); RETVAL = &PL_sv_undef; }else{ /* open route handler */ if( (RtRoute = route_open()) == NULL ){ warn("route_get: route_open: error\n"); RETVAL = &PL_sv_undef; }else{ /* convert input to string */ StrAddr = (char *) SvPV(SvDstAddr, len); /* convert input to struct addr */ if( addr_aton(StrAddr, &SadAddr) < 0 ){ warn("route_get: addr_aton: error\n"); RETVAL = &PL_sv_undef; }else{ memcpy(&SrtEntry.route_dst, &SadAddr, sizeof(struct addr)); /* resolve protocol address with route */ if( route_get(RtRoute, &SrtEntry) < 0 ){ /* do not warn: a request for a nonexistant address is valid */ RETVAL = &PL_sv_undef; }else{ /* convert output to string */ if( (StrAddr = addr_ntoa( (struct addr *) &SrtEntry.route_gw)) == NULL){ warn("route_get: addr_ntoa: error\n"); RETVAL = &PL_sv_undef; }else{ /* 0 means Perl does strlen() itself */ RETVAL = newSVpv(StrAddr, 0); } } } /* close route handler */ route_close(RtRoute); } } OUTPUT: RETVAL # # The following are the new XS implementation. # I prefixed with dnet_ in order to not clash with libdnet C functions used by # obsolete XS implementation. # #if defined DNET_INTF_H IntfHandle * dnet_intf_open() CODE: RETVAL = intf_open(); OUTPUT: RETVAL SV * dnet_intf_get(handle, entry) IntfHandle *handle SV *entry PREINIT: char buf[1024]; IntfEntry *intfEntry; IntfEntry *intfEntryPtr; INIT: intfEntry = (IntfEntry *)buf; intfEntryPtr = NULL; memset(buf, 0, sizeof(buf)); intfEntryPtr = intf_sv2c(entry, intfEntry); intfEntry->intf_len = sizeof(buf); CODE: if (intf_get(handle, intfEntryPtr) == -1) { XSRETURN_UNDEF; } else { RETVAL = intf_c2sv(intfEntry); } OUTPUT: RETVAL SV * dnet_intf_get_src(handle, src) IntfHandle *handle SV *src PREINIT: char buf[1024]; IntfEntry *intfEntry; struct addr aSrc; int ret; INIT: intfEntry = (IntfEntry *)buf; memset(buf, 0, sizeof(buf)); intfEntry->intf_len = sizeof(buf); memset(&aSrc, 0, sizeof(struct addr)); ret = addr_aton(SvPV(src, PL_na), &aSrc); CODE: if (! ret && intf_get_src(handle, intfEntry, &aSrc) == -1) { XSRETURN_UNDEF; } else { RETVAL = intf_c2sv(intfEntry); } OUTPUT: RETVAL SV * dnet_intf_get_dst(handle, dst) IntfHandle *handle SV *dst PREINIT: char buf[1024]; struct addr aDst; int ret; IntfEntry *intfEntry; INIT: intfEntry = (IntfEntry *)buf; memset(buf, 0, sizeof(buf)); intfEntry->intf_len = sizeof(buf); memset(&aDst, 0, sizeof(struct addr)); ret = addr_aton(SvPV(dst, PL_na), &aDst); CODE: if (! ret && intf_get_dst(handle, intfEntry, &aDst) == -1) { XSRETURN_UNDEF; } else { RETVAL = intf_c2sv(intfEntry); } OUTPUT: RETVAL int dnet_intf_set(handle, entry) IntfHandle *handle SV *entry PREINIT: IntfEntry *intfEntryPtr; IntfEntry intfEntry; INIT: intfEntryPtr = NULL; intfEntryPtr = intf_sv2c(entry, &intfEntry); CODE: if (intf_set(handle, &intfEntry) == -1) { XSRETURN_UNDEF; } else { RETVAL = 1; } OUTPUT: RETVAL int dnet_intf_loop(handle, callback, data) IntfHandle *handle SV *callback SV *data CODE: if (keepSub == (SV *)NULL) keepSub = newSVsv(callback); else SvSetSV(keepSub, callback); RETVAL = intf_loop(handle, (intf_handler)intf_callback, data); OUTPUT: RETVAL IntfHandle * dnet_intf_close(handle) IntfHandle *handle CODE: RETVAL = intf_close(handle); OUTPUT: RETVAL #endif #if defined DNET_ARP_H ArpHandle * dnet_arp_open() CODE: RETVAL = arp_open(); OUTPUT: RETVAL int dnet_arp_add(handle, entry) ArpHandle *handle SV *entry PREINIT: ArpEntry arpEntry; ArpEntry *arpEntryPtr; INIT: arpEntryPtr = NULL; arpEntryPtr = arp_sv2c(entry, &arpEntry); CODE: RETVAL = arp_add(handle, arpEntryPtr); if (RETVAL == -1) { XSRETURN_UNDEF; } else { RETVAL = 1; } OUTPUT: RETVAL int dnet_arp_delete(handle, entry) ArpHandle *handle SV *entry PREINIT: ArpEntry arpEntry; ArpEntry *arpEntryPtr; INIT: arpEntryPtr = NULL; arpEntryPtr = arp_sv2c(entry, &arpEntry); CODE: RETVAL = arp_delete(handle, arpEntryPtr); if (RETVAL == -1) { XSRETURN_UNDEF; } else { RETVAL = 1; } OUTPUT: RETVAL SV * dnet_arp_get(handle, entry) ArpHandle *handle SV *entry PREINIT: ArpEntry *arpEntryPtr; ArpEntry arpEntry; INIT: arpEntryPtr = NULL; arpEntryPtr = arp_sv2c(entry, &arpEntry); CODE: if (arp_get(handle, arpEntryPtr) == -1) { XSRETURN_UNDEF; } else { RETVAL = arp_c2sv(arpEntryPtr); } OUTPUT: RETVAL int dnet_arp_loop(handle, callback, data) ArpHandle *handle SV *callback SV *data CODE: if (keepSub == (SV *)NULL) keepSub = newSVsv(callback); else SvSetSV(keepSub, callback); RETVAL = arp_loop(handle, (arp_handler)arp_callback, data); OUTPUT: RETVAL ArpHandle * dnet_arp_close(handle) ArpHandle *handle CODE: RETVAL = arp_close(handle); OUTPUT: RETVAL #endif #if defined DNET_ROUTE_H RouteHandle * dnet_route_open() CODE: RETVAL = route_open(); OUTPUT: RETVAL int dnet_route_add(handle, entry) RouteHandle *handle SV *entry PREINIT: RouteEntry routeEntry; RouteEntry *routeEntryPtr; INIT: routeEntryPtr = NULL; routeEntryPtr = route_sv2c(entry, &routeEntry); CODE: RETVAL = route_add(handle, routeEntryPtr); if (RETVAL == -1) { XSRETURN_UNDEF; } else { RETVAL = 1; } OUTPUT: RETVAL int dnet_route_delete(handle, entry) RouteHandle *handle SV *entry PREINIT: RouteEntry routeEntry; RouteEntry *routeEntryPtr; INIT: routeEntryPtr = NULL; routeEntryPtr = route_sv2c(entry, &routeEntry); CODE: RETVAL = route_delete(handle, routeEntryPtr); if (RETVAL == -1) { XSRETURN_UNDEF; } else { RETVAL = 1; } OUTPUT: RETVAL SV * dnet_route_get(handle, entry) RouteHandle *handle SV *entry PREINIT: RouteEntry routeEntry; RouteEntry *routeEntryPtr; INIT: routeEntryPtr = NULL; routeEntryPtr = route_sv2c(entry, &routeEntry); CODE: if (route_get(handle, routeEntryPtr) == -1) { XSRETURN_UNDEF; } else { RETVAL = route_c2sv(routeEntryPtr); } OUTPUT: RETVAL int dnet_route_loop(handle, callback, data) RouteHandle *handle SV *callback SV *data CODE: if (keepSub == (SV *)NULL) keepSub = newSVsv(callback); else SvSetSV(keepSub, callback); RETVAL = route_loop(handle, (route_handler)route_callback, data); //printf("RETVAL: %d\n", RETVAL); OUTPUT: RETVAL RouteHandle * dnet_route_close(handle) RouteHandle *handle CODE: RETVAL = route_close(handle); OUTPUT: RETVAL #endif #if defined DNET_FW_H FwHandle * dnet_fw_open() CODE: RETVAL = fw_open(); OUTPUT: RETVAL int dnet_fw_add(handle, rule) FwHandle *handle SV *rule PREINIT: FwRule fwRule; FwRule *fwRulePtr; INIT: fwRulePtr = NULL; fwRulePtr = fw_sv2c(rule, &fwRule); CODE: RETVAL = fw_add(handle, fwRulePtr); if (RETVAL == -1) { XSRETURN_UNDEF; } else { RETVAL = 1; } OUTPUT: RETVAL int dnet_fw_delete(handle, rule) FwHandle *handle SV *rule PREINIT: FwRule fwRule; FwRule *fwRulePtr; INIT: fwRulePtr = NULL; fwRulePtr = fw_sv2c(rule, &fwRule); CODE: RETVAL = fw_delete(handle, fwRulePtr); if (RETVAL == -1) { XSRETURN_UNDEF; } else { RETVAL = 1; } OUTPUT: RETVAL int dnet_fw_loop(handle, callback, data) FwHandle *handle SV *callback SV *data CODE: if (keepSub == (SV *)NULL) keepSub = newSVsv(callback); else SvSetSV(keepSub, callback); RETVAL = fw_loop(handle, (fw_handler)fw_callback, data); OUTPUT: RETVAL FwHandle * dnet_fw_close(handle) FwHandle *handle CODE: RETVAL = fw_close(handle); OUTPUT: RETVAL #endif #if defined DNET_TUN_H TunHandle * dnet_tun_open(src, dst, size) SV *src SV *dst int size INIT: struct addr aSrc; struct addr aDst; memset(&aSrc, 0, sizeof(struct addr)); memset(&aDst, 0, sizeof(struct addr)); CODE: if (addr_aton(SvPV(src, PL_na), &aSrc)) { XSRETURN_UNDEF; } if (addr_aton(SvPV(dst, PL_na), &aDst)) { XSRETURN_UNDEF; } RETVAL = tun_open(&aSrc, &aDst, size); OUTPUT: RETVAL int dnet_tun_fileno(handle) TunHandle *handle CODE: RETVAL = tun_fileno(handle); if (RETVAL == -1) { XSRETURN_UNDEF; } OUTPUT: RETVAL const char * dnet_tun_name(handle) TunHandle *handle CODE: RETVAL = tun_name(handle); if (RETVAL == NULL) { XSRETURN_UNDEF; } OUTPUT: RETVAL int dnet_tun_send(handle, buf, size) TunHandle *handle SV *buf int size CODE: RETVAL = tun_send(handle, SvPV(buf, PL_na), size); if (RETVAL == -1) { XSRETURN_UNDEF; } OUTPUT: RETVAL SV * dnet_tun_recv(handle, size) TunHandle *handle int size PREINIT: int read; unsigned char buf[size+1]; INIT: memset(buf, 0, size+1); CODE: if ((read = tun_recv(handle, buf, size)) > 0) { RETVAL = newSVpv(buf, read); } else { XSRETURN_UNDEF; } OUTPUT: RETVAL TunHandle * dnet_tun_close(handle) TunHandle *handle CODE: RETVAL = tun_close(handle); OUTPUT: RETVAL #endif #if defined DNET_ETH_H EthHandle * dnet_eth_open(device) SV *device CODE: RETVAL = eth_open(SvPV(device, PL_na)); OUTPUT: RETVAL SV * dnet_eth_get(handle) EthHandle *handle PREINIT: char *addr; EthAddr a; INIT: memset(&a, 0, sizeof(EthAddr)); CODE: if (eth_get(handle, &a) == -1) { XSRETURN_UNDEF; } if ((addr = eth_ntoa(&a)) == NULL) { XSRETURN_UNDEF; } else { RETVAL = newSVpv(addr, 0); } OUTPUT: RETVAL int dnet_eth_set(handle, addr) EthHandle *handle SV *addr CODE: RETVAL = eth_set(handle, (const EthAddr *)SvPV(addr, PL_na)); if (RETVAL == -1) { XSRETURN_UNDEF; } OUTPUT: RETVAL int dnet_eth_send(handle, buf, size) EthHandle *handle SV *buf int size CODE: RETVAL = eth_send(handle, SvPV(buf, PL_na), size); if (RETVAL == -1) { XSRETURN_UNDEF; } OUTPUT: RETVAL EthHandle * dnet_eth_close(handle) EthHandle *handle CODE: RETVAL = eth_close(handle); OUTPUT: RETVAL #endif #if defined DNET_IP_H IpHandle * dnet_ip_open() CODE: RETVAL = ip_open(); OUTPUT: RETVAL int dnet_ip_send(handle, buf, size) IpHandle *handle SV *buf int size CODE: RETVAL = ip_send(handle, SvPV(buf, PL_na), size); if (RETVAL == -1) { XSRETURN_UNDEF; } OUTPUT: RETVAL void dnet_ip_checksum(buf, size) SV *buf int size CODE: ip_checksum(SvPV(buf, PL_na), size); IpHandle * dnet_ip_close(handle) IpHandle *handle CODE: RETVAL = ip_close(handle); OUTPUT: RETVAL #endif Net-Libdnet-0.99/ubuntu-old.patch0000644000175000017500000000463313350210754015735 0ustar gomorgomorIndex: Makefile.PL =================================================================== --- Makefile.PL (revision 42) +++ Makefile.PL (working copy) @@ -3,10 +3,10 @@ # use ExtUtils::MakeMaker; -my $libs = qx{dnet-config --libs 2>/dev/null} - || ['-L/lib -L/usr/lib -L/usr/local/lib -ldnet']; +my $libs = qx{dumbnet-config --libs 2>/dev/null} + || ['-L/lib -L/usr/lib -L/usr/local/lib -ldumbnet']; -my $inc = qx{dnet-config --cflags 2>/dev/null} +my $inc = qx{dumbnet-config --cflags 2>/dev/null} || '-I/include -I/usr/include -I/usr/local/include'; WriteMakefile( Index: Libdnet.xs =================================================================== --- Libdnet.xs (revision 42) +++ Libdnet.xs (working copy) @@ -34,38 +34,38 @@ #include "XSUB.h" #include -#include +#include -#ifdef DNET_BLOB_H +#ifdef DUMBNET_BLOB_H typedef blob_t Blob; #endif -#ifdef DNET_ETH_H +#ifdef DUMBNET_ETH_H typedef eth_t EthHandle; typedef eth_addr_t EthAddr; #endif -#ifdef DNET_INTF_H +#ifdef DUMBNET_INTF_H typedef intf_t IntfHandle; #endif -#ifdef DNET_ARP_H +#ifdef DUMBNET_ARP_H typedef arp_t ArpHandle; #endif -#ifdef DNET_FW_H +#ifdef DUMBNET_FW_H typedef fw_t FwHandle; #endif -#ifdef DNET_ROUTE_H +#ifdef DUMBNET_ROUTE_H typedef route_t RouteHandle; #endif -#ifdef DNET_TUN_H +#ifdef DUMBNET_TUN_H typedef tun_t TunHandle; #endif -#ifdef DNET_IP_H +#ifdef DUMBNET_IP_H typedef ip_t IpHandle; #endif @@ -866,7 +866,7 @@ # obsolete XS implementation. # -#if defined DNET_INTF_H +#if defined DUMBNET_INTF_H IntfHandle * dnet_intf_open() @@ -981,7 +981,7 @@ #endif -#if defined DNET_ARP_H +#if defined DUMBNET_ARP_H ArpHandle * dnet_arp_open() @@ -1064,7 +1064,7 @@ #endif -#if defined DNET_ROUTE_H +#if defined DUMBNET_ROUTE_H RouteHandle * dnet_route_open() @@ -1148,7 +1148,7 @@ #endif -#if defined DNET_FW_H +#if defined DUMBNET_FW_H FwHandle * dnet_fw_open() @@ -1215,7 +1215,7 @@ #endif -#if defined DNET_TUN_H +#if defined DUMBNET_TUN_H TunHandle * dnet_tun_open(src, dst, size) @@ -1290,7 +1290,7 @@ #endif -#if defined DNET_ETH_H +#if defined DUMBNET_ETH_H EthHandle * dnet_eth_open(device) @@ -1346,7 +1346,7 @@ #endif -#if defined DNET_IP_H +#if defined DUMBNET_IP_H IpHandle * dnet_ip_open() Net-Libdnet-0.99/META.json0000644000175000017500000000171213350211717014232 0ustar gomorgomor{ "abstract" : "binding for Dug Song's libdnet", "author" : [ "GomoR " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010", "license" : [ "bsd" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Net-Libdnet", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Class::Gomor" : "0", "perl" : "5.006001" } } }, "release_status" : "stable", "version" : "0.99", "x_serialization_backend" : "JSON::PP version 2.27400_02" } Net-Libdnet-0.99/LICENSE0000644000175000017500000000240613350210754013617 0ustar gomorgomor$Id$ Copyright (c) 2004 Vlad Manilici Copyright (c) 2008-2009 Patrice Auffret Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Net-Libdnet-0.99/Changes0000644000175000017500000000337213350211675014113 0ustar gomorgomorRevision history for Perl extension Net::Libdnet. 0.99 Tue 18 Sep 17:03:16 CEST 2018 - bugfix: applied https://rt.cpan.org/Public/Bug/Display.html?id=126967 0.98 Thu Nov 22 20:20:57 CET 2012 - bugfix: applied https://rt.cpan.org/Public/Bug/Display.html?id=72729 0.97 Fri Nov 2 17:39:36 CET 2012 - update: removed support for Libdnet6 checking code - update: copyright notice 0.96 Wed Nov 16 23:07:38 CET 2011 - bugfix: default to be compiled against libdnet (and not libdumbnet) - update: added some die() in example programs 0.95 Sun Mar 13 23:47:10 CET 2011 - new: added ubuntu and standard patchs. See README. 0.94 Fri Jan 14 11:09:49 CET 2011 - bugfix: tohash method in pod - applied http://rt.cpan.org/Public/Bug/Display.html?id=52359 0.93 Thu Jan 13 11:07:07 CET 2011 - update: makes components more inline with local install of libdnet - update: copyright notice 0.92 Wed May 13 20:59:41 CEST 2009 - applied http://rt.cpan.org/Ticket/Display.html?id=43899 - applied http://rt.cpan.org/Ticket/Display.html?id=45697 - copyright notice update 0.91 Sun Dec 7 19:15:43 CET 2008 - new: Net::Libdnet::Intf methods now return a Net::Libdnet::Entry::Intf object - new: Net::Libdnet::Intf now also has getSrcIntfFromDst(), getSrcIpFromDst() - update: constants renamed to be prefixed with DNET_ 0.90 Tue Nov 25 22:44:42 CET 2008 - complete rewrite of XS code - near full implementation of libdnet API - two APIs: a low-level and a high-level object oriented one - backward compatibility should remain 0.02 Tue Nov 25 20:59:27 CET 2008 - ownership transfered to me - updated copyright notices - still uses a BSD license 0.01 Wed Jul 7 21:11:29 2004 Original version Tested on FreeBSD 5.2.1 Net-Libdnet-0.99/Makefile.PL0000644000175000017500000000132513350210754014563 0ustar gomorgomor# # $Id: Makefile.PL,v 09f6d620bca4 2012/11/02 16:39:39 gomor $ # use ExtUtils::MakeMaker; my $libs = qx{dnet-config --libs 2>/dev/null} || ['-L/lib -L/usr/lib -L/usr/local/lib -ldnet']; my $inc = qx{dnet-config --cflags 2>/dev/null} || '-I/include -I/usr/include -I/usr/local/include'; WriteMakefile( NAME => 'Net::Libdnet', VERSION_FROM => 'lib/Net/Libdnet.pm', LICENSE => 'bsd', ABSTRACT_FROM => 'lib/Net/Libdnet.pm', AUTHOR => 'GomoR ', LIBS => $libs, INC => $inc, DEFINE => '', EXE_FILES => [ @{[glob('bin/*.pl')]} ], PREREQ_PM => { Class::Gomor => 0, }, MIN_PERL_VERSION => '5.6.1', ); Net-Libdnet-0.99/standard-new.patch0000644000175000017500000000156313350210754016225 0ustar gomorgomorIndex: Libdnet.xs =================================================================== --- Libdnet.xs (revision 41) +++ Libdnet.xs (working copy) @@ -34,7 +34,7 @@ #include "XSUB.h" #include -#include +#include #ifdef DNET_BLOB_H typedef blob_t Blob; Index: Makefile.PL =================================================================== --- Makefile.PL (revision 41) +++ Makefile.PL (working copy) @@ -3,10 +3,10 @@ # use ExtUtils::MakeMaker; -my $libs = qx{dumbnet-config --libs 2>/dev/null} - || ['-L/lib -L/usr/lib -L/usr/local/lib -ldumbnet']; +my $libs = qx{dnet-config --libs 2>/dev/null} + || ['-L/lib -L/usr/lib -L/usr/local/lib -ldnet']; -my $inc = qx{dumbnet-config --cflags 2>/dev/null} +my $inc = qx{dnet-config --cflags 2>/dev/null} || '-I/include -I/usr/include -I/usr/local/include'; WriteMakefile( Net-Libdnet-0.99/c/0000755000175000017500000000000013350211717013032 5ustar gomorgomorNet-Libdnet-0.99/c/intf_entry.c0000644000175000017500000001224313350210754015361 0ustar gomorgomor/* $Id$ */ /* * Copyright (c) 2008-2012 Patrice Auffret * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ SV * intf_c2sv(IntfEntry *entry) { HV *out = newHV(); SV *out_ref = newRV_noinc((SV *)out); char *sAddr, *sDstAddr, *sLnkAddr; hv_store(out, "intf_len", 8, newSViv(entry->intf_len), 0); hv_store(out, "intf_name", 9, newSVpv(entry->intf_name, 0), 0); hv_store(out, "intf_type", 9, newSViv(entry->intf_type), 0); hv_store(out, "intf_flags", 10, newSViv(entry->intf_flags), 0); hv_store(out, "intf_mtu", 8, newSViv(entry->intf_mtu), 0); sAddr = addr_ntoa(&(entry->intf_addr)); if (sAddr == NULL) { hv_store(out, "intf_addr", 9, &PL_sv_undef, 0); } else { hv_store(out, "intf_addr", 9, newSVpv(sAddr, 0), 0); } sDstAddr = addr_ntoa(&(entry->intf_dst_addr)); if (sDstAddr == NULL) { hv_store(out, "intf_dst_addr", 13, &PL_sv_undef, 0); } else { hv_store(out, "intf_dst_addr", 13, newSVpv(sDstAddr, 0), 0); } sLnkAddr = addr_ntoa(&(entry->intf_link_addr)); if (sLnkAddr == NULL) { hv_store(out, "intf_link_addr", 14, &PL_sv_undef, 0); } else { hv_store(out, "intf_link_addr", 14, newSVpv(sLnkAddr, 0), 0); } hv_store(out, "intf_alias_num", 14, newSViv(entry->intf_alias_num), 0); if (entry->intf_alias_num > 0) { int i; AV *aliases = newAV(); SV *aliases_ref = newRV_noinc((SV *)aliases); for (i=0; iintf_alias_num; i++) { char *alias = addr_ntoa(&(entry->intf_alias_addrs[i])); if (alias != NULL) { av_push(aliases, newSVpv(alias, 0)); } } hv_store(out, "intf_alias_addrs", 16, aliases_ref, 0); } else { hv_store(out, "intf_alias_addrs", 16, newRV_noinc((SV *)newAV()), 0); } return out_ref; } static IntfEntry * intf_sv2c(SV *h, IntfEntry *ref) { if (ref && h && SvROK(h)) { HV *hv = (HV *)SvRV(h); memset(ref, 0, sizeof(IntfEntry)); if (hv_exists(hv, "intf_len", 8)) { SV **len = hv_fetch((HV *)SvRV(h), "intf_len", 8, 0); ref->intf_len = (SvOK(*len) ? SvIV(*len) : 0); } if (hv_exists(hv, "intf_name", 9)) { SV **name = hv_fetch((HV *)SvRV(h), "intf_name", 9, 0); if (SvOK(*name)) { memcpy(&(ref->intf_name), SvPV(*name, PL_na), sizeof(ref->intf_name)); } } if (hv_exists(hv, "intf_type", 9)) { SV **type = hv_fetch((HV *)SvRV(h), "intf_type", 9, 0); ref->intf_type = (SvOK(*type) ? SvIV(*type) : 0); } if (hv_exists(hv, "intf_flags", 10)) { SV **flags = hv_fetch((HV *)SvRV(h), "intf_flags", 10, 0); ref->intf_flags = (SvOK(*flags) ? SvIV(*flags) : 0); } if (hv_exists(hv, "intf_mtu", 8)) { SV **mtu = hv_fetch((HV *)SvRV(h), "intf_mtu", 8, 0); ref->intf_mtu = (SvOK(*mtu) ? SvIV(*mtu) : 0); } if (hv_exists(hv, "intf_addr", 9)) { SV **addr = hv_fetch((HV *)SvRV(h), "intf_addr", 9, 0); if (SvOK(*addr)) { struct addr a; if (addr_aton(SvPV(*addr, PL_na), &a) == 0) { memcpy(&(ref->intf_addr), &a, sizeof(struct addr)); } } } if (hv_exists(hv, "intf_dst_addr", 13)) { SV **dstAddr = hv_fetch((HV *)SvRV(h), "intf_dst_addr", 13, 0); if (SvOK(*dstAddr)) { struct addr a; if (addr_aton(SvPV(*dstAddr, PL_na), &a) == 0) { memcpy(&(ref->intf_dst_addr), &a, sizeof(struct addr)); } } } if (hv_exists(hv, "intf_link_addr", 14)) { SV **lnkAddr = hv_fetch((HV *)SvRV(h), "intf_link_addr", 14, 0); if (SvOK(*lnkAddr)) { struct addr a; if (addr_aton(SvPV(*lnkAddr, PL_na), &a) == 0) { memcpy(&(ref->intf_link_addr), &a, sizeof(struct addr)); } } } } else { ref = NULL; } // XXX: put aliases also return ref; } Net-Libdnet-0.99/c/arp_entry.c0000644000175000017500000000505713350210754015210 0ustar gomorgomor/* $Id$ */ /* * Copyright (c) 2008-2012 Patrice Auffret * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ SV * arp_c2sv(ArpEntry *entry) { HV *out = newHV(); SV *out_ref = newRV_noinc((SV *)out); char *pa, *ha; pa = addr_ntoa(&(entry->arp_pa)); if (pa == NULL) { hv_store(out, "arp_pa", 6, &PL_sv_undef, 0); } else { hv_store(out, "arp_pa", 6, newSVpv(pa, 0), 0); } ha = addr_ntoa(&(entry->arp_ha)); if (ha == NULL) { hv_store(out, "arp_ha", 6, &PL_sv_undef, 0); } else { hv_store(out, "arp_ha", 6, newSVpv(ha, 0), 0); } return out_ref; } static ArpEntry * arp_sv2c(SV *h, ArpEntry *ref) { if (ref && h && SvROK(h)) { HV *hv = (HV *)SvRV(h); memset(ref, 0, sizeof(ArpEntry)); if (hv_exists(hv, "arp_pa", 6)) { SV **pa = hv_fetch(hv, "arp_pa", 6, 0); if (SvOK(*pa)) { struct addr a; if (addr_aton(SvPV(*pa, PL_na), &a) == 0) { memcpy(&(ref->arp_pa), &a, sizeof(struct addr)); } } } if (hv_exists(hv, "arp_ha", 6)) { SV **ha = hv_fetch(hv, "arp_ha", 6, 0); if (SvOK(*ha)) { struct addr a; if (addr_aton(SvPV(*ha, PL_na), &a) == 0) { memcpy(&(ref->arp_ha), &a, sizeof(struct addr)); } } } } return ref; } Net-Libdnet-0.99/c/fw_rule.c0000644000175000017500000001072613350210754014647 0ustar gomorgomor/* $Id$ */ /* * Copyright (c) 2008-2012 Patrice Auffret * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ SV * fw_c2sv(FwRule *rule) { HV *out = newHV(); SV *out_ref = newRV_noinc((SV *)out); AV *sport, *dport; char *src, *dst; int i; hv_store(out, "fw_device", 9, newSVpv(rule->fw_device, 0), 0); hv_store(out, "fw_op", 5, newSViv(rule->fw_op), 0); hv_store(out, "fw_dir", 6, newSViv(rule->fw_dir), 0); hv_store(out, "fw_proto", 8, newSViv(rule->fw_proto), 0); src = addr_ntoa(&(rule->fw_src)); if (src == NULL) { hv_store(out, "fw_src", 6, &PL_sv_undef, 0); } else { hv_store(out, "fw_src", 6, newSVpv(src, 0), 0); } dst = addr_ntoa(&(rule->fw_dst)); if (dst == NULL) { hv_store(out, "fw_dst", 6, &PL_sv_undef, 0); } else { hv_store(out, "fw_dst", 6, newSVpv(dst, 0), 0); } sport = newAV(); dport = newAV(); for (i=0; i<2; i++) { av_push(sport, newSViv(rule->fw_sport[i])); av_push(dport, newSViv(rule->fw_dport[i])); } hv_store(out, "fw_sport", 8, newRV_noinc((SV *)sport), 0); hv_store(out, "fw_dport", 8, newRV_noinc((SV *)dport), 0); return out_ref; } static FwRule * fw_sv2c(SV *h, FwRule *ref) { if (ref && h && SvROK(h)) { HV *hv = (HV *)SvRV(h); memset(ref, 0, sizeof(FwRule)); if (hv_exists(hv, "fw_device", 9)) { SV **r = hv_fetch(hv, "fw_device", 9, 0); if (SvOK(*r)) { memcpy(&(ref->fw_device), SvPV(*r, PL_na), sizeof(ref->fw_device)); } } if (hv_exists(hv, "fw_op", 5)) { SV **r = hv_fetch(hv, "fw_op", 5, 0); ref->fw_op = (SvOK(*r) ? SvIV(*r) : 0); } if (hv_exists(hv, "fw_dir", 6)) { SV **r = hv_fetch(hv, "fw_dir", 6, 0); ref->fw_dir = (SvOK(*r) ? SvIV(*r) : 0); } if (hv_exists(hv, "fw_proto", 8)) { SV **r = hv_fetch(hv, "fw_proto", 8, 0); ref->fw_proto = (SvOK(*r) ? SvIV(*r) : 0); } if (hv_exists(hv, "fw_src", 6)) { SV **r = hv_fetch(hv, "fw_src", 6, 0); if (SvOK(*r)) { struct addr a; if (addr_aton(SvPV(*r, PL_na), &a) == 0) { memcpy(&(ref->fw_src), &a, sizeof(struct addr)); } } } if (hv_exists(hv, "fw_dst", 6)) { SV **r = hv_fetch(hv, "fw_dst", 6, 0); if (SvOK(*r)) { struct addr a; if (addr_aton(SvPV(*r, PL_na), &a) == 0) { memcpy(&(ref->fw_dst), &a, sizeof(struct addr)); } } } if (hv_exists(hv, "fw_sport", 8)) { SV **r = hv_fetch(hv, "fw_sport", 8, 0); if (SvOK(*r)) { AV *a = (AV *)SvRV(*r); SV *p1 = av_shift(a); SV *p2 = av_shift(a); ref->fw_sport[0] = (SvOK(p1) ? SvIV(p1) : 0); ref->fw_sport[1] = (SvOK(p2) ? SvIV(p2) : 0); } } if (hv_exists(hv, "fw_dport", 8)) { SV **r = hv_fetch(hv, "fw_dport", 8, 0); if (SvOK(*r)) { AV *a = (AV *)SvRV(*r); SV *p1 = av_shift(a); SV *p2 = av_shift(a); ref->fw_dport[0] = (SvOK(p1) ? SvIV(p1) : 0); ref->fw_dport[1] = (SvOK(p2) ? SvIV(p2) : 0); } } } else { ref = NULL; } return ref; } Net-Libdnet-0.99/c/route_entry.c0000644000175000017500000000517213350210754015562 0ustar gomorgomor/* $Id$ */ /* * Copyright (c) 2008-2012 Patrice Auffret * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ SV * route_c2sv(RouteEntry *entry) { HV *out = newHV(); SV *out_ref = newRV_noinc((SV *)out); char *dst, *gw; if (entry != NULL) { dst = addr_ntoa(&(entry->route_dst)); dst == NULL ? hv_store(out, "route_dst", 9, &PL_sv_undef, 0) : hv_store(out, "route_dst", 9, newSVpv(dst, 0), 0); gw = addr_ntoa(&(entry->route_gw)); gw == NULL ? hv_store(out, "route_gw", 8, &PL_sv_undef, 0) : hv_store(out, "route_gw", 8, newSVpv(gw, 0), 0); } return out_ref; } static RouteEntry * route_sv2c(SV *h, RouteEntry *ref) { if (ref && h && SvROK(h)) { HV *hv = (HV *)SvRV(h); memset(ref, 0, sizeof(RouteEntry)); if (hv_exists(hv, "route_dst", 9)) { SV **r = hv_fetch(hv, "route_dst", 9, 0); if (SvOK(*r)) { struct addr a; if (addr_aton(SvPV(*r, PL_na), &a) == 0) { memcpy(&(ref->route_dst), &a, sizeof(struct addr)); } } } if (hv_exists(hv, "route_gw", 8)) { SV **r = hv_fetch(hv, "route_gw", 8, 0); if (SvOK(*r)) { struct addr a; if (addr_aton(SvPV(*r, PL_na), &a) == 0) { memcpy(&(ref->route_gw), &a, sizeof(struct addr)); } } } } else { ref = NULL; } return ref; } Net-Libdnet-0.99/bin/0000755000175000017500000000000013350211717013360 5ustar gomorgomorNet-Libdnet-0.99/bin/dnet.pl0000644000175000017500000001024713350210754014653 0ustar gomorgomor#!/usr/bin/perl # # $Id: dnet.pl,v 5ae6e0a9ef87 2008/12/06 17:06:25 gomor $ # use strict; use warnings; my $opt = shift || die("Usage"); my $cmd = shift || die("Usage"); my $arg = "@ARGV"; use Net::Libdnet qw(:consts); if ($opt =~ /intf/i) { intf_opt ($cmd, $arg) } elsif ($opt =~ /route/i) { route_opt($cmd, $arg) } elsif ($opt =~ /arp/i) { arp_opt ($cmd, $arg) } elsif ($opt =~ /fw/i) { fw_opt ($cmd, $arg) } elsif ($opt =~ /ip/i) { ip_opt ($cmd, $arg) } elsif ($opt =~ /eth/i) { eth_opt ($cmd, $arg) } #else { print_usage() } # # intf option handling # sub intf_opt { my ($cmd) = @_; use Net::Libdnet::Intf; my $h = Net::Libdnet::Intf->new; if ($cmd =~ /show/i) { $h->loop(\&intf_print); } elsif ($cmd =~ /get/i) { my $e = $h->get($arg); $e && intf_print($e); } elsif ($cmd =~ /set/i) { my $s = $h->set($arg); print $s ? "Success\n" : "Failed\n"; } elsif ($cmd =~ /src/i) { my $e = $h->getSrc($arg); $e && intf_print($e); } elsif ($cmd =~ /dst/i) { my $e = $h->getDst($arg); $e && intf_print($e); } #else { #intf_usage(); #} } sub intf_print { my ($e, $data) = @_; if (ref($e) eq 'HASH') { use Net::Libdnet::Entry::Intf; $e = Net::Libdnet::Entry::Intf->newFromHash($e); } print $e->print."\n"; } # # route handling # sub route_opt { my ($cmd) = @_; use Net::Libdnet::Route; my $h = Net::Libdnet::Route->new; if ($cmd =~ /show/i) { printf("%-30s %-30s\n", "Destination", "Gateway"); $h->loop(\&route_print); } elsif ($cmd =~ /get/i) { my $e = $h->get($arg); print $e ? "Gateway: $e\n" : "Same subnet\n"; } elsif ($cmd =~ /add/i) { my $s = $h->add(split(/ +/, $arg)); print $s ? "Success\n" : "Failed\n"; } elsif ($cmd =~ /delete/i) { my $s = $h->delete(split(/ +/, $arg)); print $s ? "Success\n" : "Failed\n"; } #else { #route_usage(); #} } sub route_print { my ($e, $data) = @_; printf("%-30s %-30s\n", $e->{route_dst}, $e->{route_gw}); } # # arp handling # sub arp_opt { my ($cmd) = @_; use Net::Libdnet::Arp; my $h = Net::Libdnet::Arp->new; if ($cmd =~ /show/i) { $h->loop(\&arp_print); } elsif ($cmd =~ /get/i) { my $e = $h->get($arg); print $e ? "link: $e\n" : "No link found\n"; } elsif ($cmd =~ /add/i) { my $s = $h->add(split(/ +/, $arg)); print $s ? "Success\n" : "Failed\n"; } elsif ($cmd =~ /delete/i) { my $s = $h->delete(split(/ +/, $arg)); print $s ? "Success\n" : "Failed\n"; } #else { #arp_usage(); #} } sub arp_print { my ($e, $data) = @_; printf("%s at %s\n", $e->{arp_pa}, $e->{arp_ha}); } # # fw handling # sub fw_opt { my ($cmd) = @_; use Net::Libdnet::Fw; my $h = Net::Libdnet::Fw->new; if ($cmd =~ /show/i) { $h->loop(\&fw_print); } elsif ($cmd =~ /add/i) { my $s = $h->add($arg); print $s ? "Success\n" : "Failed\n"; } elsif ($cmd =~ /delete/i) { my $s = $h->delete($arg); print $s ? "Success\n" : "Failed\n"; } #else { #fw_usage(); #} } sub fw_print { my ($e, $data) = @_; my $device = $e->{fw_device}; my $op = $e->{fw_op}; my $dir = $e->{fw_dir}; my $proto = $e->{fw_proto}; my $src = $e->{fw_src}; my $dst = $e->{fw_dst}; my $sport = $e->{fw_sport}; my $dport = $e->{fw_dport}; if ($op == DNET_FW_OP_ALLOW) { $op = "allow" } elsif ($op == DNET_FW_OP_BLOCK) { $op = "block" } if ($dir == DNET_FW_DIR_IN) { $dir = "in" } elsif ($dir == DNET_FW_DIR_OUT) { $dir = "out" } if ($proto == 6) { $proto = "tcp" } elsif ($proto == 17) { $proto = "udp" } elsif ($proto == 1) { $proto = "icmp" } $src = $src.':'.join('-', @$sport); $dst = $dst.':'.join('-', @$dport); print "$op $dir $device $proto $src $dst\n"; } # # ip handling # sub ip_opt { my ($cmd) = @_; use Net::Libdnet::Ip; my $h = Net::Libdnet::Ip->new; $h->send($cmd); } # # eth handling # sub eth_opt { my ($cmd, $arg) = @_; use Net::Libdnet::Eth; print "[$cmd] [$arg]\n"; my $h = Net::Libdnet::Eth->new(device => $cmd); $h->send($arg); }