[Winpcap-users] pcap_loop()/pcap_breakloop() problem

Adagio Grazioso adagiograzioso at gmail.com
Tue Nov 3 05:20:57 PST 2009


GV,

How does using pcap_next_ex() compare with pcap_loop() - performance-wise?

Is there any difference if I capture to file i.e. using
pcap_dump_open()/pcap_dump()

Regards,
Srivats

On Tue, Nov 3, 2009 at 1:30 AM,  <winpcap-users-request at winpcap.org> wrote:
> Date: Mon, 2 Nov 2009 09:19:54 -0800
> From: "Gianluca Varenni" <gianluca.varenni at cacetech.com>
> Subject: Re: [Winpcap-users] pcap_loop()/pcap_breakloop() problem
> To: <winpcap-users at winpcap.org>
> Message-ID: <935BDD80337646B28A852F7541E7B5CA at NELSON3>
> Content-Type: text/plain; format=flowed; charset="iso-8859-1";
>        reply-type=original
>
> My suggestion is to use pcap_next_ex instead of pcap_loop/pcap_breakloop to
> receive packets. It's much more straightforward to use.
>
> Have a nice day
> GV
>
> ----- Original Message -----
> From: "Srivats P" <pstavirs at gmail.com>
> To: <winpcap-users at winpcap.org>
> Sent: Sunday, November 01, 2009 9:33 AM
> Subject: [Winpcap-users] pcap_loop()/pcap_breakloop() problem
>
>
>> Hi,
>>
>> I want to start/stop a pkt capture based on user triggers.
>>
>> Towards this end, I do a pcap_open_live() at init -
>>
>> capHandle = pcap_open_live(port->dev->name, 65535,
>> PCAP_OPENFLAG_PROMISCUOUS, -1, errbuf);
>>
>> On the start trigger, I start a thread which essentially just calls
>> pcap_loop() -
>>
>> dumpHandle = pcap_dump_open(capHandle, capFile.fileName());
>> ret = pcap_loop(capHandle, -1, pcap_dump, (uchar*) dumpHandle);
>>
>> On the stop trigger, I call pcap_breakloop() -
>>
>> pcap_breakloop(capHandle);
>>
>> My problem is that sometimes (not always) on the start trigger when I
>> call pcap_loop(), it exits immediately with -2. As per the
>> documentation this may happen when the last call to pcap_loop()
>> returns a positive number and the breakloop flag is not reset - but in
>> my case pcap_loop() never returns a positive number 'coz the 'cnt'
>> passed to pcap_loop() is -1. So pcap_loop() always returns -2. But the
>> next invocation of pcap_loop() via the 'start' trigger may exit
>> immediately without doing any capture!
>>
>> Is there any other way to reset the breakloop flag? Or someway to
>> identify that I need to call pcap_loop() once to reset the flag before
>> calling it again for the actual start of capture?
>>
>> Or (most likely) maybe I'm doing something incorrectly?
>>
>> Regards,
>> Srivats


More information about the Winpcap-users mailing list