[Winpcap-users] Stop Capture with "pcap_next_ex"
Gianluca Varenni
gianluca.varenni at cacetech.com
Thu Apr 13 14:50:19 GMT 2006
Benjamin,
what do you mean exactly by "stopping the capture correctly"?
pcap_next_ex is simpluy an API reading packets from a WinPcap adapter (like a read on a socket or file), so there's nothing so special to do.
In general if you want to close your app cleanly (well, every application!) when Ctrl-C is hit, you should register a handler for the Ctrl-C "signal" and in this handler set some flag that tells the main thread (i.e. the one running main()) to stop looping over pcap_next_ex()
This is just some pseudocode (I haven't looked at the documentation, so the prototype of the handler is probably wrong):
volatile int g_stop_reading = FALSE;
void ctrl_c_handler()
{
g_stop_reading = TRUE;
}
int main()
{
...
register_ctrl_c_handler(ctrl_c_handler);
p = pcap_open_live();
while(!g_stop_read)
{
result = pcap_next_ex(...);
if (result != SUCCESS)
break;
//
// process packet if any
//
}
pcap_close(p);
}
Hope it helps
GV
----- Original Message -----
From: Benjamin Amaudric
To: winpcap-users at winpcap.org
Sent: Wednesday, April 12, 2006 9:09 AM
Subject: [Winpcap-users] Stop Capture with "pcap_next_ex"
I want to know if it is possible to stop the capture "correctly" when I use "pcap_next_ex" to capture packets.
"Correctly" means when I enter Ctr+C for exemple!
Thanks you
------------------------------------------------------------------------------
MSN Hotmail sur i-modeT ! : envoyez et recevez des e-mails depuis votre téléphone portable !
------------------------------------------------------------------------------
_______________________________________________
Winpcap-users mailing list
Winpcap-users at winpcap.org
https://www.winpcap.org/mailman/listinfo/winpcap-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.winpcap.org/pipermail/winpcap-users/attachments/20060413/1ff8baca/attachment.htm
More information about the Winpcap-users
mailing list