嵌入式 arm 中抓包:tcpdump移植

版权声明:本文为博主原创文章,欢迎转载,请尊重原创,转载注明链接。 https://blog.csdn.net/qqliyunpeng/article/details/81367707

1. 简介

    在网络编程中经常设计到网络数据的抓取,在linux和windows下有好用的wireshark,在arm中有tcpdump,tcpdump通过生成数据包的文件,通过ftp下载到windows或者linux下,再采用wireshark打开文件进行分析。这便是这篇文章要介绍的。


2. 移植

2.1 在编译环境中安装libpcap

libpcap 的源码在 tcpdump官网

我使用的是最新版本libpcap-1.9.0

在解压的文件夹里建立将要安装的文件夹install

> cd libpcap-1.9.0

> mkdir install

配置编译选项

> ./configure --prefix=[文件路径]/libpcat-1.9.0/install --host=arm-linux --CC=[用户交叉编译的工具]

> make

> make install

在执行配置的时候,你可能遇到如下错误

configure: error: Neither flex nor lex was found.

需要安装下flex bison

> sudo apt-get install flex bison

2.2 交叉编译tcpdump

源码下载依然在 tcpdump官网

> cd tcpdump-4.9.2

>mkdir install

> ./configure --prefix=[文件路径]/libpcat-1.9.0/install --host=arm-linux --CC=[用户交叉编译的工具]

> make

> make install

将install中相应的文件拷贝到arm中,即可运行,运行依赖 libcrypto.so.1.0.0 库文件,需要文件系统中含有。

3. 使用

抓包保存到文件的命令是 -w xxx.cap

3.1 如果想要抓 eth0 的包

> tcpdump -i eth0 -w xxx.cap

3.2 抓 eth0 上来自于192.168.1.98 的包

> tcpdump -i eth0 host 192.168.1.98 -w xxx.cap

3.3 抓192.168.1.123的80端口的包

> tcpdump -i eth0 host 192.168.1.98 and port 80 -w xxx.cap 

3.4 抓192.168.1.123的icmp的包

> tcpdump -i eth0 host 192.168.1.98 and icmp -w xxx.cap 

3.5 抓192.168.1.98的80端口和110和25以外的其他端口的包

> tcpdump -i eth0 host 192.168.1.98 and ! port 80 and ! port 25 and ! port 110 -w /tmp/xxx.cap

抓下来的文件可用直接用wireshark打开。

猜你喜欢

转载自blog.csdn.net/qqliyunpeng/article/details/81367707