tcpdump抓包时,如果-i选项指定为一个网卡地址,那么抓取的数据包数据链路层是以太网头部;如果指定any,则以太网头部将被替换为linux cooked capture头部

 # tcpdump -i any -w linux_sll.pcap
tcpdump: listening on any, link-type LINUX_SLL (Linux cooked), capture size bytes
 # tcpdump -i eth1 -w enet.pcap
tcpdump: listening on eth1, link-type EN10MB (Ethernet), capture size 96 bytes

tcpdump抓包时可以通过 -y 选项来指定data link type,不过测试发现 -i 选项指定 any 时,不支持抓获的包的data link type 为以太网 :

 # tcpdump -i any -w test.pcap -y EN10MB
tcpdump: EN10MB is not one of the DLTs supported by this device
# tcpdump -i eth1 -w test.pcap -y EN10MB
tcpdump: data link type EN10MB
#

这时,若需要将linux cooked capture格式的包转换为Ethernet格式,有那么几种方法:

1. 写代码读出每一个包后再改写到新文件(使用libpcap或者基于pcap头部结构体偏移);

2. tcpdump 3.0+ 版本下,可以用tcprewrite直接改写,这应该是最快捷的方法;

DLT Plugins
As of 3.0, tcprewrite uses plugins to support different DLT/Layer 2 types. This not only makes the
code easier to maintain, but also helps make things clearer for users regarding what is and isn't
supported. Each plugin may support reading and/or writing packets. By default, the plugin used to
read packets is also used for output, but you can override the output plugin using the --dlt option.
Changing the DLT plugin allows you to convert the packets from one DLT/Layer 2 type to another type.
This allows you for example to capture traffic on say an Ethernet interface and replay over Cisco
HDLC or capture on a BSD Loopback interface and replay over Ethernet. Plugins supported in output mode: Ethernet (enet)
Cisco HDLC (hdlc)
User defined Layer 2 (user)
Plugins supported in input mode: Ethernet
Cisco HDLC
Linux SLL
BSD Loopback
BSD Null
Raw IP
802.11
Juniper Ethernet (version >= 4.0)
Hence, if you have a pcap in one of the supported input DLT types, you can convert it to one of the
supported output DLT type by using the --dlt=<output> option. Depending on the input DLT you may
need to provide additional DLT plugin flags.

tcprewrite转换命令如下:

 # tcpdump -r linux_sll.pcap
reading from file linux_sll.pcap, link-type LINUX_SLL (Linux cooked)
# tcprewrite --dlt=enet --infile=linux_sll.pcap --outfile=enet.pcap
# tcpdump -r enet.pcap
reading from file enet.pcap, link-type EN10MB (Ethernet)
#

唯一有点问题的,是转换后的数据的Destination-Mac为空, 对这个字段有需求的要注意下:

可以参考的网址:

https://wiki.wireshark.org/SLL

http://www.tcpdump.org/linktypes.html

http://tcpreplay.synfin.net/wiki/tcprewrite

其它:

# tips 删除vlan
# tcprewrite --enet-vlan=del --infile=enet.pcap --outfile=output.pcap

  

Linux cooked-mode capture 格式转换的更多相关文章

  1. linux环境下deb格式 转换成rpm格式

    linux环境下deb格式 转换成rpm格式 使用alien工具转换deb格式到rpm格式 alien_8.87.tar.gz 下载alien_8.87.tar.gz [root@mysqlnode2 ...

  2. Linux基础命令---文本格式转换expand,unexpand

    expand 将文件中的tab转换成空格,结果送到标准输出.如果没有指定文件,那么从标准输入读取. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.openSUSE.F ...

  3. Linux基础命令---文本格式转换fmt

    fmt 将指定文件的内容,按照指定的格式重新排版,结果送到标准输出. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.openSUSE.Fedora. 1.语法     ...

  4. linux命令实现音频格式转换和拼接

    安装FFmpeg flaceric@ray:~$ sudo apt install FFmpeg flac 安装lame faaceric@ray:~$ sudo apt install lame f ...

  5. Linux - 文本格式转换

    文本文档格式查看 Linux下的文档格式查看方法 cat -A <filename> | grep "^M$", 如果存在^M$字符就是Dos格式. Windows下的 ...

  6. Linux下时间格式转换及获取方法

    Linux下使用clock_gettime给程序计时 #include <stdio.h> #include <unistd.h> #include <stdlib.h& ...

  7. 使用notepad++进行格式转换

    由于历史原因,导致Windows.Unix/Linux.Mac三者之间,对于文本中所用回车换行符,表示的方法,都不一样.这就导致了很多人都会遇到回车换行符的困惑,同时需要在不同格式间进行转换. 1)查 ...

  8. Linux下常见音频格式之间的转换方法

    Linux下常见音频格式之间的转换方法[转] 下面简单介绍下Linux环境常见音频格式之间的转换方法: MP3 相关工具: lameOGG 相关工具: vorbis-toolsAPE 相关工具: ma ...

  9. calibre,完成对各种格式的电子书籍的管理和格式转换及同步

    Calibre是免费的电子书制作.阅读软件,源代码开放,拥有跨平台的设计,支持多个基于不同系统的便携式移动设备,包括苹果iPhone.Amazon电子书等设备.它是一个完整的电子图书馆,包括图书馆管理 ...

随机推荐

  1. bootstarp v3 学习简记

    1.快速设置浮动通过这两个class让页面元素左右浮动. !important被用来避免某些问题. <div class="pull-left">...</div ...

  2. C#中 property 与 attribute的区别?

    C#中 property 与 attribute的区别?答:attribute:自定义属性的基类;property :类中的属性

  3. hdu_4944_FSF’s game

    FSF has programmed a game. In this game, players need to divide a rectangle into several same square ...

  4. 大数据学习(一) | 初识 Hadoop

    作者: seriouszyx 首发地址:https://seriouszyx.top/ 代码均可在 Github 上找到(求Star) 最近想要了解一些前沿技术,不能一门心思眼中只有 web,因为我目 ...

  5. java中的构造方法(2013-05-05-bd 写的日志迁移

    特点: 1.方法名和类名相同 2.没有返回值 3.在创建一个类的新对象时,系统会自动的调用该类的构造方法完成对新对象的初始化 一个类中可以定义多个不同构造方法: 如果程序员没有定义构造方法,系统能够会 ...

  6. Linux相关常用命令

    1.XShell中上传文件命令 首先需要安装rz文件上传工具: yum -y install lrzsz 然后执行以下命令,可打开本地系统的选择文件窗口:(或者直接把本地的文件拖动到SSH Shell ...

  7. Codeforces Round #458C DP

    C. Travelling Salesman and Special Numbers time limit per test 1 second memory limit per test 256 me ...

  8. C语言进阶——enum, sizeof, typedef 分析11

    枚举类型的使用方法: enum是C语言的 一种自定义类型 enum值是可以根据需要自定义的整型值 第一个enum的值默认为0 默认情况下的enum值是在前一个定义值的基础上加 1 enum类型的变量只 ...

  9. [Codeforces958C2]Encryption (medium)(区间DP)

    Description 题目链接 Solution 显然的区间DP,正常想法f[i][j]表示前i个数分成j块,每次在i前找一个k使得balala,然而常规打法会超时 我们发现,对于i前面的所有点,他 ...

  10. 正则表达式,regular expression, regex, RE

    正则表达式是用来简洁表达一组字符串的表达式 正则表达式可以用来判断某字符串的特征归属