@@ -1437,6 +1437,42 @@ main(int argc, char **argv)
14371437 netdissect_options Ndo ;
14381438 netdissect_options * ndo = & Ndo ;
14391439
1440+ #ifdef _WIN32
1441+ /*
1442+ * We need to look for wpcap.dll in \Windows\System32\Npcap first,
1443+ * as either:
1444+ *
1445+ * 1) WinPcap isn't installed and Npcap isn't installed in "WinPcap
1446+ * API-compatible Mode", so there's no wpcap.dll in
1447+ * \Windows\System32, only in \Windows\System32\Npcap;
1448+ *
1449+ * 2) WinPcap is installed and Npcap isn't installed in "WinPcap
1450+ * API-compatible Mode", so the wpcap.dll in \Windows\System32
1451+ * is a WinPcap DLL, but we'd prefer an Npcap DLL (we should
1452+ * work with either one if we're configured against WinPcap,
1453+ * and we'll probably require Npcap if we're configured againt
1454+ * it), and that's in \Windows\System32\Npcap;
1455+ *
1456+ * 3) Npcap is installed in "WinPcap API-compatible Mode", so both
1457+ * \Windows\System32 and \Windows\System32\Npcap have an Npcap
1458+ * wpcap.dll.
1459+ *
1460+ * Unfortunately, Windows has no notion of an rpath, so we can't
1461+ * set the rpath to include \Windows\System32\Npcap at link time;
1462+ * what we need to do is to link wpcap as a delay-load DLL and
1463+ * add \Windows\System32\Npcap to the DLL search path early in
1464+ * main() with a call to SetDllDirectory().
1465+ *
1466+ * The same applies to packet.dll.
1467+ *
1468+ * We add \Windows\System32\Npcap here.
1469+ *
1470+ * See https://npcap.com/guide/npcap-devguide.html#npcap-feature-native-dll-implicitly
1471+ */
1472+ if (!SetDllDirectoryA ("C:\\Windows\\System32\\Npcap" ))
1473+ error ("SetDllDirectory failed" );
1474+ #endif
1475+
14401476 /*
14411477 * Initialize the netdissect code.
14421478 */
0 commit comments