title: callback method in pcap_loop
body: <p>I am trying to use the pcap_loop function in libpcab library in Linux with this prototype:</p>
  
  <pre><code>int pcap_loop(pcap_t *, int, pcap_handler, u_char *);
  </code></pre>
  
  <p>pcap_pkthdr is a function pointer:</p>
  
  <pre><code>typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *, const u_char *);
  </code></pre>
  
  <p>In my program, I have defined the following method in class SniffEthernet:</p>
  
  <pre><code>void SniffEthernet::got_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet);
  </code></pre>
  
  <p>Now calling pcap_loop as below </p>
  
  <pre><code>pcap_loop(handle, num_packets, this-&gt;got_packet, NULL);
  </code></pre>
  
  <p>gives me the following compile-time error:</p>
  
  <pre><code>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*)}’
  </code></pre>
  
  <p>What am I doing wrong here?</p>
  
  <p>Edit: I found a similar post <a href="https://stackoverflow.com/questions/4881896/using-a-c-class-member-function-cannot-be-static-as-a-c-callback-function">here</a>.</p>