【问题标题】:C++ pcap_loop() arguments issueC++ pcap_loop() 参数问题
【发布时间】:2017-07-30 14:13:31
【问题描述】:

我正在尝试将 NULL 传递给 pcap_loop() 函数,就像 tcpdump man 一样。

这是我要触发的回调函数:

void Home::gotPacket(u_char *args, const struct pcap_pkthdr *header,
                const u_char *packet){

}

首先我尝试了这个:

pcap_loop(handle, 0, gotPacket, NULL);

其次,我尝试传递一个具有 NULL 值的变量:

u_char *arg = NULL;
pcap_loop(handle, 0, gotPacket, arg);

第一种和第二种方法都返回了这个错误:

error: invalid use of non-static member function
pcap_loop(handle, 0, gotPacket, NULL);
                                    ^

error: invalid use of non-static member function
pcap_loop(handle, 0, gotPacket, arg);
                                   ^

我该如何解决这个错误?提前感谢您的帮助!

【问题讨论】:

    标签: c++ pcap


    【解决方案1】:

    我几乎可以肯定问题在于Home::gotPacket 不是static。考虑将其更改为static

    static void Home::gotPacket(u_char *args, const struct pcap_pkthdr *header,
                    const u_char *packet){
    
    }
    

    这应该可以解决您的问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-20
      • 1970-01-01
      • 2011-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多