【问题标题】:Qt pointer to a structure指向结构的 Qt 指针
【发布时间】:2020-03-27 17:52:23
【问题描述】:

我使用 Qt Creator (5.13),我尝试使用 libpcap 创建一些应用程序。当我在一个类中使用 (struct ethhdr *eth) 创建一些方法时,我会得到一个错误:

代码:

void SniffPackets::foo(struct ethhdr *eth){
     sprintf(temp_buf, "%3d.%3d.%3d.%3d",
        (int)eth->h_dest[0],
        (int)eth->h_dest[1],
        (int)eth->h_dest[2],
        (int)eth->h_dest[3]);
}

错误: 成员访问不完整类型“struct ethhdr *eth”。

顺便说一句,我用的是 c++99

【问题讨论】:

  • ` INCLUDEPATH += C:/WpdPack/Include LIBS += -LC:/WpdPack/Lib LIBS += -lwpcap `
  • 和标题:#include
  • 我意识到,我查看了 Linux 的示例,这个结构在 <net/ethernet.h> 中。但我在 Windows 中需要相同的标题。它是什么文件?
  • “我使用 c++99” - C++99 不是一门语言。有 C++98 和 C99(等等)。

标签: windows pointers structure libpcap


【解决方案1】:

如果你使用 Windows,你应该使用tcpdump,有几个标题。

ether.hip.hudp.htcp.h

此外,我尝试使用ethhdr,但它是错误的,显然这个结构用于Linux。

在 Windows 上使用它:

/*
* Structure of an Ethernet header.
*/
struct  ether_header {
    uint8_t     ether_dhost[ETHER_ADDR_LEN];
    uint8_t     ether_shost[ETHER_ADDR_LEN];
    uint16_t    ether_length_type;
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-21
    • 2012-03-28
    • 1970-01-01
    相关资源
    最近更新 更多