{"id":371,"date":"2025-08-12T00:03:41","date_gmt":"2025-08-11T16:03:41","guid":{"rendered":"http:\/\/yangnanbei.top\/?p=371"},"modified":"2025-08-17T16:52:53","modified_gmt":"2025-08-17T08:52:53","slug":"nbeasytshark%e5%bc%80%e5%8f%91%e8%ae%b0%e5%bd%95-01","status":"publish","type":"post","link":"http:\/\/yangnanbei.top\/index.php\/2025\/08\/12\/nbeasytshark%e5%bc%80%e5%8f%91%e8%ae%b0%e5%bd%95-01\/","title":{"rendered":"nbEasyTshark 01-04 \u4ece\u73af\u5883\u914d\u7f6e\u5f00\u59cb~"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">01 \u6982\u8ff0<\/h2>\n\n\n\n<p>\u57fa\u4e8etshark, cpp\u5f00\u53d1\u7c7bwireshark\u8f6f\u4ef6 nbEasyTshark<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Wireshark\u4e3b\u8981\u7279\u70b9\uff1a<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u652f\u6301\u4e09\u5343\u591a\u79cd\u534f\u8bae\u6df1\u5ea6\u89e3\u6790<\/li>\n\n\n\n<li>\u5b9e\u65f6\u6355\u83b7\u548c\u79bb\u7ebf\u5206\u6790<\/li>\n\n\n\n<li>\u5f3a\u5927\u7684\u8fc7\u6ee4\u529f\u80fd \uff08Display Filter\u3001Capture Filter\uff09<\/li>\n\n\n\n<li>\u652f\u6301\u6d41\u5206\u6790\uff08FollowStream\uff09<\/li>\n\n\n\n<li>\u652f\u6301\u591a\u79cd\u64cd\u4f5c\u7cfb\u7edf\uff08Windows\u3001Linux\u3001macOS\uff09<\/li>\n<\/ul>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>tshark\u547d\u4ee4\u7ec3\u4e60\n<ol class=\"wp-block-list\">\n<li>\u4f7f\u7528 <code>tshark -D<\/code> \u679a\u4e3e\u4f60\u7684\u7f51\u7edc\u63a5\u53e3\u3002<\/li>\n\n\n\n<li>\u9009\u62e9\u5408\u9002\u7684\u7f51\u5361\u63a5\u53e3\u5e76\u6293\u53d61000\u4e2a\u6570\u636e\u5305\uff08\u63d0\u793a\uff1a\u4f7f\u7528 <code>-c 1000<\/code> \u53c2\u6570\u9650\u5236\u6293\u5305\u6570\u91cf\uff09\uff0c\u7136\u540e\u4fdd\u5b58\u4e3acapture.pcap\u3002<\/li>\n\n\n\n<li>\u89e3\u6790 <code>capture.pcap<\/code> \u5e76\u7b5b\u9009\u51fa\u6240\u6709TCP\u534f\u8bae\u7684\u6570\u636e\u5305\u3002<\/li>\n\n\n\n<li>\u7edf\u8ba1 <code>capture.pcap<\/code> \u4e2d\u5404\u4e2a\u534f\u8bae\u7684\u6570\u636e\u5305\u6570\u91cf\u3002<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">02 \u5f00\u53d1\u73af\u5883\u642d\u5efa<\/h2>\n\n\n\n<p>\u771f\u7684\u5f88\u4e45\u5f88\u4e45\u6ca1\u5f00\u53d1windows\u7aef\u5e94\u7528\u4e86\u3002\u8fd9\u6b21\u4f7f\u7528VisualStudio 2022\u4e3aIDE\u5f00\u53d1\uff0c\u4e60\u60ef\u4e86JB\u5bb6\u7684IDE\u548c\u9ad8\u989c\u503cvscode\uff0c\u7528\u8fd9\u4e2aold school\u7684\u754c\u9762\u770b\u7740\u6709\u70b9\u96be\u53d7\u55b5~<\/p>\n\n\n\n<p>\u6302\u4e00\u4e2a\u9879\u76ee\u5730\u5740\uff1ahttps:\/\/github.com\/yangnanbei\/nb_easy_tshark<\/p>\n\n\n\n<p>\u9996\u5148\u6211\u4eec\u8981\u8bfb\u53d6tshark\u7684\u5185\u5bb9\u3002tshark\u5de5\u5177\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e0b\u5206\u6790\u6570\u636e\u5305\uff0c\u6211\u4eec\u6574\u70b9\u5305\u5148\u3002<\/p>\n\n\n\n<p>tshark -h\u4e00\u5806\u4e1c\u897f\u8f93\u51fa\uff0ctoooo verbose\uff0c\u6211\u76f4\u63a5\u4e0d\u770b\uff0c\u95ee\u4e00\u624bAI\u5148\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>tshark -D<\/p>\n<\/blockquote>\n\n\n\n<p>\u627e\u7f51\u53e3\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/yangnanbei.top\/wp-content\/uploads\/2025\/08\/image.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"654\" height=\"332\" data-original=\"http:\/\/yangnanbei.top\/wp-content\/uploads\/2025\/08\/image.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-372\"  sizes=\"(max-width: 654px) 100vw, 654px\" \/><\/div><\/figure>\n\n\n\n<p>\u90a3\u4e48\u663e\u7136 \\Device\\NPF_{FFCB4D95-E737-4DCA-B016-522C9BA641B5} \u8fd9\u5c31\u662f\u6211\u4eec\u8981\u627e\u7684\u7f51\u53e3\u4e86<\/p>\n\n\n\n<p>tshark\u5236\u5b9a\u7f51\u53e3\u7559\u5b581000\u4e2a\u6570\u636e\u5305\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>tshark -i &#8216;\\Device\\NPF_{FFCB4D95-E737-4DCA-B016-522C9BA641B5}&#8217; -c 1000 -w capture.pcap<\/p>\n<\/blockquote>\n\n\n\n<p>\u6ce8\u610f\u53cd\u659c\u6760\u6709\u9700\u8981\u8f6c\u4e49\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u7528\u5355\u5f15\u53f7\u62ec\u8d77\u6765\u5148\u3002<\/p>\n\n\n\n<p>ok\uff0c\u62ff\u5230\u4e86\u5bf9\u5e94\u7684\u5305\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Length Name<\/p>\n\n\n\n<p>263324 capture.pcap<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">VisualStudio cmd\u7f16\u7801\u95ee\u9898<\/h3>\n\n\n\n<p>\u5c06tshark\u7684\u8f93\u51fa\u901a\u8fc7popen\u4f20\u5165Visual Studio\uff0c\u6d4b\u8bd5\u65f6\u53d1\u73b0\u4e86\u4e2a\u95ee\u9898\u3002<\/p>\n\n\n\n<p>\u90a3\u5c31\u662fcmd\u7684\u9ed8\u8ba4\u7f16\u7801\u662fgbk\u7684\uff0c\u9700\u8981\u6539\u6210utf8\u624d\u80fd\u6109\u5feb\u73a9\u800d~<\/p>\n\n\n\n<p>\u89c1\u4ee5\u4e0b\u653b\u7565\uff1a<\/p>\n\n\n\n<p><a href=\"https:\/\/www.cnblogs.com\/resea\/p\/18517126\">C++\/8\/VS2022\u66f4\u6539\u4e3aUTF-8\u7684n\u79cd\u65b9\u6cd5 &#8211; \u5f52\u6d77\u8a00\u8bfa &#8211; \u535a\u5ba2\u56ed<\/a><\/p>\n\n\n\n<p>\u4f46\u662f\u535a\u4e3b\u7684\u653b\u7565\u6709\u4e2a\u95ee\u9898\u662f\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Command Processor<\/p>\n\n\n\n<p>\u5728\u53f3\u4fa7\u7a97\u683c\u4e2d\uff0c\u53f3\u952e\u5355\u51fb\u7a7a\u767d\u533a\u57df\uff0c\u9009\u62e9\u201c\u65b0\u5efa\u201d&gt;\u201cDWORD\u503c\uff0832\u4f4d\uff09\u201d\u3002<\/p>\n\n\n\n<p>\u5c06\u65b0\u521b\u5efa\u7684DWORD\u503c\u547d\u540d\u4e3a\u201cAutorun\u201d\uff0c\u7136\u540e\u53cc\u51fb\u5b83\u4ee5\u7f16\u8f91\u5176\u503c\u6570\u636e\u3002<\/p>\n\n\n\n<p>\u5728\u201c\u6570\u503c\u6570\u636e\u201d\u6846\u4e2d\uff0c\u8f93\u5165\u201cchcp 65001\u201d\uff0c\u7136\u540e\u70b9\u51fb\u201c\u786e\u5b9a\u201d<\/p>\n<\/blockquote>\n\n\n\n<p>\u8fd9\u91cc\u201c\u65b0\u5efa\u201d&gt;\u201cDWORD\u503c\uff0832\u4f4d\uff09\u201d\u662f\u4e0d\u5bf9\u7684\uff0c\u7c7b\u578b\u5f97\u662f<strong>\u5b57\u7b26\u4e32\u7c7b\u578b<\/strong>\u3002<\/p>\n\n\n\n<p>\u4f46\u662f\u540e\u7eed\u53d1\u73b0\u8bbe\u7f6eautorun\u4f1a\u5bfc\u81f4cmd\/powershell\u542f\u52a8\u62a5\u9519<\/p>\n\n\n\n<p>\u6700\u540e\u91c7\u7528\u5728main\u51fd\u6570\u5f00\u5934\u8bbe\u7f6eutf8\u5c5e\u6027<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> setlocale(LC_ALL, \"zh_CN.UTF-8\"); <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">03 \u4ee5json\u683c\u5f0f\u83b7\u53d6\u6570\u636e\u5305\u4fe1\u606f<\/h2>\n\n\n\n<p>\u6211\u4eec\u901a\u8fc7tshark\u83b7\u53d6\u4fe1\u606f\u4e4b\u540e\u8981\u5c06\u5176\u5b58\u50a8\u4e0b\u6765\uff0c<\/p>\n\n\n\n<p>\u4fe1\u606f\u7ed3\u6784\u4f53\uff1a<\/p>\n\n\n\n<p>\u76f8\u5173\u547d\u4ee4\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>tshark -r .\\10pkts.pcap -T fields -e frame.number -e frame.time -e ip.src -e ip.dst -e _ws.col.Protocol -e _ws.col.Info<\/p>\n<\/blockquote>\n\n\n\n<p>\u89e3\u6790\u79bb\u7ebf\u5305\u7684\u76f8\u5173\u6570\u636e\uff1a<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#f6f6f4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#f6f6f4;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>typedef struct Packet_ {\n    int frame_number;\n    std::string time;\n    std::string src_ip;\n    std::string dst_ip;\n    int src_port;\n    int dst_port;\n    std::string protocol;\n    std::string info;\n} Packet;<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki dracula-soft\" style=\"background-color: #282A36\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F286C4\">typedef<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">struct<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #97E1F1; font-style: italic\">Packet_<\/span><span style=\"color: #F6F6F4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">int<\/span><span style=\"color: #F6F6F4\"> frame_number;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #F6F6F4\">string time;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #F6F6F4\">string src_ip;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #F6F6F4\">string dst_ip;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">int<\/span><span style=\"color: #F6F6F4\"> src_port;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">int<\/span><span style=\"color: #F6F6F4\"> dst_port;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #F6F6F4\">string protocol;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #F6F6F4\">string info;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">} <\/span><span style=\"color: #97E1F1; font-style: italic\">Packet<\/span><span style=\"color: #F6F6F4\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u4f7f\u7528rapidjson\u5e93\u4ee5json\u683c\u5f0f\u8f93\u51fa\uff0c\u89e3\u6790\u6210\u529f\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/yangnanbei.top\/wp-content\/uploads\/2025\/08\/image-1-1024x290.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"290\" data-original=\"http:\/\/yangnanbei.top\/wp-content\/uploads\/2025\/08\/image-1-1024x290.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-374\"  sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">04 pcap\u6587\u4ef6\u683c\u5f0f<\/h2>\n\n\n\n<p>\u6211\u4eec\u5df2\u7ecf\u53ef\u4ee5\u8bfb\u53d6\u79bb\u7ebfpcap\u7684\u4e00\u4e9b\u5143\u7ec4\u4fe1\u606f\u3002\u73b0\u5728\u6211\u4eec\u9700\u8981\u83b7\u53d6\u6570\u636e\u5305\u7684\u539f\u59cb\u5341\u516d\u8fdb\u5236\u6570\u636e<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/yangnanbei.top\/wp-content\/uploads\/2025\/08\/image-2.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"568\" height=\"156\" data-original=\"http:\/\/yangnanbei.top\/wp-content\/uploads\/2025\/08\/image-2.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-375\"  sizes=\"(max-width: 568px) 100vw, 568px\" \/><\/div><\/figure>\n\n\n\n<p>\u90a3\u4e48\u5c06packet\u7684\u6570\u636e\u4fdd\u5b58\u5728\u7ed3\u6784\u4f53\u4e2d\uff0c\u5728\u9700\u8981\u7684\u65f6\u5019\u53bb\u8bfb\u5427\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">packet\u6587\u4ef6\u683c\u5f0f<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/yangnanbei.top\/wp-content\/uploads\/2025\/08\/image-3.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"712\" height=\"339\" data-original=\"http:\/\/yangnanbei.top\/wp-content\/uploads\/2025\/08\/image-3.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-377\"  sizes=\"(max-width: 712px) 100vw, 712px\" \/><\/div><\/figure>\n\n\n\n<p>\u53ef\u4ee5\u770b\u5230 pcap\u6587\u4ef6\u7ed3\u6784\u4e2d\uff0c\u4ee5\u4e00\u4e2a24\u5b57\u8282\u7684<code>Pcap Header<\/code>\u5f00\u5934\uff0c\u800c\u540e\u7684\u6bcf\u4e2a\u5305\u90fd\u4ee5<code>Packet Header<\/code>+<code>Packet Data<\/code>\u7684\u5f62\u5f0f\u5b58\u5728\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Pcap Header<\/h4>\n\n\n\n<p>\u5168\u5c40\u6587\u4ef6\u5934\uff0c\u5171<strong>24B<\/strong>\u4f4d\u4e8e\u6587\u4ef6\u7684\u8d77\u59cb\u4f4d\u7f6e\uff0c\u6bcf\u4e2a\u6587\u4ef6\u53ea\u6709\u4e00\u4e2a\u3002\u5305\u542b\u5982\u4e0b\u5b57\u6bb5<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><code>magic number<\/code>(4B): \u7528\u4e8e\u6807\u8bc6\u6587\u4ef6\u683c\u5f0f\n<ol class=\"wp-block-list\">\n<li>\u53ef\u4ee5\u4ece\u6b64\u533a\u5206\u5927\u7aef(0xa1b2c3d4)\u548c\u5c0f\u7aef(0x4dc3b2a1)\n<ul class=\"wp-block-list\">\n<li>\u73b0\u5728\u7535\u8111\u5927\u90e8\u5206\u662f\u5c0f\u7aef\u6a21\u5f0f<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/li>\n\n\n\n<li><code>version<\/code>(2B + 2B)\uff1apcap\u6587\u4ef6\u7248\u672c\u53f7\uff0c\u59822.4\n<ol class=\"wp-block-list\">\n<li>major(2B): \u4e3b\u8981\u7248\u672c<\/li>\n\n\n\n<li>minor(2B): \u6b21\u8981\u7248\u672c<\/li>\n<\/ol>\n<\/li>\n\n\n\n<li><code>this zone<\/code>(4B): \u65f6\u533a\u504f\u79fb\uff0c\u901a\u5e38\u4e3a0<\/li>\n\n\n\n<li><code>sigfigs<\/code>(4B): \u65f6\u95f4\u6233\u7cbe\u5ea6\uff0c\u901a\u5e38\u4e3a0<\/li>\n\n\n\n<li><code>snaplen<\/code>(4B): \u6355\u83b7\u7684\u6570\u636e\u8868\u6700\u5927\u957f\u5ea6<\/li>\n\n\n\n<li><code>network<\/code>(4B): \u94fe\u8def\u5c42\u7c7b\u578b\uff0c\u5982\u4ee5\u592a\u7f51<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\">Packet Header<\/h4>\n\n\n\n<p>\u6bcf\u4e2a\u6570\u636e\u8868\u7684metadata\uff0c\u517116B\uff0c\u5305\u542b\u5982\u4e0b\u5b57\u6bb5\uff1a<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><code>timestamp second<\/code>(4B): \u65f6\u95f4\u6233, \u79d2\u7ea7<\/li>\n\n\n\n<li><code>timestamp microseconds<\/code>(4B)\uff1a\u65f6\u95f4\u6233\uff0c\u5fae\u5999\u7ea7<\/li>\n\n\n\n<li><code>capture length<\/code>(4B): \u5b9e\u9645\u6355\u83b7\u7684\u6570\u636e\u5305\u957f\u5ea6\u3002\u5373\u6293\u53d6\u5230\u7684\u6570\u636e\u5e27\u957f\u5ea6\uff0c\u7531\u6b64\u53ef\u4ee5\u5f97\u5230\u4e0b\u4e00\u4e2a\u6570\u636e\u5e27\u7684\u4f4d\u7f6e\u3002<\/li>\n\n\n\n<li><code>original length<\/code>(4B): \u6570\u636e\u5305\u539f\u59cb\u957f\u5ea6\u3002\u79bb\u7ebf\u6570\u636e\u957f\u5ea6\uff0c\u7f51\u8def\u4e2d\u5b9e\u9645\u6570\u636e\u5e27\u7684\u957f\u5ea6\uff0c\u4e00\u822c\u4e0d\u5927\u4e8e Caplen\uff0c\u591a\u6570\u60c5\u51b5\u4e0b\u548c Caplen\u503c\u4e00\u6837<\/li>\n<\/ol>\n\n\n\n<p>\u6570\u636e\u8868\u6570\u636e\u4ee516\u8fdb\u5236\u7684\u5f62\u5f0f\u5b58\u50a8\u3002\u6211\u4eec\u53ef\u4ee5\u5c06\u5176\u8bfb\u53d6\u540e\u4ee516\u8fdb\u5236\u5f62\u5f0f\u6253\u5370\u51fa\u6765<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#f6f6f4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#f6f6f4;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly> \/* read pcap data *\/\nstd::vector&lt;unsigned char> data(packetHeader.caplen);\nfile.read(reinterpret_cast&lt;char*>(data.data()), packetHeader.caplen);<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki dracula-soft\" style=\"background-color: #282A36\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #7B7F8B\"> \/* read pcap data *\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #97E1F1; font-style: italic\">vector<\/span><span style=\"color: #F6F6F4\">&lt;<\/span><span style=\"color: #F286C4\">unsigned<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">char<\/span><span style=\"color: #F6F6F4\">&gt; <\/span><span style=\"color: #62E884\">data<\/span><span style=\"color: #F6F6F4\">(<\/span><span style=\"color: #97E1F1; font-style: italic\">packetHeader<\/span><span style=\"color: #F6F6F4\">.<\/span><span style=\"color: #FFB86C; font-style: italic\">caplen<\/span><span style=\"color: #F6F6F4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">file.<\/span><span style=\"color: #62E884\">read<\/span><span style=\"color: #F6F6F4\">(<\/span><span style=\"color: #F286C4\">reinterpret_cast&lt;char*&gt;<\/span><span style=\"color: #F6F6F4\">(data.<\/span><span style=\"color: #62E884\">data<\/span><span style=\"color: #F6F6F4\">()), packetHeader.caplen);<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-large\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/yangnanbei.top\/wp-content\/uploads\/2025\/08\/image-4-1024x160.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"160\" data-original=\"http:\/\/yangnanbei.top\/wp-content\/uploads\/2025\/08\/image-4-1024x160.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-378\"  sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/div><\/figure>\n\n\n\n<p>\u6309\u7167\u4e4b\u524d\u6240\u8bf4\uff0c\u6211\u4eec\u73b0\u5728\u8981\u8bb0\u5f55\u62a5\u6587\u7684\u504f\u79fb\u548c\u957f\u5ea6\uff0c\u628a\u5b83\u4fdd\u5b58\u8d77\u6765\uff0c\u90a3\u5c31\u9700\u8981<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>\u4fee\u6539\u4e00\u4e0bpacket\u7684\u7ed3\u6784\u4f53\u3002<\/li>\n\n\n\n<li>tshark\u5728\u5206\u6790\u7684\u65f6\u5019\uff0c\u5c06\u62a5\u6587\u7684\u957f\u5ea6\u8f93\u51fa\u51fa\u6765: <code>frame.cap_len<\/code>. \u8fd9\u6837\u6211\u4eec\u5c31\u80fd\u83b7\u53d6\u62a5\u6587\u957f\u5ea6\uff0c\u6765\u8ba1\u7b97\u504f\u79fb\u5e76\u8bb0\u5f55\u4e86\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u5728\u89e3\u6790\u7684\u65f6\u5019\u8bb0\u5f55\u6bcf\u4e2a\u5305\u7684offset+caplen\uff0c\u800c\u540e\u5728\u6700\u540e\u8bfb\u53d6\u6587\u4ef6\u65f6\u8f93\u51fa\u5373\u53ef\u3002<\/p>\n\n\n\n<p>\u89e3\u6790\u51fd\u6570\uff1a<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#f6f6f4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#f6f6f4;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>bool readPacketHex(const std::string&amp; packet_file, uint32_t file_offset,\n                   uint32_t length, std::vector&lt;unsigned char>&amp; buffer)\n{\n    buffer.resize(length);\n    FILE* file = fopen(packet_file.c_str(), \"rb\");\n    if (!file) {\n        std::cerr &lt;&lt; \"Failed to open file: \" &lt;&lt; packet_file &lt;&lt; std::endl;\n        buffer.clear();\n        return false;\n    }\n    if (fseek(file, file_offset, SEEK_SET) != 0) {\n        std::cerr &lt;&lt; \"Failed to seek to offset: \" &lt;&lt; file_offset &lt;&lt; std::endl;\n        fclose(file);\n        buffer.clear();\n        return false;\n    }\n    size_t bytesRead = fread(buffer.data(), 1, length, file);\n    fclose(file);\n    if (bytesRead != length) {\n        std::cerr &lt;&lt; \"Failed to read data from file. Expected: \" &lt;&lt; length &lt;&lt; \", got: \" &lt;&lt; bytesRead &lt;&lt; std::endl;\n        buffer.resize(bytesRead);\n        return false;\n    }\n    return true;\n}<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki dracula-soft\" style=\"background-color: #282A36\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F286C4\">bool<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">readPacketHex<\/span><span style=\"color: #F6F6F4\">(<\/span><span style=\"color: #F286C4\">const<\/span><span style=\"color: #F6F6F4\"> std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #97E1F1; font-style: italic\">string<\/span><span style=\"color: #F286C4\">&amp;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #FFB86C; font-style: italic\">packet_file<\/span><span style=\"color: #F6F6F4\">, <\/span><span style=\"color: #F286C4\">uint32_t<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #FFB86C; font-style: italic\">file_offset<\/span><span style=\"color: #F6F6F4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">                   <\/span><span style=\"color: #F286C4\">uint32_t<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #FFB86C; font-style: italic\">length<\/span><span style=\"color: #F6F6F4\">, std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #97E1F1; font-style: italic\">vector<\/span><span style=\"color: #F6F6F4\">&lt;<\/span><span style=\"color: #F286C4\">unsigned<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">char<\/span><span style=\"color: #F6F6F4\">&gt;<\/span><span style=\"color: #F286C4\">&amp;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #FFB86C; font-style: italic\">buffer<\/span><span style=\"color: #F6F6F4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    buffer.<\/span><span style=\"color: #62E884\">resize<\/span><span style=\"color: #F6F6F4\">(length);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    FILE<\/span><span style=\"color: #F286C4\">*<\/span><span style=\"color: #F6F6F4\"> file <\/span><span style=\"color: #F286C4\">=<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">fopen<\/span><span style=\"color: #F6F6F4\">(packet_file.<\/span><span style=\"color: #62E884\">c_str<\/span><span style=\"color: #F6F6F4\">(), <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">rb<\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">if<\/span><span style=\"color: #F6F6F4\"> (<\/span><span style=\"color: #F286C4\">!<\/span><span style=\"color: #F6F6F4\">file) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #F6F6F4\">cerr <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">Failed to open file: <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> packet_file <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #F6F6F4\">endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        buffer.<\/span><span style=\"color: #62E884\">clear<\/span><span style=\"color: #F6F6F4\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        <\/span><span style=\"color: #F286C4\">return<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #BF9EEE\">false<\/span><span style=\"color: #F6F6F4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">if<\/span><span style=\"color: #F6F6F4\"> (<\/span><span style=\"color: #62E884\">fseek<\/span><span style=\"color: #F6F6F4\">(file, file_offset, SEEK_SET) <\/span><span style=\"color: #F286C4\">!=<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #BF9EEE\">0<\/span><span style=\"color: #F6F6F4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #F6F6F4\">cerr <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">Failed to seek to offset: <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> file_offset <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #F6F6F4\">endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        <\/span><span style=\"color: #62E884\">fclose<\/span><span style=\"color: #F6F6F4\">(file);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        buffer.<\/span><span style=\"color: #62E884\">clear<\/span><span style=\"color: #F6F6F4\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        <\/span><span style=\"color: #F286C4\">return<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #BF9EEE\">false<\/span><span style=\"color: #F6F6F4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">size_t<\/span><span style=\"color: #F6F6F4\"> bytesRead <\/span><span style=\"color: #F286C4\">=<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">fread<\/span><span style=\"color: #F6F6F4\">(buffer.<\/span><span style=\"color: #62E884\">data<\/span><span style=\"color: #F6F6F4\">(), <\/span><span style=\"color: #BF9EEE\">1<\/span><span style=\"color: #F6F6F4\">, length, file);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #62E884\">fclose<\/span><span style=\"color: #F6F6F4\">(file);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">if<\/span><span style=\"color: #F6F6F4\"> (bytesRead <\/span><span style=\"color: #F286C4\">!=<\/span><span style=\"color: #F6F6F4\"> length) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #F6F6F4\">cerr <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">Failed to read data from file. Expected: <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> length <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">, got: <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> bytesRead <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #F6F6F4\">endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        buffer.<\/span><span style=\"color: #62E884\">resize<\/span><span style=\"color: #F6F6F4\">(bytesRead);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        <\/span><span style=\"color: #F286C4\">return<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #BF9EEE\">false<\/span><span style=\"color: #F6F6F4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">return<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #BF9EEE\">true<\/span><span style=\"color: #F6F6F4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u6b64\u65f6\u6211\u4eec\u7684\u76f8\u5173\u5b9a\u4e49\u5982\u4e0b\uff1a<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#f6f6f4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#f6f6f4;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>struct PcapHeader {\n    uint32_t magic_number;\n    uint16_t version_major;\n    uint16_t version_minor;\n    int32_t  thiszone;\n    uint32_t sigfigs;\n    uint32_t snaplen;\n    uint32_t network;\n};\n\nstruct PacketHeader {\n    uint32_t ts_sec;\n    uint32_t ts_usec;\n    uint32_t caplen;\n    uint32_t len;\n};\n\nstruct Packet {\n    int frame_number;\n    std::string time;\n    uint32_t cap_len;\n    std::string src_ip;\n    uint16_t src_port;\n    std::string dst_ip;\n    uint16_t dst_port;\n    std::string protocol;\n    std::string info;\n    uint32_t file_offset;\n};<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki dracula-soft\" style=\"background-color: #282A36\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F286C4\">struct<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #97E1F1; font-style: italic\">PcapHeader<\/span><span style=\"color: #F6F6F4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">uint32_t<\/span><span style=\"color: #F6F6F4\"> magic_number;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">uint16_t<\/span><span style=\"color: #F6F6F4\"> version_major;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">uint16_t<\/span><span style=\"color: #F6F6F4\"> version_minor;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">int32_t<\/span><span style=\"color: #F6F6F4\">  thiszone;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">uint32_t<\/span><span style=\"color: #F6F6F4\"> sigfigs;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">uint32_t<\/span><span style=\"color: #F6F6F4\"> snaplen;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">uint32_t<\/span><span style=\"color: #F6F6F4\"> network;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">struct<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #97E1F1; font-style: italic\">PacketHeader<\/span><span style=\"color: #F6F6F4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">uint32_t<\/span><span style=\"color: #F6F6F4\"> ts_sec;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">uint32_t<\/span><span style=\"color: #F6F6F4\"> ts_usec;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">uint32_t<\/span><span style=\"color: #F6F6F4\"> caplen;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">uint32_t<\/span><span style=\"color: #F6F6F4\"> len;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">struct<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #97E1F1; font-style: italic\">Packet<\/span><span style=\"color: #F6F6F4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">int<\/span><span style=\"color: #F6F6F4\"> frame_number;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #F6F6F4\">string time;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">uint32_t<\/span><span style=\"color: #F6F6F4\"> cap_len;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #F6F6F4\">string src_ip;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">uint16_t<\/span><span style=\"color: #F6F6F4\"> src_port;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #F6F6F4\">string dst_ip;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">uint16_t<\/span><span style=\"color: #F6F6F4\"> dst_port;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #F6F6F4\">string protocol;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #F6F6F4\">string info;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">uint32_t<\/span><span style=\"color: #F6F6F4\"> file_offset;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">};<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u6d4b\u8bd5\uff1a<\/h3>\n\n\n\n<p>\u8bd5\u4e00\u8bd5\u6211\u4eec\u89e3\u6790\u51fa\u7684hex\u6570\u636e\u548cwireshark\u4e2d\u505a\u6bd4\u8f83\uff1a<\/p>\n\n\n\n<p>\u6211\u4eec\u89e3\u6790\u7684\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/yangnanbei.top\/wp-content\/uploads\/2025\/08\/image-5.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"959\" height=\"113\" data-original=\"http:\/\/yangnanbei.top\/wp-content\/uploads\/2025\/08\/image-5.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-379\"  sizes=\"(max-width: 959px) 100vw, 959px\" \/><\/div><\/figure>\n\n\n\n<p>wireshark\u4e2d\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/syfdjmqori.feishu.cn\/space\/api\/box\/stream\/download\/asynccode\/?code=N2ZkZmY0MzVhMGU2MzE4YmE3NjYyODFkMDFkNDI5ZDlfNUZsckd0aGxwT1hFQTM1YVh0TlVmWTNzWWpzMFJGTWxfVG9rZW46U21ndmI1TnhBbzhMT1V4bk9HRWNlRE82bnFkXzE3NTU0MjA1MzE6MTc1NTQyNDEzMV9WNA'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/syfdjmqori.feishu.cn\/space\/api\/box\/stream\/download\/asynccode\/?code=N2ZkZmY0MzVhMGU2MzE4YmE3NjYyODFkMDFkNDI5ZDlfNUZsckd0aGxwT1hFQTM1YVh0TlVmWTNzWWpzMFJGTWxfVG9rZW46U21ndmI1TnhBbzhMT1V4bk9HRWNlRE82bnFkXzE3NTU0MjA1MzE6MTc1NTQyNDEzMV9WNA\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\"\/><\/div><\/figure>\n\n\n\n<p>\u662f\u80fd\u5bf9\u5e94\u4e0a\u7684~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>01 \u6982\u8ff0 \u57fa\u4e8etshark, cpp\u5f00\u53d1\u7c7bwireshark\u8f6f\u4ef6 nbEasyTshark Wireshar [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":92,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,7,8,9,3],"tags":[40,71,69,70,49],"class_list":["post-371","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-c","category-network","category-network_codeing","category-network_knowledge","category-coding_language","tag-c","tag-tshark","tag-windows","tag-wireshark","tag-49"],"_links":{"self":[{"href":"http:\/\/yangnanbei.top\/index.php\/wp-json\/wp\/v2\/posts\/371"}],"collection":[{"href":"http:\/\/yangnanbei.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/yangnanbei.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/yangnanbei.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/yangnanbei.top\/index.php\/wp-json\/wp\/v2\/comments?post=371"}],"version-history":[{"count":3,"href":"http:\/\/yangnanbei.top\/index.php\/wp-json\/wp\/v2\/posts\/371\/revisions"}],"predecessor-version":[{"id":382,"href":"http:\/\/yangnanbei.top\/index.php\/wp-json\/wp\/v2\/posts\/371\/revisions\/382"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/yangnanbei.top\/index.php\/wp-json\/wp\/v2\/media\/92"}],"wp:attachment":[{"href":"http:\/\/yangnanbei.top\/index.php\/wp-json\/wp\/v2\/media?parent=371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/yangnanbei.top\/index.php\/wp-json\/wp\/v2\/categories?post=371"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/yangnanbei.top\/index.php\/wp-json\/wp\/v2\/tags?post=371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}