'sizeof'无效应用于不完整类型'struct ether_arp'

时间:2012-02-26 06:45:16

标签: android android-ndk

我试图使用android-ndk从open-mesh.org编译batctl-2012.0.0,但是,正在进行中,tcpdump.c无效地应用了' sizeof'到不完整类型&#struct; 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' 

1 个答案:

答案 0 :(得分:1)

“不完整类型”表示编译器无法看到结构的定义。您无法使用sizeof或访问不完整类型的任何字段。

要使此功能正常工作,您需要#include具有struct ether_arp定义的头文件。由于它是Linux结构,而不是特定于Android的结构,因此您应该在NDK中的包含路径中找到它。

#include <netinet/if_ether.h>