Search code examples
windowspointersstructurelibpcap

Qt pointer to a structure


I use Qt Creator (5.13), I try to create some application with libpcap. When I create some method with (struct ethhdr *eth) in a class, I'll get an error:

Code:

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]);
}

Error: Member access into incomplete type 'struct ethhdr *eth'.

Btw, I use c++99


Solution

  • If you use Windows, you should use tcpdump, there are a few headers for that.

    ether.h, ip.h, udp.h, and tcp.h

    And more, I tried to use ethhdr, but it's wrong, obviously this struct for Linux.

    Use that for 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;
    };