PCAP不完全类型 [英] Pcap Incomplete Type

查看:261
本文介绍了PCAP不完全类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到利用PCAP一个小项目的MAC地址。由于现在的结构,我看起来与工作是这样的:

 结构ethernet_header
    {
         u_char点雅[6];
         u_char shost [6];
         u_short类型;
    };

的int code调用简单loosk这样的:

 无效get_packet(u_char * ARGS,常量结构pcap_pkthdr *头,常量u_char *包)
    {
         常量结构ethernet_header *以太网;
         常量结构IP_HEADER * IP;
         以太网=(结构ethernet_header *)(包);
         IP =(结构IP_HEADER *)(分组+ 16);         的printf(目的MAC:%S \\ n,以太网的>点雅);
    }

我receiveing​​的错误是

 错误:提领指向不完全类型

现在据我知道包VAR被正确initalized,因为它是在code的其他部分所使用没有问题。在IP结构的情况下,这也工作正常,没有错误。我知道什么是被加载到particluar地址我只是无法弄清楚怎么回事。任何人有任何想法。


解决方案

  

错误:提领指向不完全类型


您错过了包括哪些结构ethernet_header 定义了具有功能的C文件头文件无效get_packet()

这个错误是因为编译器不能的的结构的定义,很可能你只是向前宣布它。然而,由于取消引用指针结构,编译器必须知道该结构的布局,因此,必须看到结构的定义。

因此​​,只要有它,你需要包括包含在这个特殊的C文件的结构定义的头文件。

I am attempting to find the MAC address using pcap for a small project. As of right now the structure I am working with looks like this:

    struct ethernet_header
    {
         u_char dhost[6];
         u_char shost[6];
         u_short type;
    };

The call int the code simply loosk like:

    void get_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet)
    {
         const struct ethernet_header *ethernet;
         const struct ip_header *ip;
         ethernet = (struct ethernet_header *)(packet);
         ip = (struct ip_header *)(packet + 16);

         printf("Destination MAC: %s\n", ethernet->dhost);
    }

The error I am receiveing is

error: dereferencing pointer to incomplete type

Now as far as I know the packet var is being initalized properly because it is being used in other sections of the code without a problem. In the case of the ip struct, this also works fine with no errors. I know what is being loaded into that particluar address I just can't figure out whats going on. Anyone have any ideas.

解决方案

error: dereferencing pointer to incomplete type

You missed including the header file which defines struct ethernet_header in the c file which has the function void get_packet().

The error is because the compiler cannot see the definition of the structure, most likely you are just forward declaring it. However, Since you dereference the pointer to structure the compiler must know the layout of the structure and hence must see the definition of the structure.

So just include it You need to include the header file which contains the definition of the structure in this particular c file.

这篇关于PCAP不完全类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆