[Winpcap-users] Re: breaking out of a pcap_next_ex() loop

Gianluca Varenni gianluca.varenni at cacetech.com
Fri May 12 15:51:23 GMT 2006


Joe, 

I think your approach is not a good one: you are basically receiving packets from the handler of a button in your GUI. The overall effect is that your GUI will be blocked forever, because you never return from the Click button handler (OnButtonCapture). You should never do lengthy operations (or blocking ones) in any handler related to the GUI (OnClick and so on), because when you are doing the lenghty operation, the GUI becomes not responsible to user interaction (every user interaction is managed by a single thread, what's usually called "main thread" or "UI thread").

The easiest solution (at least for me) would be to spawn a worker thread that captures packets in the background, and the UI interacts with the thread (using events, a global variable, whatever) to stop the capture thread.

In particular, it's always better to create a loop like 

while (pcap_next_ex returns success AND we do not need to terminate the capture)
{
    process the packet
}

(ok, I'm lazy and I prefer to write text rather than code today, it's should be clear enough).

Have a nice day
GV



  ----- Original Message ----- 
  From: joe kibz 
  To: winpcap-users at winpcap.org 
  Sent: Friday, May 12, 2006 5:53 AM
  Subject: [Winpcap-users] Re: breaking out of a pcap_next_ex() loop


  problem:

  here's my code in brief:

  void CButton::onButtonCapture(){

  open a device handle;

  while(pcap_next_ex())//capture packets;

  }

  ?How do i break out or stop a pcap_next_ex() loop whenever i want ?
  ?How does the timeout value in pcap_next_ex() parameters work ?


  joe


------------------------------------------------------------------------------
  Yahoo! Mail goes everywhere you do. Get it on your phone.


------------------------------------------------------------------------------


  _______________________________________________
  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/20060512/c7d50189/attachment.htm


More information about the Winpcap-users mailing list