libpcap向嵌入式Linux的移植过程


解决了一个关于嵌入式移植的问题,发现Linux真是一个可移植性很强的OS,希望今年能静心将此做为重点学习对象。

移植的对象是libpcap,数据包捕获库,可以到www.tcpdump.org下载最新版本,主要目标是实现在嵌入式linux系统下进行数据捕获,下面写写移植过程吧

1. 安装编译器:cross-2.95.3.tar.bz2,并解压至/usr/local/arm目录下
2. 声明环境变量:export PATH=/usr/local/arm/2.95.3/bin:$PATH
3. 解压libpcap-0.9.5.tar.gz,cd进入目录,修改confiugre文件,把下面两段注释掉
 #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
  .......
 #  if test $ac_cv_linux_vers = unknown ; then
 #   { { echo "$as_me:$LINENO: error: cannot determine linux version when cross-compiling" >&5
 #echo "$as_me: error: cannot determine linux version when cross-compiling" >&2;}
 #   { (exit 1); exit 1; }; }
 #  fi
4. 执行./configure --host=arm-linux,这样就会使用arm-linux-gcc进行configure,生成Makefile
5. 修改Makefile的prefix项为prefix=/usr/local/arm/2.95.3/arm-linux,同时注意查看Makefile中的CC项,已经为arm-linux-gcc了,呵呵。
6. 接下来make,make install,完成了libpcap的编译和安装,查看/usr/local/arm/2.95.3/arm-linux/include,该目录下增加了三个pcap的文件库
7. 利用get_packet_code.c这个小程序进行测试,arm-linux-gcc -o aaa get_packet_code.c -lpcap,编译成功,用命令#file aaa,查看文件类型,显示适用于arm,成功!

最后用minicom的方式运行可执行文件aaa,能够捕包咯。

相关内容