Skip Menu |

This queue is for tickets about the AnyEvent-Pcap CPAN distribution.

Report information
The Basics
Id: 84749
Status: new
Priority: 0/
Queue: AnyEvent-Pcap

People
Owner: Nobody in particular
Requestors: SAPER [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.00002
Fixed in: (no value)



Subject: [patch] add support for offline mode
Hello, Attached is a patch (01-support-offline-mode.diff) to add support for the offline mode, that is processing saved dumps. The second patch (02-test-offline-mode.diff) adds some unit tests. The samples are in samples.tar.gz A third patch (03-old-Net-Pcap-compat.diff) is provided to make AnyEvent::Pcap works when an old version of Net::Pcap is installed. 04-manifest.diff updates the MANIFEST. Regards, Sébastien Aperghis-Tramoni -- Close the world, txEn eht nepO.
Subject: 02-test-offline-mode.diff
commit e3032b7ccb2295517ad33f1a76d9de2fc514b70e Author: Sébastien Aperghis-Tramoni <sebastien.aperghis-tramoni@diabolocom.com> Date: Fri Apr 19 19:23:44 2013 +0200 test offline mode diff --git a/t/10_setup_pcap.t b/t/10_setup_pcap.t new file mode 100644 index 0000000..d508420 --- /dev/null +++ b/t/10_setup_pcap.t @@ -0,0 +1,44 @@ +#!perl +use strict; +use warnings; +use Test::More; +use AnyEvent::Pcap; +use NetPacket::ICMP qw< :types >; + + +my @samples = glob "t/samples/*.dmp"; + +plan tests => 5 * @samples; + + +# check that _setup_pcap() works on saved dumps +for my $sample (@samples) { + my $cv = AnyEvent->condvar; + + my $ae_pcap; $ae_pcap = eval { AnyEvent::Pcap->new( + device => "file:$sample", + packet_handler => sub { + my ($header, $packet) = @_; + return unless ref $header eq "HASH"; + + my $ip = $ae_pcap->utils->extract_ip_packet($packet); + my $icmp = NetPacket::ICMP->decode($ip->{data}); + + ok $icmp->{type} == ICMP_ECHO || $icmp->{type} == ICMP_ECHOREPLY, + "check that the packet is an ICMP echo or echo-reply"; + + $cv->send; + }, + )}; + is $@, "", "AnyEvent::Pcap->new(...)"; + + my $pcap = eval { $ae_pcap->_setup_pcap }; + is $@, "", "\$ae_pcap->_setup_pcap"; + + isa_ok $pcap, "pcap_tPtr", 'check that $pcap'; + isa_ok $ae_pcap->fd, "GLOB", 'check that $ae_pcap->fd'; + + $ae_pcap->run; + $cv->recv; +} +
Subject: 03-old-Net-Pcap-compat.diff
commit bd114578990709bfe234cf2e5b3c3e401b83068a Author: Sébastien Aperghis-Tramoni <sebastien.aperghis-tramoni@diabolocom.com> Date: Fri Apr 19 19:29:27 2013 +0200 be compatible with old versions of Net::Pcap diff --git a/lib/AnyEvent/Pcap.pm b/lib/AnyEvent/Pcap.pm index 4dd95c1..e394019 100644 --- a/lib/AnyEvent/Pcap.pm +++ b/lib/AnyEvent/Pcap.pm @@ -11,6 +11,15 @@ our $VERSION = '0.00002'; __PACKAGE__->mk_accessors($_) for qw(utils device filter packet_handler fd); + +# be compatible with old versions of Net::Pcap +if ($Net::Pcap::VERSION < 0.15) { + *Net::Pcap::pcap_lookupdev = \&Net::Pcap::lookupdev; + *Net::Pcap::pcap_open_live = \&Net::Pcap::open_live; + *Net::Pcap::pcap_open_offline = \&Net::Pcap::open_offline; + *Net::Pcap::pcap_file = \&Net::Pcap::file; +} + sub new { my $class = shift; my $self = bless {@_}, $class;
Subject: 01-support-offline-mode.diff
commit 48d4e48efa54eb6c5ff2b0a965aa9e100f90eb0c Author: Sébastien Aperghis-Tramoni <sebastien.aperghis-tramoni@diabolocom.com> Date: Fri Apr 19 19:23:22 2013 +0200 add support for offline mode diff --git a/lib/AnyEvent/Pcap.pm b/lib/AnyEvent/Pcap.pm index 17824b7..4dd95c1 100644 --- a/lib/AnyEvent/Pcap.pm +++ b/lib/AnyEvent/Pcap.pm @@ -28,12 +28,31 @@ sub _setup_pcap { ->(); croak $err if $err; - my $pcap = Net::Pcap::pcap_open_live( $device, 1024, 1, 0, \$err ); - croak $err if $err; - - my ( $address, $netmask ); - Net::Pcap::lookupnet( $device, \$address, \$netmask, \$err ); - croak $err if $err; + my $pcap; + my $netmask = 0; + + if ($device =~ s/^file://) { + # open the file + $pcap = Net::Pcap::pcap_open_offline( $device, \$err ); + croak $err if $err; + + # get its file descriptor + my $fd = Net::Pcap::pcap_file($pcap); + $self->fd($fd); + } + else { + # open the device + $pcap = Net::Pcap::pcap_open_live( $device, 1024, 1, 0, \$err ); + croak $err if $err; + + # get its file descriptor + my $fd = Net::Pcap::fileno($pcap); + $self->fd($fd); + + # get the associated network mask + Net::Pcap::lookupnet( $device, \my $address, \$netmask, \$err ); + croak $err if $err; + } my $filter; my $filter_string = $self->filter || sub { @@ -44,8 +63,6 @@ sub _setup_pcap { Net::Pcap::compile( $pcap, \$filter, $filter_string, 0, $netmask ); Net::Pcap::setfilter( $pcap, $filter ); - my $fd = Net::Pcap::fileno($pcap); - $self->fd($fd); return $pcap; }
Subject: 04-manifest.diff
commit 78d8f19e600bfc5c2250b1b818038315d884d21b Author: Sébastien Aperghis-Tramoni <sebastien.aperghis-tramoni@diabolocom.com> Date: Fri Apr 19 19:30:33 2013 +0200 new files diff --git a/MANIFEST b/MANIFEST index 4c38892..4bd55be 100644 --- a/MANIFEST +++ b/MANIFEST @@ -24,6 +24,9 @@ README t/00_compile.t t/01_basic.t t/02_method.t +t/10_setup_pcap.t t/97_kwalitee.t t/98_pod-coverage.t t/99_pod.t +t/samples/ping-ietf-20pk-be.dmp +t/samples/ping-ietf-20pk-le.dmp
Subject: samples.tar.gz
Download samples.tar.gz
application/x-gzip 1.1k

Message body not shown because it is not plain text.