fork download
  1. #include <iostream>
  2. #include <thread>
  3.  
  4. typedef double pcap_t;
  5. typedef float device;
  6.  
  7. typedef void (*pcap_handler)(u_char *user, const struct pcap_pkthdr *h, const u_char *bytes);
  8.  
  9. int pcap_loop(pcap_t *p, int cnt, pcap_handler callback, u_char *user);
  10.  
  11. class monitor {
  12. public:
  13. monitor(device *dev);
  14. void exec();
  15. void end();
  16. virtual ~monitor();
  17.  
  18. private:
  19. static pcap_handler process_packet(u_char *arg, const struct pcap_pkthdr* pkthdr,
  20. const u_char * packet);
  21. static void thread_func(monitor *mon);
  22. device *dev;
  23. };
  24. void monitor::exec() {
  25. std::thread t (monitor::thread_func, this);
  26. }
  27.  
  28. void monitor::thread_func(monitor *mon) {
  29. pcap_loop(nullptr, -1, monitor::process_packet, reinterpret_cast<u_char*>(mon)); // error in this line
  30. }
  31.  
  32. pcap_handler monitor::process_packet(u_char *arg, const struct pcap_pkthdr* pkthdr,
  33. const u_char * packet) {
  34. monitor *mon = reinterpret_cast<monitor*>(arg);
  35. }
  36.  
  37.  
  38. int main() {
  39. // your code goes here
  40. return 0;
  41. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In static member function ‘static void monitor::thread_func(monitor*)’:
prog.cpp:29:81: error: invalid conversion from ‘void (* (*)(u_char*, const pcap_pkthdr*, const u_char*))(u_char*, const pcap_pkthdr*, const u_char*) {aka void (* (*)(unsigned char*, const pcap_pkthdr*, const unsigned char*))(unsigned char*, const pcap_pkthdr*, const unsigned char*)}’ to ‘pcap_handler {aka void (*)(unsigned char*, const pcap_pkthdr*, const unsigned char*)}’ [-fpermissive]
   pcap_loop(nullptr, -1, monitor::process_packet, reinterpret_cast<u_char*>(mon)); // error in this line
                                                                                 ^
prog.cpp:9:5: error:   initializing argument 3 of ‘int pcap_loop(pcap_t*, int, pcap_handler, u_char*)’ [-fpermissive]
 int pcap_loop(pcap_t *p, int cnt, pcap_handler callback, u_char *user);
     ^
prog.cpp: In static member function ‘static void (* monitor::process_packet(u_char*, const pcap_pkthdr*, const u_char*))(u_char*, const pcap_pkthdr*, const u_char*)’:
prog.cpp:34:12: warning: unused variable ‘mon’ [-Wunused-variable]
   monitor *mon = reinterpret_cast<monitor*>(arg);
            ^
prog.cpp:35:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
stdout
Standard output is empty