在 ARM 上取消引用指向不完整类型但不是 x86 上的指针

Dereferencing pointer to incomplete type on ARM but not x86

我在 beaglebone 上编译时遇到了这个错误(当然我已经包含 netinet/ip_icmp.h):

src/network.c: In function 'ping':
src/network.c:74:3: warning: implicit declaration of function 'setuid' [-Wimplicit-function-declaration]
src/network.c:74:3: warning: implicit declaration of function 'getuid' [-Wimplicit-function-declaration]
src/network.c:88:6: error: dereferencing pointer to incomplete type
src/network.c:89:6: error: dereferencing pointer to incomplete type
src/network.c:118:14: error: dereferencing pointer to incomplete type

但它只出现在 ARM 平台 (beaglebone) 上。在我的 x86 上一切正常。 这里有一些有用的信息:

root@beaglebone:~/mips# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/4.6/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Debian 4.6.3-14' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-sjlj-exceptions --with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard --with-mode=thumb --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
Thread model: posix
gcc version 4.6.3 (Debian 4.6.3-14)

84 到 89 行形式 network.c:

struct icmp *pkt;
pkt = (struct icmp *) packet;
memset(pkt, 0, sizeof(packet));
pkt->icmp_type = ICMP_ECHO;
pkt->icmp_cksum = in_cksum((unsigned short *) pkt, sizeof(packet));

我找到了告诉我使用标志 -D__USE_BSD 的答案,但它没有用。

有没有人知道:

  1. 如何使这个程序运行?
  2. 如何不使用 <netinet/ip_icmp.h> 编写一个简单的 ping 程序?

在包含 headers 之前添加 GNU 扩展的定义:

#define _GNU_SOURCE

或-D_GNU_SOURCE编译器标志。