Skip Menu |

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

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

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

Bug Information
Severity: Important
Broken in: (no value)
Fixed in: (no value)



Subject: [patch] erroneous arguments given to the packet handler
Hello, While cleaning the patch and writing the tests for #84749, I discovered that the way arguments are given to the packet handler is quite wrong: because the count argument of pcap_dispatch() is -1, it actually processes as many packets as it can, meaning that several pairs of ($header,$packet) are pushed in @pending. As a result, when the packet handler is called back, it can received much more than the two documented arguments (and even more than the three arguments, given that the internal AnyEvent::IO object is also passed). With the samples from #84749, which consists of 10 pings to www.ietf.org, the packet handler is called once with 41 arguments. The consequence is that, in such a case, the handler will miss many packets because it does not expect to process more than one packet at a time. Attached is a patch that correct this. However, the packet handler in t/10_setup_pcap.t is called a third time for a reason I can't understand. Regards, Sébastien Aperghis-Tramoni -- Close the world, txEn eht nepO.
Subject: packet-handler-args.diff
commit f5f72886415ae97bd9b7ed59440443287787c5af Author: Sébastien Aperghis-Tramoni <sebastien.aperghis-tramoni@diabolocom.com> Date: Fri Apr 19 20:09:09 2013 +0200 make sure the packet handler is only called with the documented arguments, and that no packet is missed diff --git a/lib/AnyEvent/Pcap.pm b/lib/AnyEvent/Pcap.pm index e394019..5e640fb 100644 --- a/lib/AnyEvent/Pcap.pm +++ b/lib/AnyEvent/Pcap.pm @@ -79,6 +79,7 @@ sub run { my $self = shift; my $pcap = $self->_setup_pcap(); + my $empty = { len => 0, caplen => 0, tv_sec => 0, tv_usec => 0 }; my $packet_handler = $self->packet_handler || sub { $self->packet_handler( sub { } ); @@ -90,17 +91,17 @@ sub run { fh => $self->fd, poll => 'r', cb => sub { - my @pending; + my @args; Net::Pcap::dispatch( - $pcap, -1, + $pcap, 1, sub { my $header = $_[1]; my $packet = $_[2]; push @{ $_[0] }, ( $header, $packet ); }, - \@pending + \@args ); - $packet_handler->( @pending, $io ); + $packet_handler->( $args[0]||$empty, $args[1]||"", $io ); } ); }