我正在尝试使用C++的libtins库,但总是遇到一个基本的错误。
这是我的代码:
#define TINS_STATIC
#define WIN32
#include <iostream>
#include <tins/tins.h>
using namespace Tins;
int main(void) {
NetworkInterface iface = NetworkInterface::default_interface();
Sniffer sniffer(iface.name());
//more code below
}在运行时,我得到了以下错误:
Exception thrown at 0x00007FFD80F7DC9A (ntdll.dll) in test.exe: 0xC0000008: An invalid handle was specified.我的默认网络接口是"Ethernet 2“。当我列出所有接口时,Libtins可以成功检测到这一点。
{07C8C0D2-A2FC-4B91-9875-A8301682EF7C} (Ethernet 2)我尝试手动输入接口名称,如下所示:
Sniffer sniffer("\\Device\\NPF_{07C8C0D2-A2FC-4B91-9875-A8301682EF7C}");但在运行时会出现以下错误:
Exception thrown at 0x00007FFD7D2EA388 in test.exe: Microsoft C++ exception: Tins::pcap_error at memory location 0x000000543FCFF790.
Unhandled exception at 0x00007FFD7D2EA388 in test.exe: Microsoft C++ exception: Tins::pcap_error at memory location 0x000000543FCFF790.我做错了什么?是否与我的网络配置有关?我在Windows10机器上使用预置的64位libtins库。Wireshark可以毫无问题地嗅探接口。
发布于 2018-11-27 22:33:02
我怀疑您的接口的名称是\\Device\\NPF_{07C8C0D2-A2FC-4B91-9875-A8301682EF7C}。据我所知,由于您的接口是Ethernet2,因此您应该将eth2传递给Sniffer对象。
下面的工作对我来说是完美的:
SnifferConfiguration config;
config.set_promisc_mode(true);
config.set_filter("udp and (dst port 53 or src port 53)");
Sniffer sniffer("wlp9s0", config);
sniffer.sniff_loop(callback);https://stackoverflow.com/questions/51049905
复制相似问题