Skip Menu |

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

Report information
The Basics
Id: 77807
Status: resolved
Priority: 0/
Queue: Net-Pcap

People
Owner: Nobody in particular
Requestors: mike.schmidt [...] intello.com
Cc:
AdminCc:

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



Subject: Net-Pcap loop will not work correctly in a multi-threaded environment
Date: Wed, 13 Jun 2012 16:41:10 -0400
To: bug-Net-Pcap [...] rt.cpan.org
From: Mike Schmidt <mike.schmidt [...] intello.com>
I have been trying to use Net::Pcap's loop function (cia Net::PcapUtuls) in a multithreaded environment where I need to monitor about 15-20 interfaces. It did not work correctly, in that only one callback routine was ever called, no matter what the interface was. This is, I presume, what you meant in the Limitations section of the Net::Pcap docs. Is this a limit imposed by Net::Pcap? In the libpcap documentation, they certainly imply that multithreade use is possible, even expected. If this is a Net::Pcap limit, is it easy to change? -- *Mike SCHMIDT **CTO Intello Technologies Inc. **mike.schmidt@intello.com* *Canada: 1-888-404-6261 x320 USA: 1-888-404-6268 x320 Mobile: 514-409-6898 www.intello.com* * *
Subject: Re: [rt.cpan.org #77807] Net-Pcap loop will not work correctly in a multi-threaded environment
Date: Thu, 29 Nov 2012 00:08:52 +0100
To: bug-Net-Pcap [...] rt.cpan.org
From: Sébastien Aperghis-Tramoni <saper [...] cpan.org>
Mike Schmidt wrote via RT: Show quoted text
> I have been trying to use Net::Pcap's loop function (cia Net::PcapUtuls) in > a multithreaded environment where I need to monitor about 15-20 interfaces. > It did not work correctly, in that only one callback routine was ever > called, no matter what the interface was. This is, I presume, what you > meant in the Limitations section of the Net::Pcap docs. Is this a limit > imposed by Net::Pcap? In the libpcap documentation, they certainly imply > that multithreade use is possible, even expected. > If this is a Net::Pcap limit, is it easy to change?
This is a limit in Net::Pcap itself and not in libpcap. The origin of the problem, as described in the documentation, is that the callback function is stored in a global variable in Pcap.xs » https://github.com/maddingue/Net-Pcap/blob/master/Pcap.xs#L52 A solution would be to wrap the pcap_t object in a Net::Pcap object so each Perl callback can be attached to the corresponding pcap object. It's not necessarily hard, but it takes a bit of time and C knowledge to do correctly. -- Sébastien Aperghis-Tramoni Close the world, txEn eht nepO.
James Rouzier found a way to remove this limitation. This should be fixed with version 0.18. Details in: https://github.com/maddingue/Net-Pcap/pull/5 -- Close the world, txEn eht nepO.