tcpdump移植

4140阅读 0评论2014-04-10 猪也有春天
分类:LINUX

1、下载libpcap-0.9.8.tar.gztcpdump-3.9.8.tar.gz两个文件。(或上面发布的最新的文件)

2、解压。将文件拷入虚拟ubuntu系统

3、进入虚拟机ubuntu系统

4、进入libpcap-1.0.0目录,先终端将PATH环境变量做一个修改:
1)export PATH=/projects/hnd/tools/linux/hndtools-mipsel-linux-uclibc-4.2.3/bin:$PATH
/projects/hnd/tools/linux/hndtools-mipsel-linux-uclibc-4.2.3/bin是交叉编译工具存放的地方(当然也可以在.barhrc中添加)
2) 再执行./configure--host= mipsel-uclibc-linux26时会出现了一个错误: 
[root@olive libpcap-0.9.4]# ./configure --host=mipsel-uclibc-linux26
                       .........  
  configure: error: pcap type not determined when cross-compiling; use --with-pcap=...

运行configure说交叉编译时没指定pcap类型,采取暴力措施了,在configure脚本中注释掉检查交叉编译的部分,具体注释掉一下语句:vim 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  

     #  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

 再次运行configure命令,这下终于OK!终于生成了Makefile.接下来make:  

居然没生成动态链接库,只有一个libpcap.a静态库.只好再修改它的Makefile.打开Makefile,找到了下面这个目标:

从新make,执行如:make libpcap.so即可生成该动态文件libpcap.so.1.0.0

编译tcpdump

然后去到tcpdump-4.2.1下面,也是先
1)export PATH=/projects/hnd/tools/linux/hndtools-mipsel-linux-uclibc-4.2.3/bin:$PATH

2)打开configure文件修改如下

linux*)
 { echo "$as_me:$LINENO: checking Linux kernel version" >&5
echo $ECHO_N "checking Linux kernel version... $ECHO_C" >&6; }
  if test "$cross_compiling" = yes; then
   if test "${ac_cv_linux_vers+set}" = set; then
  echo $ECHO_N "(cached) $ECHO_C" >&6
else
  ac_cv_linux_vers=2.6
fi

3) 再执行./configure--host= mipsel-uclibc-linux26 ,生成Makefile (如果生成过程当中出现了错误,可以回到libpcap目录下执行make install命令)。

打开生成的Makefie,找到如下:


发现将libpcap-1.0.0定义在了该目录的上一个目录。

4)执行make即可。

最后生成了tcpdump文件,用file命令查看如下:

tcpdump: ELF 32-bit LSB executable, MIPS, MIPS32 version 1 (SYSV), dynamically linked (uses shared libs), not stripped

最后通过tftp命令将文件传到板子上去


上一篇:static inline内联函数
下一篇:linux中idr基本原理介绍