From f1e18d458304e052e0d3f1824809cebf51bbcd0c Mon Sep 17 00:00:00 2001 From: "U-DESKTOP-T772REH\\wangyu" Date: Sun, 1 Jul 2018 11:13:50 +0800 Subject: [PATCH] support npcap non-compatiable mode --- pcap_wrapper.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/pcap_wrapper.cpp b/pcap_wrapper.cpp index 891f17b..84812be 100644 --- a/pcap_wrapper.cpp +++ b/pcap_wrapper.cpp @@ -40,10 +40,42 @@ struct init_pcap_t }do_it; +static void init_npcap_dll_path() +{ + BOOL(WINAPI *SetDllDirectory)(LPCTSTR); + char sysdir_name[512]; + int len; + + SetDllDirectory = (BOOL(WINAPI *)(LPCTSTR)) GetProcAddress(GetModuleHandle("kernel32.dll"), "SetDllDirectoryA"); + if (SetDllDirectory == NULL) { + printf("Error in SetDllDirectory"); + } + else { + len = GetSystemDirectory(sysdir_name, 480); // be safe + if (!len) + printf("Error in GetSystemDirectory (%d)", (int)GetLastError()); + strcat(sysdir_name, "\\Npcap"); + if (SetDllDirectory(sysdir_name) == 0) + printf("Error in SetDllDirectory(\"System32\\Npcap\")"); + } +} + #define EXPORT_FUN(XXX) do{ XXX= (__typeof__(XXX)) GetProcAddress(wpcap, #XXX); }while(0) int init_pcap() { HMODULE wpcap=LoadLibrary("wpcap.dll"); + if(wpcap!=0) + { + printf("using system32/wpcap.dll\n"); + } + else + { + init_npcap_dll_path(); + //SetDllDirectory("C:\\Windows\\System32\\Npcap\\"); + wpcap=LoadLibrary("wpcap.dll"); + if(wpcap!=0) + printf("using system32/npcap/wpcap.dll\n"); + } if(wpcap==0) { printf("cant not open wpcap.dll, make sure winpcap/npcap is installed\n");