有老板子需要抓包,编译tcpdump
查看cpu和系统版本及libc版本, 确定交叉编译工具链,libc是4.5.2编译,在网上找4.9也是兼容的。
[root@M3352 ~]# cat /proc/cpuinfo
Processor : ARMv7 Processor rev 2 (v7l)
BogoMIPS : 795.44
Features : swp half thumb fastmult vfp edsp thumbee neon vfpv3 tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x3
CPU part : 0xc08
CPU revision : 2
Hardware : m3352
Revision : 0000
Serial : 0000000000000000
[root@M3352 ~]# uname -a
Linux M3352 3.2.0 #1 Wed Jul 5 03:32:13 CST 2017 armv7l GNU/Linux
# 查看GLIBc版本
[root@M3352 ~]# /lib/libc.so.6
GNU C Library (Sourcery G++ Lite 2011.03-41) stable release version 2.13, by Roland McGrath et al.
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.5.2.
Compiled on a Linux 2.6.38 system on 2011-04-15.
Available extensions:
crypt add-on version 2.1 by Michael Glad and others
GNU Libidn by Simon Josefsson
Native POSIX Threads Library by Ulrich Drepper et al
Support for some architectures added on, not maintained in glibc core.
BIND-8.2.3-T5B
libc ABIs: UNIQUE
For bug reporting instructions, please see:
<https://support.codesourcery.com/GNUToolchain/>.
配置编译工具4.9.4
wget https://releases.linaro.org/components/toolchain/binaries/4.9-2017.01/arm-linux-gnueabihf/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf.tar.xz
tar -xvf gcc-linaro-4.9.4-*.tar.xz
因为我还有64位工具链,就不配置到PATH,每次手动运行
export CXX=/home/wv/bin/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-c++
export CC=/home/wv/bin/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc
PATH=$PATH:/home/wv/bin/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin
arm-linux-gnueabihf-gcc -v # 查看版本及支持的架构
静态编译:单个文件libpcap打包到一起
# 改为使静态库编译
git clone https://github.com/the-tcpdump-group/libpcap
cd libpcap
git checkout libpcap-1.9
mkdir build-static && cd build-static
make distclean # 清理旧编译文件
../configure --host=arm-linux-gnueabi \
--prefix=$PWD/install \
--enable-static=yes \
--disable-shared \
--with-pcap=linux
make && make install
# 应存在此文件
ls install/lib/libpcap.a
git clone https://github.com/the-tcpdump-group/tcpdump
cd tcpdump
git checkout tcpdump-4.9
mkdir build-static && cd build-static
../configure --host=arm-linux-gnueabi \
--with-libpcap=../../libpcap/build-static/install \
CFLAGS="-I../../libpcap/build-static/install/include" \
LDFLAGS="-L../../libpcap/build-static/install/lib -static"
make
file tcpdump
tcpdump: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, for GNU/Linux 2.6.31, BuildID[sha1]=6fab3757bf05219fc6e8320fa12768fc896b2692, with debug_info, not stripped
# 上传开发板tcpdump就行,不用传libpcap
[root@M3352 ~]# ./tcpdump -D
1.eth0 [Up, Running]
2.lo [Up, Running, Loopback]
3.any (Pseudo-device that captures on all interfaces) [Up, Running]
4.can0 [none]
5.can1 [none]
6.usb0 [none]
7.eth1 [none]
在网上找都是动态编译,如下,编译正常,但运行报错
git clone https://github.com/the-tcpdump-group/libpcap
cd libpcap
git checkout libpcap-1.9
mkdir build
cd build
../configure --host=arm-linux --prefix=$PWD/install --with-pcap=linux
make && make install
git clone https://github.com/the-tcpdump-group/tcpdump
cd tcpdump
git checkout tcpdump-4.9
mkdir build
cd build
ln -s ../../libpcap/build/install/ libpcap
../configure --host=arm-linux CFLAGS="-I./libpcap/include/ -L./libpcap/lib/" --with-pcap=linux
make
file tcpdump
# 32位编译后
tcpdump: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.31, BuildID[sha1]=87b1ccd914c49d14420d8b174091d7f360a805ba, with debug_info, not stripped
# 上传tcpdump和libpcap.so.1
ln -s libpcap.so.1.9.1 libpcap.so.1
export LD_LIBRARY_PATH=./
./tcpdump --help
-sh: ./tcpdump: No such file or directory