From c4e858d3467fe6a9670c987b9df87712ccadfdfe Mon Sep 17 00:00:00 2001 From: Kyle Schwarz Date: Wed, 4 Jun 2025 22:14:09 -0400 Subject: [PATCH] Driver: Prefer Npcap Prefer Npcap over WinPcap and TCP --- CMakeLists.txt | 1 - .../platform/windows/internal/pcapdll.h | 2 +- platform/windows/internal/pcapdll.cpp | 22 +++++++------------ pyproject.toml | 1 - 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e581ba..a62c84c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -430,7 +430,6 @@ if(LIBICSNEO_ENABLE_RAW_ETHERNET) add_definitions(-DWPCAP -DHAVE_REMOTE) else() target_include_directories(icsneocpp PUBLIC AFTER ${LIBICSNEO_NPCAP_INCLUDE_DIR}) - add_definitions(-DNPCAP) endif() else() find_package(PCAP REQUIRED) diff --git a/include/icsneo/platform/windows/internal/pcapdll.h b/include/icsneo/platform/windows/internal/pcapdll.h index 6a252a3..ad9614b 100644 --- a/include/icsneo/platform/windows/internal/pcapdll.h +++ b/include/icsneo/platform/windows/internal/pcapdll.h @@ -50,7 +50,7 @@ public: bool ok() const; private: PCAPDLL(); - HINSTANCE dll; + HINSTANCE dll = nullptr; void closeDLL(); }; } diff --git a/platform/windows/internal/pcapdll.cpp b/platform/windows/internal/pcapdll.cpp index 02672f0..4bdbb0f 100644 --- a/platform/windows/internal/pcapdll.cpp +++ b/platform/windows/internal/pcapdll.cpp @@ -28,21 +28,15 @@ bool PCAPDLL::ok() const PCAPDLL::PCAPDLL() { -#ifdef NPCAP // Use -DLIBICSNEO_NPCAP_INCLUDE_DIR when configuring, point towards the npcap includes - DLL_DIRECTORY_COOKIE cookie = 0; - TCHAR dllPath[512] = { 0 }; - int len = GetSystemDirectory(dllPath, 480); // be safe - if (len) { - _tcscat_s(dllPath, 512, TEXT("\\Npcap")); - cookie = AddDllDirectory(dllPath); + TCHAR dir[512] = {0}; + if(GetSystemDirectory(dir, 480)) { + _tcscat_s(dir, 512, TEXT("\\Npcap")); + if(SetDllDirectory(dir)) { + // will search for Npcap first, then fall back to WinPcap + dll = LoadLibrary(TEXT("wpcap.dll")); + SetDllDirectory(nullptr); // reset + } } - dll = LoadLibraryEx(TEXT("wpcap.dll"), nullptr, LOAD_LIBRARY_SEARCH_USER_DIRS); - - if (cookie) - RemoveDllDirectory(cookie); -#else // Otherwise we'll use WinPCAP, or npcap in compatibility mode - dll = LoadLibrary(TEXT("wpcap.dll")); -#endif if(dll == NULL) { closeDLL(); diff --git a/pyproject.toml b/pyproject.toml index 78fdd8b..a7b3ed7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,7 +46,6 @@ local_scheme = "no-local-version" [tool.scikit-build.cmake.define] LIBICSNEO_ENABLE_BINDINGS_PYTHON = true -LIBICSNEO_ENABLE_TCP = true CMAKE_MSVC_RUNTIME_LIBRARY = "MultiThreaded" [tool.cibuildwheel]