2012-02-26 134 views
1

我正在尝试从open-mesh.org编译batctl-2012.0.0,使用android-ndk,但是在进行中,tcpdump.c会给出无效的应用程序'sizeof'改为不完整类型'struct ether_arp'。请告诉我在哪里或如何解决它。非常感谢你'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' 

回答

1

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

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

#include <netinet/if_ether.h> 
+0

我有同样的问题,现在我正在寻找哪里的any_arp驻留在Android头。 http://osxr.org/android/ident?_i=ether_arp似乎是这样的目的的好工具 – Mixaz 2014-03-01 07:51:18

+0

根据我的搜索,结构ether_arp没有在Android源代码中定义... – Mixaz 2014-03-01 11:19:43

+0

@Mixaz这是因为它是不是一个Android结构,而是一个Linux结构(准确地说,是一个POSIX结构)。我已经用更多信息更新了我的答案。 – 2014-03-01 12:25:15

相关问题