3
/* start the capture */
pcap_loop(adhandle, 0, packet_handler, NULL);

The above starts the capture,but I don't find a way to stop the capture except exit the programe...

httpinterpret
  • 6,409
  • 9
  • 33
  • 37

1 Answers1

5

Call pcap_breakloop() in your pcap_handler (you've named it packet_handler in your example). The call to pcap_loop() will then return -2.

Alternatively, make repeated calls to pcap_dispatch() until you're done, or specify a nonzero value for count to handle that number of packets before returning.

Matt Joiner
  • 112,946
  • 110
  • 377
  • 526