Add support for Npcap native mode:

1) Start Npcap service for capturing packets on
Windows if WinPcap service is unavailable.
2) Search Npcap DLLs (wpcap.dll, Packet.dll) also in
"system32\Npcap" folder after "system32" is searched.

Change-Id: I6810382db431a4e7fe309edd08757db60d8ade38
Reviewed-on: https://code.wireshark.org/review/15707
Reviewed-by: Yang Luo <hsluoyz@gmail.com>
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Yang Luo 2016-06-03 12:25:28 +08:00 committed by Guy Harris
parent da84de5dff
commit 6a860e948d
2 changed files with 38 additions and 4 deletions

View File

@ -73,6 +73,7 @@
static gchar *program_path = NULL;
static gchar *system_path = NULL;
static gchar *npcap_path = NULL;
/**
* g_open:
@ -472,7 +473,7 @@ init_dll_load_paths()
{
TCHAR path_w[MAX_PATH];
if (program_path && system_path)
if (program_path && system_path && npcap_path)
return TRUE;
/* XXX - Duplicate code in filesystem.c:init_progfile_dir */
@ -496,7 +497,13 @@ init_dll_load_paths()
system_path = g_utf16_to_utf8(path_w, -1, NULL, NULL, NULL);
}
if (program_path && system_path)
_tcscat_s(path_w, MAX_PATH, _T("\\Npcap"));
if (!npcap_path) {
npcap_path = g_utf16_to_utf8(path_w, -1, NULL, NULL, NULL);
}
if (program_path && system_path && npcap_path)
return TRUE;
return FALSE;
@ -568,6 +575,19 @@ ws_load_library(const gchar *library_name)
}
}
/* At last try the Npcap directory */
full_path = g_module_build_path(npcap_path, library_name);
full_path_w = g_utf8_to_utf16(full_path, -1, NULL, NULL, NULL);
if (full_path && full_path_w) {
dll_h = LoadLibraryW(full_path_w);
if (dll_h) {
g_free(full_path);
g_free(full_path_w);
return dll_h;
}
}
return NULL;
}
@ -602,6 +622,17 @@ ws_module_open(gchar *module_name, GModuleFlags flags)
}
}
/* At last try the Npcap directory */
full_path = g_module_build_path(npcap_path, module_name);
if (full_path) {
mod = g_module_open(full_path, flags);
if (mod) {
g_free(full_path);
return mod;
}
}
return NULL;
}

View File

@ -140,8 +140,11 @@ npf_sys_is_running() {
return FALSE;
h_serv = OpenService(h_scm, _T("npf"), SC_MANAGER_CONNECT|SERVICE_QUERY_STATUS);
if (!h_serv)
return FALSE;
if (!h_serv) {
h_serv = OpenService(h_scm, _T("npcap"), SC_MANAGER_CONNECT|SERVICE_QUERY_STATUS);
if (!h_serv)
return FALSE;
}
if (QueryServiceStatus(h_serv, &ss)) {
if (ss.dwCurrentState & SERVICE_RUNNING)