This paper studies the use of libpcap to collect data packets on openwrt routers (based on ARM architecture).
1. Install the ARM cross-compilation environment
Download the openwrt source code and check Build OpenWrt Toolchain when compiling. For the compilation process, see: http://tcspecial.iteye.com/blog/2280873
2. Download the source code
libpcap only has the same set of source code, supports embedded compilation, and does not have a separate embedded version.
wget http://www.tcpdump.org/release/libpcap-1.4.0.tar.gz tar -xzvf libpcap-1.4.0.tar.gz cd libpcap-1.4.0
3. Compile libpcap
3.1 Setting up the cross-compilation environment
Because libpcap is running on the router, it should be compiled with the arm-openwrt-linux-gcc tool.
#armenv.sh Workdir=~/openwrt-arm export STAGING_DIR=${Workdir}/bin export PATH=${Workdir}/bin:$PATH export CROSS_COMPILE=arm-openwrt-linux- export CROSS_PREFIX=arm-openwrt-linux- export CC=${CROSS_PREFIX}gcc export STRIP=${CROSS_PREFIX}strip export AR=${CROSS_PREFIX}ar export RANLIB=${CROSS_PREFIX}ranlib export OBJCOPY=${CROSS_PREFIX}objcopy
source ~/mipsenv.sh ./configure --prefix=/home/ubuntu/libpcap-arm --host=arm-openwrt-linux
Note: MIPS platform, specify --host=mips-openwrt-linux
Error message:
configure: error: pcap type not determined when cross-compiling; use --with-pcap=...
Method 1: Add the --with-pcap parameter to specify the collection type
./configure --prefix=/home/ubuntu/libpcap-arm --host=arm-openwrt-linux --with-pcap=linux
Method 2: Comment the code
Line 7210
vi configure #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; }; } #be
make && make install
4. Test