PCAP不完全类型

编程入门 行业动态 更新时间:2024-10-23 18:34:35
本文介绍了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不完全类型

本文发布于:2023-11-27 08:56:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637386.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不完全   类型   PCAP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!