mfontanini / libtins

High-level, multiplatform C++ network packet sniffing and crafting library.
http://libtins.github.io/
BSD 2-Clause "Simplified" License
1.91k stars 375 forks source link

Missing wpcap.dll #380

Open KainWhite opened 4 years ago

KainWhite commented 4 years ago

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: image 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?

yeahitsjan commented 2 years ago

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.

rectified95 commented 2 years ago

@yeahitsjan Do you mean you were able to fix the missing DLL error by defining WIN32 in the source file?

mfontanini commented 2 years ago

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.

rectified95 commented 2 years ago

@mfontanini Here are a few issues on Windows 11 I wanted to bring to your attention:

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.

rectified95 commented 2 years ago

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.