如何为Android x86和x86_64编译tcpdump

时间:2018-08-16 23:21:04

标签: android x86 cross-compiling tcpdump libpcap

我遇到了这个问题Cross Compile - tcpdump for x86

我尝试了OQ中的脚本和可接受的答案,但都没有奏效,它们都给出了错误,所以我认为做错了事。

这是我尝试针对x86进行编译:

#!/usr/bin/env bash

sudo apt-get install byacc
sudo apt-get install flex

export TCPDUMP=4.9.2
export LIBPCAP=1.9.0

wget http://www.tcpdump.org/release/tcpdump-$TCPDUMP.tar.gz
wget http://www.tcpdump.org/release/libpcap-$LIBPCAP.tar.gz

tar zxvf tcpdump-$TCPDUMP.tar.gz
tar zxvf libpcap-$LIBPCAP.tar.gz
export CC=gcc
cd libpcap-$LIBPCAP
./configure --host=x86 --with-pcap=linux
make
cd ..

cd tcpdump-$TCPDUMP
export ac_cv_linux_vers=2
export CFLAGS=-static
export CPPFLAGS=-static
export LDFLAGS=-static

./configure --host=x86 --disable-ipv6
make

它也不起作用(与x86_64相同),这是命令输出:

checking build system type... x86_64-pc-linux-gnu
checking host system type... x86-unknown-none
checking target system type... x86-unknown-none
checking for x86-gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for gcc option to accept ISO C99... none needed
checking whether the compiler supports the -fvisibility=hidden option... yes
checking for inline... inline
checking for special C compiler options needed for large files... no
checking for _FILE_OFFSET_BITS value needed for large files... no
checking for _LARGEFILE_SOURCE value needed for large files... no
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking sys/ioccom.h usability... no
checking sys/ioccom.h presence... no
checking for sys/ioccom.h... no
checking sys/sockio.h usability... no
checking sys/sockio.h presence... no
checking for sys/sockio.h... no
checking limits.h usability... yes
checking limits.h presence... yes
checking for limits.h... yes
checking netpacket/packet.h usability... yes
checking netpacket/packet.h presence... yes
checking for netpacket/packet.h... yes
checking for net/pfvar.h... no
checking for ANSI ioctl definitions... yes
checking for strerror... yes
checking for strerror_r... yes
checking for strerror_s... no
checking for strlcpy... no
checking for strlcat... no
checking for vsnprintf... yes
checking for snprintf... yes
checking for strtok_r... yes
checking for ffs... yes
checking whether ffs is declared... yes
checking for getaddrinfo... yes
checking for library containing putmsg... none required
checking whether getnetbyname_r is declared... yes
checking for the Linux getnetbyname_r()... yes
checking whether getprotobyname_r is declared... yes
checking for the Linux getprotobyname_r()... yes
checking for ether_hostton... yes
checking whether ether_hostton is declared... no
checking whether ether_hostton is declared... yes
checking pthread.h usability... yes
checking pthread.h presence... yes
checking for pthread.h... yes
checking for pthread_create... no
checking for pthread_create in -lpthreads... no
checking for pthread_create in -lpthread... yes
checking if --disable-protochain option is specified... enabled
checking packet capture type... linux
checking for linux/wireless.h... yes
checking for nl_socket_alloc in -lnl-3... no
checking for nl_socket_alloc in -lnl... no
checking for nl_handle_alloc in -lnl... no
checking for linux/ethtool.h... yes
checking for struct tpacket_stats... yes
checking for struct tpacket_auxdata.tp_vlan_tci... yes
checking for getifaddrs... yes
checking ifaddrs.h usability... yes
checking ifaddrs.h presence... yes
checking for ifaddrs.h... yes
configure: no hardware timestamp support implemented for none
checking for socklen_t... yes
checking dagapi.h usability... no
checking dagapi.h presence... no
checking for dagapi.h... no
checking whether we have Septel API headers... no
checking whether we have Myricom Sniffer API... no
checking whether TurboCap is supported... no
checking whether to enable remote packet capture... no
checking whether to build optimizer debugging code... no
checking whether to build parser debugging code... no
checking for flex... flex
checking lex output file root... lex.yy
checking lex library... -lfl
checking whether yytext is a pointer... yes
checking for capable lex... yes
checking for bison... bison -y
checking for capable yacc/bison... yes
checking for x86-ranlib... no
checking for ranlib... ranlib
checking for x86-ar... no
checking for ar... ar
checking whether ln -s works... yes
checking for struct sockaddr.sa_len... no
checking for struct sockaddr_storage... yes
checking for dl_hp_ppa_info_t.dl_module_id_1... no
checking if unaligned accesses fail... no
checking for USB sniffing support... no
checking whether the platform could support netfilter sniffing... no
checking whether we can compile the netmap support... no
configure: no Bluetooth sniffing support implemented for none
checking for pkg-config... pkg-config
checking for D-Bus... yes
checking whether the D-Bus library defines dbus_connection_read_write... yes
checking for ibv_get_device_list in -libverbs... no
checking for a BSD-compatible install... /usr/bin/install -c
configure: creating ./config.status
config.status: creating Makefile
config.status: creating pcap-filter.manmisc
config.status: creating pcap-linktype.manmisc
config.status: creating pcap-tstamp.manmisc
config.status: creating pcap-savefile.manfile
config.status: creating pcap.3pcap
config.status: creating pcap_compile.3pcap
config.status: creating pcap_datalink.3pcap
config.status: creating pcap_dump_open.3pcap
config.status: creating pcap_get_tstamp_precision.3pcap
config.status: creating pcap_list_datalinks.3pcap
config.status: creating pcap_list_tstamp_types.3pcap
config.status: creating pcap_open_dead.3pcap
config.status: creating pcap_open_offline.3pcap
config.status: creating pcap_set_tstamp_precision.3pcap
config.status: creating pcap_set_tstamp_type.3pcap
config.status: creating rpcapd/Makefile
config.status: creating rpcapd/rpcapd.manadmin
config.status: creating testprogs/Makefile
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing default-1 commands
./config.status --file=libpcap.pc.tmp:./libpcap.pc.in
config.status: creating libpcap.pc.tmp
mv libpcap.pc.tmp libpcap.pc
chmod a+x libpcap.pc
./config.status --file=pcap-config.tmp:./pcap-config.in
config.status: creating pcap-config.tmp
mv pcap-config.tmp pcap-config
chmod a+x pcap-config
configure: WARNING: unrecognized options: --disable-ipv6
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86-unknown-none
checking for x86-gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether the compiler supports the -ffloat-store option... yes
checking for inline... inline
checking for __attribute__... yes
checking whether __attribute__((unused)) can be used without warnings... yes
checking whether __attribute__((noreturn)) can be applied to function pointers without warnings... yes
checking whether __attribute__((format)) can be used without warnings... yes
checking whether __attribute__((format)) can be applied to function pointers... yes
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking fcntl.h usability... yes
checking fcntl.h presence... yes
checking for fcntl.h... yes
checking rpc/rpc.h usability... yes
checking rpc/rpc.h presence... yes
checking for rpc/rpc.h... yes
checking rpc/rpcent.h usability... no
checking rpc/rpcent.h presence... no
checking for rpc/rpcent.h... no
checking netdnet/dnetdb.h usability... no
checking netdnet/dnetdb.h presence... no
checking for netdnet/dnetdb.h... no
checking for net/pfvar.h... no
checking for netinet/if_ether.h... yes
checking whether time.h and sys/time.h may both be included... yes
checking smi.h usability... no
checking smi.h presence... no
checking for smi.h... no
checking whether to enable the possibly-buggy SMB printer... yes
configure: WARNING: The SMB printer may have exploitable buffer overflows!!!
checking whether to drop root privileges by default... no
checking whether to chroot... no
checking for cap_enter... no
checking for cap_rights_limit... no
checking for cap_ioctls_limit... no
checking for openat... yes
checking whether to sandbox using capsicum... no
checking for library containing gethostbyname... none required
checking for library containing socket... none required
checking for library containing putmsg... none required
checking whether the operating system supports IPv6... yes
checking ipv6 stack type... linux-glibc
checking for dnet_htoa declaration in netdnet/dnetdb.h... no
checking for vfprintf... yes
checking for strlcat... no
checking for strlcpy... no
checking for strdup... yes
checking for strsep... yes
checking for getopt_long... yes
checking for fork... yes
checking for vfork... yes
checking for strftime... yes
checking for setlinebuf... yes
checking for alarm... yes
checking for vsnprintf... yes
checking for snprintf... yes
checking return type of signal handlers... void
checking for sigaction... yes
checking for library containing dnet_htoa... no
checking for main in -lrpc... no
checking for library containing getrpcbynumber... none required
checking for local pcap library... ../libpcap-1.9.0/libpcap.a
checking for pcap-config... ../libpcap-1.9.0/pcap-config
checking for pcap_loop... no
configure: error: This is a bug, please follow the guidelines in CONTRIBUTING and include the
config.log file in your report.  If you have downloaded libpcap from
tcpdump.org, and built it yourself, please also include the config.log
file from the libpcap source directory, the Makefile from the libpcap
source directory, and the output of the make process for libpcap, as
this could be a problem with the libpcap that was built, and we will
not be able to determine why this is happening, and thus will not be
able to fix it, without that information, as we have not been able to
reproduce this problem ourselves.
make: *** No targets specified and no makefile found.  Stop.

1 个答案:

答案 0 :(得分:0)

已解决。此脚本的编译输出文件应同时在x86x86_64上运行

export TCPDUMP=4.9.2
export LIBPCAP=1.9.0
tar zxvf tcpdump-$TCPDUMP.tar.gz
tar zxvf libpcap-$LIBPCAP.tar.gz
export CC=i686-linux-gnu-gcc
cd libpcap-$LIBPCAP
./configure --host=x86-linux --with-pcap=linux
make
cd ..

cd tcpdump-$TCPDUMP
export ac_cv_linux_vers=2
export CFLAGS=-static
export CPPFLAGS=-static
export LDFLAGS=-static

./configure --host=x86-linux
make