libpcap 交叉编译

本文研究在openwrt的路由器(基于ARM架构)上用libpcap采集数据包。

一. 安装ARM交叉编译环境

下载openwrt源码,编译时勾取 Build OpenWrt Toolchain。编译过程参见:http://tcspecial.iteye.com/blog/2280873 

二. 下载源码

libpcap只有同一套源码,支持嵌入式编译,没有单独的嵌入式版本。

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

三. 编译libpcap

3.1 设置交叉编译环境

因为libpcap是运行在路由器上的,因此要用arm-openwrt-linux-gcc 工具来编译。

#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

    注:MIPS平台,指定 --host=mips-openwrt-linux

出错提示:

configure: error: pcap type not determined when cross-compiling; use --with-pcap=...

方法一:添加--with-pcap参数,指定采集类型

./configure --prefix=/home/ubuntu/libpcap-arm --host=arm-openwrt-linux --with-pcap=linux

  

方法二:注释该段代码

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; }; }
#fi

  

make && make install 

四. 测试

猜你喜欢

转载自tcspecial.iteye.com/blog/2323731