2012-02-26 128 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

相關問題