Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何使用visual c+从wireshark读取pcap文件+;_C++_Visual C++_Pcap_Libpcap_Winpcap - Fatal编程技术网

C++ 如何使用visual c+从wireshark读取pcap文件+;

C++ 如何使用visual c+从wireshark读取pcap文件+;,c++,visual-c++,pcap,libpcap,winpcap,C++,Visual C++,Pcap,Libpcap,Winpcap,我需要设置一个编程环境来从Wireshark读取pcap文件。(C++) 用于读取pcap文件的软件库。(我不知道) 我还需要一个DNS消息解析器来获取DNS的内容 消息。(我也没有找到) 这就是我所做的: 我使用Wireshark捕获了一个流量并保存了文件。 我从这个站点(())遵循了以下步骤 这是我的代码: #include <string> #include <iostream> #include <pcap.h> using namespace s

我需要设置一个编程环境来从Wireshark读取pcap文件。(C++) 用于读取pcap文件的软件库。(我不知道) 我还需要一个DNS消息解析器来获取DNS的内容 消息。(我也没有找到)

这就是我所做的: 我使用Wireshark捕获了一个流量并保存了文件。 我从这个站点(())遵循了以下步骤 这是我的代码:

#include <string>
#include <iostream>
#include <pcap.h>


using namespace std;

int main(int argc, char *argv[])
{
string file = "C:\\Users\\It-am\\Desktop\\Master\\dns-ipv4-ipv6.pcap";

char errbuff[PCAP_ERRBUF_SIZE];

pcap_t * pcap = pcap_open_offline(file.c_str(), errbuff);

struct pcap_pkthdr *header;

const u_char *data;

u_int packetCount = 0;

while (int returnValue = pcap_next_ex(pcap, &header, &data) >= 0)
{
    printf("Packet # %i\n", ++packetCount);
    printf("Packet size: %d bytes\n", header->len);

    if (header->len != header->caplen)
        printf("Warning! Capture size different than packet size: %ld bytes\n", header->len);

    printf("Epoch Time: %d:%d seconds\n", header->ts.tv_sec, header->ts.tv_usec);

    for (u_int i = 0; (i < header->caplen); i++)
    {
        if ((i % 16) == 0) printf("\n");
        printf("%.2x ", data[i]);
    }
    printf("\n\n");
}
}
#包括
#包括
#包括
使用名称空间std;
int main(int argc,char*argv[])
{
string file=“C:\\Users\\It am\\Desktop\\Master\\dns-ipv4-ipv6.pcap”;
字符errbuff[PCAP_ERRBUF_SIZE];
pcap_t*pcap=pcap_open_offline(file.c_str(),errbuff);
结构pcap_pkthdr*头;
常量u_char*数据;
u_int packetCount=0;
while(int returnValue=pcap\u next\u ex(pcap、头和数据)>=0)
{
printf(“数据包#%i\n”++数据包计数);
printf(“数据包大小:%d字节\n”,标题->len);
如果(标题->标题!=标题->标题)
printf(“警告!捕获大小不同于数据包大小:%ld字节\n”,标题->len);
printf(“纪元时间:%d:%d秒\n”,标题->ts.tv\u秒,标题->ts.tv\u秒);
对于(u_int i=0;(icaplen);i++)
{
如果((i%16)==0)printf(“\n”);
printf(“%.2x”,数据[i]);
}
printf(“\n\n”);
}
}
但最后,我有一个错误((LNK1104无法打开文件'winpcap.lib')) 如果有人能解决这个问题,我将不胜感激。 或者如果有人用另一个代码来实现C++中的数据,请帮助。
提前感谢。

库名不是
winpcap.lib
,而是
wpcap.lib
。您可能还需要链接到
Packet.lib
。您必须告诉链接器文件的位置。Win32的文件夹为
Lib
,64位的文件夹为
Lib\x64

库名不是
winpcap.Lib
,而是
wpcap.Lib
。您可能还需要链接到
Packet.lib
。您必须告诉链接器文件的位置。Win32的文件夹为
Lib
,64位的文件夹为
Lib\x64

使用库源pcap\U文件生成器。 示例如下:

#include "pcap_file_generator.h"
...

PCAPFILE  * pfr = lpcap_open("./pcaplibtestfile.pcap");
  pcap_hdr_t   phdr;
  if( lpcap_read_header( pfr, &phdr ))
  {
    int rese_rec_read = 0 ;
    pcaprec_hdr_and_data_t  p_rec_data;
    do{   
       rese_rec_read = lpcap_read_frame_record( pfr , &p_rec_data);
      //p_rec_data -  contain data of record
    }while(rese_rec_read>0);
使用库的源pcap\u文件\u生成器。 示例如下:

#include "pcap_file_generator.h"
...

PCAPFILE  * pfr = lpcap_open("./pcaplibtestfile.pcap");
  pcap_hdr_t   phdr;
  if( lpcap_read_header( pfr, &phdr ))
  {
    int rese_rec_read = 0 ;
    pcaprec_hdr_and_data_t  p_rec_data;
    do{   
       rese_rec_read = lpcap_read_frame_record( pfr , &p_rec_data);
      //p_rec_data -  contain data of record
    }while(rese_rec_read>0);

wincap.lib
所在的目录添加到您的库搜索路径。我访问并下载了最新版本,并将wincap.lib包含到我的库中,但我遇到了相同的问题您没有阅读我写的内容。可能有帮助。未将“doxygen”识别为内部或外部命令、可操作程序或批处理文件。当我试图从winpcap.org/devel.html提供的windows批处理文件中构建wdpack时,会发生此错误。显然,您需要安装
doxygen
,以便生成文档。您应该注意在构建过程中关闭该部分的标志。顺便说一句,与您的原始问题无关。请将
wincap.lib
所在的目录添加到您的库搜索路径。我访问并下载了最新版本,并将wincap.lib包含到我的库中,但我遇到了相同的问题您没有阅读我写的内容。可能有帮助。未将“doxygen”识别为内部或外部命令、可操作程序或批处理文件。当我试图从winpcap.org/devel.html提供的windows批处理文件中构建wdpack时,会发生此错误。显然,您需要安装
doxygen
,以便生成文档。您应该注意在构建过程中关闭该部分的标志。顺便说一句,与你原来的问题无关。