I am trying to use the pcap_loop function in libpcab library in Linux with this prototype:
int pcap_loop(pcap_t *, int, pcap_handler, u_char *);
pcap_pkthdr is a function pointer:
typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *, const u_char *);
In my program, I have defined the following method in class SniffEthernet:
void SniffEthernet::got_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet);
Now calling pcap_loop as below
pcap_loop(handle, num_packets, this->got_packet, NULL);
gives me the following compile-time error:
SniffEthernet.cc:139:58: error: cannot convert ‘VENTOS::SniffEthernet::got_packet’ from type ‘void (VENTOS::SniffEthernet::)(u_char*, const pcap_pkthdr*, const u_char*) {aka void (VENTOS::SniffEthernet::)(unsigned char*, const pcap_pkthdr*, const unsigned char*)}’ to type ‘pcap_handler {aka void (*)(unsigned char*, const pcap_pkthdr*, const unsigned char*)}’
What am I doing wrong here?
Edit: I found a similar post here.