[Winpcap-users] pcap_loop()/pcap_breakloop() problem
Gianluca Varenni
gianluca.varenni at cacetech.com
Mon Nov 2 09:19:54 PST 2009
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
> _______________________________________________
> Winpcap-users mailing list
> Winpcap-users at winpcap.org
> https://www.winpcap.org/mailman/listinfo/winpcap-users
More information about the Winpcap-users
mailing list