当前位置: 首页 > news >正文

交叉编译tcpdump静态编译单个文件

有老板子需要抓包,编译tcpdump

查看cpu和系统版本及libc版本, 确定交叉编译工具链,libc是4.5.2编译,在网上找4.9也是兼容的。

[root@M3352 ~]# cat /proc/cpuinfo
Processor       : ARMv7 Processor rev 2 (v7l)
BogoMIPS        : 795.44
Features        : swp half thumb fastmult vfp edsp thumbee neon vfpv3 tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x3
CPU part        : 0xc08
CPU revision    : 2Hardware        : m3352
Revision        : 0000
Serial          : 0000000000000000[root@M3352 ~]# uname -a
Linux M3352 3.2.0 #1 Wed Jul 5 03:32:13 CST 2017 armv7l GNU/Linux# 查看GLIBc版本
[root@M3352 ~]# /lib/libc.so.6
GNU C Library (Sourcery G++ Lite 2011.03-41) stable release version 2.13, by Roland McGrath et al.
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.5.2.
Compiled on a Linux 2.6.38 system on 2011-04-15.
Available extensions:crypt add-on version 2.1 by Michael Glad and othersGNU Libidn by Simon JosefssonNative POSIX Threads Library by Ulrich Drepper et alSupport for some architectures added on, not maintained in glibc core.BIND-8.2.3-T5B
libc ABIs: UNIQUE
For bug reporting instructions, please see:
<https://support.codesourcery.com/GNUToolchain/>.

配置编译工具4.9.4

wget https://releases.linaro.org/components/toolchain/binaries/4.9-2017.01/arm-linux-gnueabihf/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf.tar.xz
tar -xvf gcc-linaro-4.9.4-*.tar.xz

因为我还有64位工具链,就不配置到PATH,每次手动运行

export CXX=/home/wv/bin/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-c++
export CC=/home/wv/bin/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc
PATH=$PATH:/home/wv/bin/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/binarm-linux-gnueabihf-gcc -v  # 查看版本及支持的架构

静态编译:单个文件libpcap打包到一起

# 改为使静态库编译
git clone https://github.com/the-tcpdump-group/libpcap
cd libpcap
git checkout libpcap-1.9
mkdir build-static && cd build-static
make distclean  # 清理旧编译文件
../configure --host=arm-linux-gnueabi \--prefix=$PWD/install \--enable-static=yes \--disable-shared \--with-pcap=linux
make && make install# 应存在此文件
ls install/lib/libpcap.a  git clone https://github.com/the-tcpdump-group/tcpdump
cd tcpdump
git checkout tcpdump-4.9
mkdir build-static && cd build-static
../configure --host=arm-linux-gnueabi \--with-libpcap=../../libpcap/build-static/install \CFLAGS="-I../../libpcap/build-static/install/include" \LDFLAGS="-L../../libpcap/build-static/install/lib -static"
make        file tcpdump
tcpdump: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, for GNU/Linux 2.6.31, BuildID[sha1]=6fab3757bf05219fc6e8320fa12768fc896b2692, with debug_info, not stripped# 上传开发板tcpdump就行,不用传libpcap
[root@M3352 ~]# ./tcpdump -D
1.eth0 [Up, Running]
2.lo [Up, Running, Loopback]
3.any (Pseudo-device that captures on all interfaces) [Up, Running]
4.can0 [none]
5.can1 [none]
6.usb0 [none]
7.eth1 [none]

在网上找都是动态编译,如下,编译正常,但运行报错

git clone https://github.com/the-tcpdump-group/libpcap
cd libpcap
git checkout libpcap-1.9
mkdir build
cd build
../configure --host=arm-linux  --prefix=$PWD/install --with-pcap=linux
make && make installgit clone https://github.com/the-tcpdump-group/tcpdump
cd tcpdump
git checkout tcpdump-4.9
mkdir build
cd build
ln -s ../../libpcap/build/install/ libpcap
../configure --host=arm-linux CFLAGS="-I./libpcap/include/ -L./libpcap/lib/" --with-pcap=linux
make
file tcpdump# 32位编译后
tcpdump: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.31, BuildID[sha1]=87b1ccd914c49d14420d8b174091d7f360a805ba, with debug_info, not stripped# 上传tcpdump和libpcap.so.1
ln -s libpcap.so.1.9.1 libpcap.so.1
export LD_LIBRARY_PATH=./
./tcpdump --help
-sh: ./tcpdump: No such file or directory

相关文章:

  • DHCP 服务器运行流程图
  • NHANES指标推荐:BUCR
  • uniapp-商城-40-shop 购物车 选好了 进行订单确认4 配送方式3 地址编辑
  • Spring_MVC 中的 JSON 数据处理与 REST 风格开发
  • 图论---最大流(Dinic)
  • Lua 第11部分 小插曲:出现频率最高的单词
  • 《MySQL 技术内幕-innoDB 存储引擎》笔记
  • 顶会招牌idea:机器学习+组合优化 优秀论文合集
  • 博物馆除湿控湿保卫战:M-5J1R 电解除湿科技如何重塑文物守护的未来
  • 服务器数据备份,服务器怎么备份数据呢?
  • 现代多核调度器的本质 调度三重奏
  • 设计模式--桥接模式详解
  • 1.1 道路结构特征
  • 驱动开发硬核特训 · Day 22(上篇): 电源管理体系完整梳理:I2C、Regulator、PMIC与Power-Domain框架
  • c++多线程初识
  • apkpure 谷歌插件 下载的apk包
  • RISC-V MCU定时器架构与低功耗设计
  • OpenStack私有云详细介绍
  • 洞悉 NGINX ngx_http_access_module基于 IP 的访问控制实战指南
  • Linux 在个人家目录下添加环境变量 如FLINK_PROPERTIES=“jobmanager.rpc.address: jobmanager“
  • 4月份全国93个国家气象站日最高气温达到或突破极值
  • 伊朗港口爆炸已致40人死亡
  • 这场迪图瓦纪念拉威尔的音乐会,必将成为乐迷反复品味的回忆
  • 加拿大温哥华一车辆冲撞人群,造成多人伤亡
  • 伊朗外长:美伊谈判进展良好,讨论了很多技术细节
  • 临沂文旅集团被诉侵权,原告每年三百余起类案