Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Made WinDump use Npcap when Npcap and WinPcap coexist.
There are two steps:
1) Add "wpcap.dll" to the "DelayLoadDLLs" of the project file.
2) Call init_npcap_dll_path() before you use any wpcap.dll functions, the beginning of the main() function is a good place.
  • Loading branch information
hsluoyz committed Jun 15, 2016
1 parent bb60861 commit dffe2ea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Tcpdump.c
Expand Up @@ -443,6 +443,26 @@ static int tcpdump_printf(netdissect_options *ndo _U_,
return ret;
}

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) {
error("Error in SetDllDirectory");
}
else {
len = GetSystemDirectory(sysdir_name, 480); // be safe
if (!len)
error("Error in GetSystemDirectory (%d)", GetLastError());
strcat(sysdir_name, "\\Npcap");
if (SetDllDirectory(sysdir_name) == 0)
error("Error in SetDllDirectory(\"System32\\Npcap\")");
}
}

int
main(int argc, char **argv)
{
Expand All @@ -466,6 +486,9 @@ main(int argc, char **argv)
int devnum;
#endif
int status;

init_npcap_dll_path();

#ifdef WIN32
u_int UserBufferSize = 1000000;
if(wsockinit() != 0) return 1;
Expand Down
4 changes: 4 additions & 0 deletions win32/prj/WinDump.vcxproj
Expand Up @@ -135,6 +135,7 @@
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<DelayLoadDLLs>wpcap.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Bscmake>
<SuppressStartupBanner>true</SuppressStartupBanner>
Expand Down Expand Up @@ -176,6 +177,7 @@
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<DelayLoadDLLs>wpcap.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Bscmake>
<SuppressStartupBanner>true</SuppressStartupBanner>
Expand Down Expand Up @@ -221,6 +223,7 @@
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
<DelayLoadDLLs>wpcap.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Bscmake>
<SuppressStartupBanner>true</SuppressStartupBanner>
Expand Down Expand Up @@ -263,6 +266,7 @@
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
<DelayLoadDLLs>wpcap.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
</Link>
<Bscmake>
<SuppressStartupBanner>true</SuppressStartupBanner>
Expand Down

0 comments on commit dffe2ea

Please sign in to comment.