Skip to content

Commit

Permalink
wsutil: Switch away from G_MODULE_SUFFIX and g_module_build_path
Browse files Browse the repository at this point in the history
GLib 2.76 deprecated G_MODULE_SUFFIX, so just use ".dll" on Windows and
".so" elsewhere. It also deprecated g_module_build_path, so just use
g_strconcat.

ws_module_open was only used to open wpcap.dll, so rename it to
load_wpcap_module.
  • Loading branch information
geraldcombs authored and randstr committed Apr 11, 2023
1 parent 764982a commit 1ffff91
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion capture/capture-wpcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ load_wpcap(void)
GModule *wh; /* wpcap handle */
const symbol_table_t *sym;

wh = ws_module_open("wpcap.dll", 0);
wh = load_wpcap_module();

if (!wh) {
return;
Expand Down
2 changes: 1 addition & 1 deletion doc/README.capture
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Capture driver
Wireshark doesn't have direct access to the capture hardware. Instead of this,
it uses the Libpcap/Winpcap library to capture data from network cards.

On Win32, in capture-wpcap.c the function ws_module_open("wpcap.dll") is called
On Win32, in capture-wpcap.c the function load_wpcap_module() is called
to load the wpcap.dll. This dll includes all functions needed for
packet capturing.

Expand Down
16 changes: 9 additions & 7 deletions wsutil/file_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ ws_load_library(const gchar *library_name)
return NULL;

/* First try the program directory */
full_path = g_module_build_path(program_path, library_name);
full_path = g_strconcat(program_path, G_DIR_SEPARATOR_S, library_name, NULL);
full_path_w = g_utf8_to_utf16(full_path, -1, NULL, NULL, NULL);

if (full_path && full_path_w) {
Expand All @@ -540,7 +540,7 @@ ws_load_library(const gchar *library_name)
}

/* Next try the system directory */
full_path = g_module_build_path(system_path, library_name);
full_path = g_strconcat(system_path, G_DIR_SEPARATOR_S, library_name, NULL);
full_path_w = g_utf8_to_utf16(full_path, -1, NULL, NULL, NULL);

if (full_path && full_path_w) {
Expand Down Expand Up @@ -580,16 +580,18 @@ load_npcap_module(const gchar *full_path, GModuleFlags flags)
}

GModule *
ws_module_open(gchar *module_name, GModuleFlags flags)
load_wpcap_module(void)
{
gchar *module_name = "wpcap.dll";
gchar *full_path;
GModule *mod;
GModuleFlags flags = 0;

if (!init_dll_load_paths() || !module_name)
if (!init_dll_load_paths())
return NULL;

/* First try the program directory */
full_path = g_module_build_path(program_path, module_name);
full_path = g_strconcat(program_path, G_DIR_SEPARATOR_S, module_name, NULL);

if (full_path) {
mod = g_module_open(full_path, flags);
Expand All @@ -600,7 +602,7 @@ ws_module_open(gchar *module_name, GModuleFlags flags)
}

/* Next try the Npcap directory */
full_path = g_module_build_path(npcap_path, module_name);
full_path = g_strconcat(npcap_path, G_DIR_SEPARATOR_S, module_name, NULL);

if (full_path) {
mod = load_npcap_module(full_path, flags);
Expand All @@ -611,7 +613,7 @@ ws_module_open(gchar *module_name, GModuleFlags flags)
}

/* At last try the system directory */
full_path = g_module_build_path(system_path, module_name);
full_path = g_strconcat(system_path, G_DIR_SEPARATOR_S, module_name, NULL);

if (full_path) {
mod = g_module_open(full_path, flags);
Expand Down
6 changes: 2 additions & 4 deletions wsutil/file_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,13 @@ gboolean ws_init_dll_search_path(void);
WS_DLL_PUBLIC
void *ws_load_library(const gchar *library_name);

/** Load a DLL using g_module_open.
/** Load wpcap.dll using g_module_open.
* Only the system and program directories are searched.
*
* @param module_name The name of the DLL.
* @param flags Flags to be passed to g_module_open.
* @return A handle to the DLL if found, NULL on failure.
*/
WS_DLL_PUBLIC
GModule *ws_module_open(gchar *module_name, GModuleFlags flags);
GModule *load_wpcap_module(void);

/** Create or open a "Wireshark is running" mutex.
* Create or open a mutex which signals that Wireshark or its associated
Expand Down
11 changes: 9 additions & 2 deletions wsutil/plugins.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ pass_plugin_version_compatibility(GModule *handle, const char *name)
return TRUE;
}

// GLib and Qt allow ".dylib" and ".so" on macOS. Should we do the same?
#ifdef _WIN32
#define MODULE_SUFFIX ".dll"
#else
#define MODULE_SUFFIX ".so"
#endif

static void
scan_plugins_dir(GHashTable *plugins_module, const char *dirpath, plugin_type_e type, gboolean append_type)
{
Expand All @@ -146,8 +153,8 @@ scan_plugins_dir(GHashTable *plugins_module, const char *dirpath, plugin_type_e
}

while ((name = g_dir_read_name(dir)) != NULL) {
/* Skip anything but files with G_MODULE_SUFFIX. */
if (!g_str_has_suffix(name, "." G_MODULE_SUFFIX))
/* Skip anything but files with .dll or .so. */
if (!g_str_has_suffix(name, MODULE_SUFFIX))
continue;

/*
Expand Down

0 comments on commit 1ffff91

Please sign in to comment.