本文主要记录tcpdump,一个linux平台的抓包工具在arm平台上的编译方法,不涉及其使用。
下载tcpdump工具,地址:http://www.tcpdump.org/
需要下载2个压缩包:
libpcap-1.4.0.tar.gz
tcpdump-4.4.0.tar.gz
一、编译libpcap(如flex、bison等必要工具,不列举出来)
1、配置
$ ./configure --prefix=/home/latelee/bin/tcpdumptools/libpcap --host=arm-linux CC=arm-arago-linux-gnueabi-gcc
configure出错,信息如下:
configure: error: pcap type not determined when cross-compiling; use --with-pcap=...
解决方法:找到configure文件,注释如下内容:
# comment by latelee
#if test -z "$with_pcap" && test "$cross_compiling" = yes; then
# { { echo "$as_me:$LINENO: error: pcap type not determined when cross-compiling; use --with-pcap=..." >&5
#echo "$as_me: error: pcap type not determined when cross-compiling; use --with-pcap=..." >&2;}
# { (exit 1); exit 1; }; }
#fi
继续用上述的configure配置,无问题。
2、编译安装
$ make;make install
得到的库的头文件及库在/home/latelee/bin/tcpdumptools/libpcap中,编译tcpdump要使用到。
二、编译tcpdump
1、配置
配置有2种方式,建议使用第1种,省事很多。
// 使用静态库,无须libpcap动态库。
./configure --prefix=/home/latelee/bin/tcpdumptools/tcpdump --disable-ipv6 CC=arm-arago-linux-gnueabi-gcc --host=arm-linux CFLAGS='-I/home/latelee/bin/tcpdumptools/libpcap/include' LDFLAGS='-L/home/latelee/bin/tcpdumptools/libpcap/lib/libpcap.a'
// 使用动态库,须将libpcap放到库目录路径中
./configure --prefix=/home/latelee/bin/tcpdumptools/tcpdump --disable-ipv6 CC=arm-arago-linux-gnueabi-gcc --host=arm-linux CFLAGS='-I/home/latelee/bin/tcpdumptools/libpcap/include' LDFLAGS='-L/home/latelee/bin/tcpdumptools/libpcap/lib' LIBS='-lpcap'
同样,configure会出错,如下:
configure: error: cannot determine linux version when cross-compiling
解决方法:修改configure文件,注释如下内容:
# comment by latelee
# if test $ac_cv_linux_vers = unknown ; then
# as_fn_error $? "cannot determine linux version when cross-compiling" "$LINENO" 5
# fi
继续用上述的configure配置,无问题。
2、编译安装
$ make;make install
得到的tcpdump工具在tcpdumptools/tcpdump/sbin目录下。
附:
1、交叉编译这么多的工具,第一次遇到在configure这一步出错的情况,不知是自己在使用上出问题,还是其本身的问题。无论如何,终归是可以正常编译通过了。
2、如有人参考本文,请务必将路径及交叉编译器修改成自己的。