c++解析wireshark中的rtp包
来源:互联网 发布:免费外汇交易软件 编辑:程序博客网 时间:2024/06/05 04:00
1.使用wireshark抓取rtp的包,点击一下你要解析的某一个包,然后点击左上角的“文件”-->“导出分组解析结果”-->“As JSON”-->选择"select packet"-->点击"保存"
2.现在打开保存的json文件可以看到对应的信息,比如rtp的传输内容的信息,包头的信息等。c++具体操作为:通过c++获取文件操作,先把json文件中的数据读取到一个string字符串中,使用jsoncpp或者poco库中的json来解析,博主使用的是poco的库,在使用时需要先把json文件的最前面和最后面的'[' ']'删除掉才可以解析,因为这个我找了很久程序崩溃的问题。
下面给出程序,需要poco库的支持,大家可以学习一下
util.h
#pragma once#include <iostream>#include <fstream>#include <string>#include <Poco/File.h>#include <Poco/FileStream.h>#include <Poco/FileStream_WIN32.h>#include <Poco/JSON/Parser.h>#include <Poco/JSON/ParseHandler.h>#include <Poco/JSON/Query.h>#include <Poco/JSON/Object.h>#include <Poco/Dynamic/Var.h>#include <Poco/Util/JSONConfiguration.h>#include <Poco/AutoPtr.h>#include <Poco/Util/Application.h>using Poco::File;using Poco::FileStream;using Poco::FileInputStream;using Poco::FileStreamBuf;using Poco::Dynamic::Var;using Poco::JSON::Parser;using Poco::JSON::ParseHandler;using Poco::JSON::Query;using Poco::JSON::Object;using Poco::Util::JSONConfiguration;using Poco::AutoPtr;using Poco::Util::Application;
resolve_rtp.h
#pragma once#include "util.h"struct RTP_Header{unsigned __int16 csrc_count;unsigned __int16 extension;unsigned __int16 padding;unsigned __int16 version;unsigned __int16 payloadtype;unsigned __int16 marker;unsigned __int16 seq;unsigned __int32 timestamp;unsigned __int32 ssrc;};class ResolveRtp{public:ResolveRtp(std::string &path):_filePath(path){ReadJson();GetRtpHeaderInfo();}RTP_Header GetRtpHeader(){return _rtpHeader;}private:void GetRtpHeaderInfo();void ReadJson();int GiveKeyGetVal(std::vector<std::string> nameVec, std::string name);std::string GetVal(std::vector<std::string> &nameVec);private:std::string _filePath;Object::Ptr _object;RTP_Header _rtpHeader;};
main.cpp
#include "resolve_rtp.h"int main(){std::string filePath("C:/Users/CC000033/Desktop/test.json");ResolveRtp resRtp(filePath);RTP_Header header = resRtp.GetRtpHeader();return 0;}
resolve_rtp.cpp
#include "resolve_rtp.h"#include <Poco/FileStream.h>#include <fstream>void ResolveRtp::ReadJson(){Parser parser;std::string content;FILE *stream;std::ifstream infile;infile.open(_filePath); //将文件流对象与文件连接起来 std::string s;while (getline(infile, s)){content += s;}infile.close(); //关闭文件输入流 parser.parse(content);Var result = parser.result();_object = result.extract<Object::Ptr>();}std::string ResolveRtp::GetVal(std::vector<std::string> &nameVec){std::string val;int vecSize = 0;Object::Ptr tmpObj = _object;Var res;vecSize = nameVec.size();for (int i = 0; i < vecSize; ++i){std::string &name = nameVec[i];res = tmpObj->get(name);if (i != vecSize - 1){tmpObj = res.extract<Object::Ptr>();}}val = res.convert<std::string>();return val;}void ResolveRtp::GetRtpHeaderInfo(){std::vector<std::string> nameVec;nameVec.push_back("_source");nameVec.push_back("layers");nameVec.push_back("rtp");_rtpHeader.version = GiveKeyGetVal(nameVec, "rtp.version");_rtpHeader.csrc_count = GiveKeyGetVal(nameVec, "rtp.cc");_rtpHeader.extension = GiveKeyGetVal(nameVec, "rtp.ext");_rtpHeader.padding = GiveKeyGetVal(nameVec, "rtp.padding");_rtpHeader.payloadtype = GiveKeyGetVal(nameVec, "rtp.payload");_rtpHeader.marker = GiveKeyGetVal(nameVec, "rtp.marker");_rtpHeader.seq = GiveKeyGetVal(nameVec, "rtp.seq");_rtpHeader.timestamp = GiveKeyGetVal(nameVec, "rtp.timestamp");_rtpHeader.ssrc = GiveKeyGetVal(nameVec, "rtp.ssrc");}int ResolveRtp::GiveKeyGetVal(std::vector<std::string> nameVec, std::string name){nameVec.push_back(name);std::string str = GetVal(nameVec);return atoi(str.data());}
阅读全文
0 0
- c++解析wireshark中的rtp包
- Wireshark提取RTP包中的H264码流
- wireshark解析rtp协议,流媒体中的AMR/H263/H264包的方法
- wireshark解析rtp协议,流媒体中的AMR/H263/H264包的方法
- wireshark解析rtp协议,流媒体中的AMR/H263/H264包的方法
- wireshark解析rtp协议,流媒体中的AMR/H263/H264包的方法
- wireshark解析rtp协议,流媒体中的AMR/H263/H264包的方法
- Wireshark将udp包作为rtp包解析
- wireshark识别RTP包
- wireshark抓取rtp包
- wireshark 还原语音包 RTP
- wireshark 还原语音包 RTP
- 使用wireshark检测RTP丢包问题
- Wireshark抓取RTP包,还原语音
- wireshark解析流媒体中的AMR/H263/H264包的方法
- webrtc中的rtp解析
- RTP 包格式 详细解析
- RTP 包格式 详细解析
- 面试知识点详解总结
- 1153: 简易版最长序列
- oracle数据库导入导出
- 3.HTML横排导航列表
- hdu 6050 Funny Function (构造矩阵)
- c++解析wireshark中的rtp包
- 重用其他程序库
- C++11介绍
- Maven web项目通过插件实现热部署到Tomcat
- HDU 5955 Guessing the Dice Roll AC自动机 高斯消元
- 一个输入框限定最多输入两位小数
- 1039. Course List for Student (25)
- 图片预加载的方法
- vb.net 教程 12-3 HtmlElement类 3