libtins
libtins copied to clipboard
Missing wpcap.dll
Windows 10, MSVS 2019 I have started up with this code:
#ifndef TINS_STATIC
#define TINS_STATIC
#endif // !TINS_STATIC
#include <tins/tins.h>
#include <iostream>
int main() {
Tins::Sniffer sniffer("eth0");
Tins::PDU *pdu = sniffer.next_packet();
Tins::DNS dns = pdu->rfind_pdu<Tins::RawPDU>().to<Tins::DNS>();
for (const auto &query : dns.queries()) {
std::cout << query.dname() << std::endl;
}
delete pdu;
}
and tried to build it x86. Result was a bunch of LNK2019 errors, at the end of which there was this: "libtins-master\build\lib\Debug\tins.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'x86'". Ok, tried to build it x64, result: "WpdPack\Include\pcap\pcap.h(47,12): fatal error C1083: Cannot open include file: 'sys/time.h': No such file or directory". In this file:
#if defined(WIN32)
#include <pcap-stdinc.h>
#elif defined(MSDOS)
#include <sys/types.h>
#include <sys/socket.h> /* u_int, u_char etc. */
#else /* UN*X */
#include <sys/types.h>
#include <sys/time.h>
#endif /* WIN32/MSDOS/UN*X */
OOOOOK. (my code):
#ifndef WIN32
#define WIN32
#endif // !WIN32
Builded again and finally successfully. But when I run it I got this:
I have tried installing Winpcap, that places needed dll in System32 folder, but then there are memory access violation in this code (sniffer.cpp):
if (pcap_activate(get_pcap_handle()) < 0) {
throw pcap_error(pcap_geterr(get_pcap_handle()));
}
Well, am I doing anything wrong?
Don't know if this is still relevant for you. But instead also define WIN32
in your file. pcap.h
shows this:
#if defined(WIN32)
#include <pcap-stdinc.h>
#elif defined(MSDOS)
#include <sys/types.h>
#include <sys/socket.h> /* u_int, u_char etc. */
#else /* UN*X */
#include <sys/types.h>
#include <sys/time.h>
#endif /* WIN32/MSDOS/UN*X */
Should work. Got the same error and fixed it with that.
@yeahitsjan Do you mean you were able to fix the missing DLL error by defining WIN32 in the source file?
I don't use Windows so it's hard for me to reproduce this. This was working fine last I tried it there, but I'm unsure of what version of Windows I used at the time.
@mfontanini Here are a few issues on Windows 11 I wanted to bring to your attention:
- Libtins website lists WinPCAP as a dependency on Windows: that project hasn't worked on Windows for a while, and itself instructs users to use NPCAP instead, which has a compatible API - https://npcap.com/
- The build artifacts expire after a month, so it was impossible to access them until yesterday when a new PR got merged. It'd be awesome if you could extend the retention time or host the binaries somewhere else.
I'm gonna try the pre-built version and update the comment, but letting you know that Libtins seems broken on Windows when building from source.
I was able to figure it out by reading the NPCAP docs - they do ship wpcap.dll. I first only downloaded the NPCAP SDK - analogous to libtins saying to get the WinPCAP SDK - but didn't install NPCAP itself - doing that solved this issue: https://npcap.com/#download I think it can be closed. FYI @mfontanini @KainWhite
It'd be great if the libtins website were updated to reflect needing to use NPCAP instead of WPCAP.