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

Srivats P pstavirs at gmail.com
Sun Nov 1 09:33:27 PST 2009


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,

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() -


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?


More information about the Winpcap-users mailing list