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 ~/armenv.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 

 

四. 测试

 

 

 
  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值