Hi I'm doing a sniffer with c++ and libpcap and I would want to stop the capture when I press ctrl+c, this is my code:
void Capture::terminate_process(int s){
pcap_breakloop(descr);
pcap_close(descr);
}
void Capture::capturar(){
signal(SIGINT, terminate_process);
pcap_loop (descr, -1, mycallback, NULL);
}
At the .h I have declared:
pcap_t *descr;
I've seen similar solutions for my problem like this: How to use pcap_breakloop? But I can't compile, I get this error:
capture.cpp: 138:35: error: argument of type 'void (Capture ::) (int)' does not match '{aka __sighandler_t void (*) (int)}'
signal requires a function pointer, you are using a member function pointer. Just declare Capture::terminate_process(int) as static:
class Capture {
public:
/* ... */
static void Capture::terminate_process(int s);
/* ... */
};
void Capture::terminate_process(int s){
pcap_breakloop(descr);
pcap_close(descr);
}
/* ... */
signal(SIGINT, &Capture::terminate_process);
You will have to make some changes to your code so that you don't depend on instance variables though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With