windows pcapng文件抽出udp负载

news/2024/5/18 15:29:42 标签: udp, 网络协议, 网络
  • wireshark收下的流是pcapng格式的,需要另存为pcap格式
  • 依赖Npcap SDK
  • 不同的需求抽取负载的方法不同,主要是负载的起始位置不同

我的需求:UDP传输,端口为10005,绑定的IP为192.168.178.1
所以设置过滤器"host 192.168.178.1 and udp port 9000"

#define RTP_HEAD_LEN  (12)

#define ipFrameFrontLen  (16 * 2 + 8 + 2)  //UDP负载开始位置


/* 4 bytes IP address */
typedef struct ip_address
{
	u_char byte1;
	u_char byte2;
	u_char byte3;
	u_char byte4;
}ip_address;

/* IPv4 header */
typedef struct ip_header
{
	u_char	ver_ihl;		// Version (4 bits) + Internet header length (4 bits)
	u_char	tos;			// Type of service 
	u_short tlen;			// Total length 
	u_short identification; // Identification
	u_short flags_fo;		// Flags (3 bits) + Fragment offset (13 bits)
	u_char	ttl;			// Time to live
	u_char	proto;			// Protocol
	u_short crc;			// Header checksum
	ip_address	saddr;		// Source address
	ip_address	daddr;		// Destination address
	u_int	op_pad;			// Option + Padding
}ip_header;

int main()
{
	pcap_t* fp;
	char errbuf[
	PCAP_ERRBUF_SIZE];
	//打开Pcap包
	if ((fp = pcap_open_offline(1.pcap”, errbuf)) == NULL)
	{
		return 1;
	}
	std::string packet_filter = "host 192.168.178.1 and udp port 9000"; //过滤(源IP:172.16.21.174且端口8080)
	struct bpf_program fcode;	// used in pcap_compile()
	if (pcap_compile(fp, &fcode, packet_filter.c_str(), 1, 0) >= 0)
	{
		//设置过滤器
		if (pcap_setfilter(fp, &fcode) < 0)
		{
			fprintf(stderr, "\nError setting the filter.\n");
			return 1;
		}
	}
	else
	{
		fprintf(stderr, "\nError setting the filter.\n");
		return 1;
	}
	//读取文件直到结尾
	struct pcap_pkthdr* header;		//报文头
	const unsigned char* pkt_data;	//报文内容
	ip_header* ih;
	int read_count = 0;


	while ((pcap_next_ex(fp, &header, &pkt_data)) > 0)
	{
  		memcpy(buffer, &pkt_data[ipFrameFrontLen], header->caplen- ipFrameFrontLen);
  		//buff 就是RTP数据
		Sleep(1);
	}
	pcap_close(fp);
}
	

http://www.niftyadmin.cn/n/628230.html

相关文章

链表中倒数第k个节点

题目描述 输入一个链表&#xff0c;输出该链表中倒数第k个结点。 代码实现&#xff08;Java&#xff09; /* public class ListNode {int val;ListNode next null;ListNode(int val) {this.val val;} }*/ public class Solution {public ListNode FindKthToTail(ListNode …

jrebel热部署不起作用_阿里原来是这么干的!Spring Boot 五种热部署方式

作者&#xff1a;若离x来源&#xff1a;my.oschina.net/ruoli/blog/15901481、模板热部署在 Spring Boot 中&#xff0c;模板引擎的页面默认是开启缓存的&#xff0c;如果修改了页面的内容&#xff0c;则刷新页面是得不到修改后的页面的&#xff0c;因此我们可以在application.…

一些比较好的博客归纳和自己遇到的一些问题 -ffmpeg

雷霄骅 RTSP–雷霄骅 ffmpeg官方例子 ffmpeg官方文档 声网开发者文档 x264参数 H.264码流结构 云天之巅的音视屏教程 QTFFMPEG4.3.1环境搭建 windows使用QTCreator开发的QT程序移植到Ubuntu18&#xff0c;以及打包发布 时间戳 裸H264流时间戳问题 ffmpeg windows从…

有两个python怎么停用其中一_python如何停止递归

首先&#xff0c;在递归函数之外定义一个全局变量&#xff1a;isGo&#xff0c;布尔型&#xff0c;初始值为真&#xff0c;意思是可以继续循环。 接着&#xff0c;在递归循环的一开始就设置判断机制&#xff0c;一旦isGo的值为假&#xff0c;就层层阻止&#xff0c;直到退出所有…

QT字符串

文章目录QTCreator使用MSVC中文乱码问题QString和QByteArray互转1.QString 转QByteArray2.**QByteArray转QString****3.QString和int互转****4.char*转string****5.char数组转QByteArray****6.QByteArray 转十六进制QString****7.十六进制QString转QByteArray**QString转十六进…

公众号菜单 点击推送图片素材_公众号菜单食用指南

自上一次更新公众号菜单栏已经过去半年&#xff0c;不知道是因为懒还是懒还是懒……不过最近&#xff0c;我们把发布过的210篇文章洗牌规整&#xff0c;呈现出一个最新版本。什么回顾没有及时更新啊、前几季宣传片找不到、志愿者招募内容等等&#xff0c;多种“疑难杂症”一并给…

没知识真可怕——应用密码学的笑话之MD5+Salt不安全

看到一篇很有意思的文章&#xff0c;故转载之。 原博地址&#xff1a;http://blog.sina.com.cn/s/blog_77e8d1350100wfc7.html 这段时间诸多爆库的新闻&#xff0c;里面有许多饶有趣味的事情。那些用简单密码&#xff0c;或者一个密码走天下的笑话就不说了&#xff0c;咱说点有…

php 未定义数组索引_PHP 命名空间与spl_autoload_register() 自动加载机制(仅学习)...

原链接&#xff1a;PHP 命名空间与spl_autoload_register() 自动加载机制include 和 require 是PHP中引入文件的两个基本方法。在小规模开发中直接使用 include 和 require 但在大型项目中会造成大量的 include 和 require 堆积。这样的代码既不优雅&#xff0c;执行效率也很低…