我正在尝试使用android-ndk从open-mesh.org编译batctl-2012.0.0,但是在进行中,tcpdump.c将'sizeof'的无效应用程序赋予了不完整的类型'struct ether_arp'。请告诉我在哪里或如何解决。非常感谢你
static void dump_arp(unsigned char *packet_buff, ssize_t buff_len, int time_printed)
{
struct ether_arp *arphdr;
LEN_CHECK((size_t)buff_len, (long)sizeof(struct ether_arp), "ARP");
if (!time_printed)
print_time();
arphdr = (struct ether_arp *)packet_buff;
switch (ntohs(arphdr->arp_op)) {
case ARPOP_REQUEST:
printf("ARP, Request who-has %s", inet_ntoa(*(struct in_addr *)&arphdr->arp_tpa));
printf(" tell %s (%s), length %zd\n", inet_ntoa(*(struct in_addr *)&arphdr->arp_spa),
ether_ntoa_long((struct ether_addr *)&arphdr->arp_sha), buff_len);
break;
case ARPOP_REPLY:
printf("ARP, Reply %s is-at %s, length %zd\n", inet_ntoa(*(struct in_addr *)&arphdr->arp_spa),
ether_ntoa_long((struct ether_addr *)&arphdr->arp_sha), buff_len);
break;
default:
printf("ARP, unknown op code: %i\n", ntohs(arphdr->arp_op));
break;
}
}
而这个在终端
/home/renanto/workspace/androidbatctl/jni/tcpdump.c: In function 'dump_arp':
/home/renanto/workspace/androidbatctl/jni/tcpdump.c:96: error: invalid application of 'sizeof' to incomplete type 'struct ether_arp'
/home/renanto/workspace/androidbatctl/jni/tcpdump.c:96: error: invalid application of 'sizeof' to incomplete type 'struct ether_arp'
最佳答案
“不完整类型”表示编译器看不到结构的定义。您不能使用sizeof
或访问不完整类型的任何字段。
要使此功能起作用,您需要#include
具有struct ether_arp
定义的头文件。由于它是Linux结构,而不是Android特定结构,因此您应该在NDK的include路径中找到它。
#include <netinet/if_ether.h>
关于android - 对不完整类型'struct ether_arp'的'sizeof'无效应用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9451150/