Hello.
I'm writing a packet sniffer in C++ using libpcap-0.9.4.
I've tried to use a class function member as a callback for
pcap_loop(), but the compiler complains that arguments don't
match. The code is something like this (I have simplified it):
8<-----------------------------
class X
{
public:
// This is the callback, defined below
void dumper(u_char *u, const struct pcap_pkthdr *h,
const u_char *p);
};
void X::dumper(u_char *u, const struct pcap_pkthdr *h, const
u_char *p)
{
// stuff...
pcap_dump(blah, blah, blah);
}
int main()
{
X x;
// Open pcap, etc...
pcap_loop(p, -1, x.dumper, 0);
}
----------------------------->8
And g++ says this:
In function `int main()':
sniffer.cc:645: error: argument of type `void (X::)(u_char*,
const pcap_pkthdr*, const u_char*)' does not match `void
(*)(u_char*, const pcap_pkthdr*, const u_char*)'
This is not a warning but an error, so I cannot compile the program.
Is there any trick to fix this? Am I missing something?
Should I avoid C++ and use C instead (don't say that please...)
Thanks.
__david
-
This is the tcpdump-workers list.
Visit https://lists.sandelman.ca/ to unsubscribe.