tags:

views:

78

answers:

1
/* 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...

+2  A: 

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
Correct.You can also use pcap_next_ex() to get a single packet (maybe in a loop).
brickner