Problems with interrupting capture with libpcap
Hi I am doing a sniffer with C ++ and libpcap and I would like to stop capturing 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);
}
In .h I stated:
pcap_t *descr;
I've seen similar solutions for my problem: How do I use pcap_breakloop? But I cannot compile, I get this error:
capture.cpp: 138: 35: error: argument of type 'void (Capture: :) ββ(int)' does not match '{aka __sighandler_t void (*) (int)}'
+3
source to share
1 answer
signal
a function pointer is required, 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 are not dependent on instance variables.
+3
source to share