使用winpcap写入DLT_USER0捕获时出现问题

Having trouble using winpcap to write DLT_USER0 captures

本文关键字:问题 USER0 winpcap 写入 DLT 使用      更新时间:2023-10-16

我正在使用MINGW制作一个C++程序,该程序使用Winpcap库将BTLE数据包保存到PCAP文件中。

我正在尝试使用DLT_USER0链接层类型打开PCAP文件。

我可以使用对pcap_open_dead()的调用打开DLT_USER0,但pcap_dump_open()抱怨它不知道相应的链接类型。

调用pcap_geterr()后,我收到以下消息:

     out-dump.pcap: link-layer type -1 isn't supported in savefiles

下面是我的代码。

#define OUT_FILENAME "out-dump.pcap"
pcap_t *pcap_dumpfile;  // Descriptor of an open capture instance
pcap_dumper_t *dumper;  // libpcap savefile descriptor"
// pcap_open_dead() creates a pcap_t structure to use when 
// calling other functions in libpacp
pcap_dumpfile = pcap_open_dead(DLT_USER0, 128);
// Check if pcap_dumpfile was created. If it was not it will return a NULL
if (NULL == pcap_dumpfile)
{
    cout << "npcap_open_dead() FAILED!!!" << endl;
}
else
{
    // Open a save file to write to!
    dumper = pcap_dump_open(pcap_dumpfile, OUT_FILENAME);
    pcap_dump_flush(dumper);
    // Check if the dumper was created
    if (NULL == dumper)
    {
        // Printout the FAIL status
        cout << "npcap_dump_open() FAILED!!!" << endl;
        // Printout the PCAP Error
        cout << "n" << pcap_geterr(pcap_dumpfile) << endl;
        // Close the pcap_dumpfile and deallocate it's resources
        pcap_close(pcap_dumpfile);
    }
} 

我正在使用WinPcap 4.1.2开发包来构建我的C++应用程序。

遗憾的是,这是WinPcap 4.1.2中的一个错误。

希望WinPcap的未来版本将基于libpcap的更高版本,在该版本中修复了该错误。