3 * $Id: wtap.h 21651 2007-05-02 20:09:42Z lego $
6 * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
47 #include "file_util.h"
49 #define PLUGINS_DIR_NAME "wiretap_plugins"
51 static gboolean plugins_loaded = FALSE;
53 void wtap_load_plugins(char* dirname) {
55 #define FILENAME_LEN 1024
56 ETH_DIR *dir; /* scanned directory */
57 ETH_DIRENT *file; /* current file */
59 #if GLIB_MAJOR_VERSION < 2
60 gchar *hack_path; /* pathname used to construct lt_lib_ext */
61 gchar *lt_lib_ext; /* extension for loadable modules */
63 gchar filename[FILENAME_LEN]; /* current file name */
64 GModule *handle; /* handle returned by dlopen */
69 if (plugins_loaded || ! dirname) return;
71 plugins_loaded = TRUE;
73 #if GLIB_MAJOR_VERSION < 2
75 * We find the extension used on this platform for loadable modules
76 * by the sneaky hack of calling "g_module_build_path" to build
77 * the pathname for a module with an empty directory name and
78 * empty module name, and then search for the last "." and use
79 * everything from the last "." on.
81 hack_path = g_module_build_path("", "");
82 lt_lib_ext = strrchr(hack_path, '.');
83 if (lt_lib_ext == NULL)
86 * Does this mean there *is* no extension? Assume so.
88 * XXX - the code below assumes that all loadable modules have
95 if ((dir = eth_dir_open(dirname, 0, NULL)) != NULL)
97 while ((file = eth_dir_read_name(dir)) != NULL)
99 name = eth_dir_get_name(file);
100 #if GLIB_MAJOR_VERSION < 2
101 /* don't try to open "." and ".." */
102 if (!(strcmp(name, "..") &&
106 /* skip anything but files with lt_lib_ext */
107 dot = strrchr(name, '.');
108 if (dot == NULL || strcmp(dot, lt_lib_ext) != 0)
113 * GLib 2.x defines G_MODULE_SUFFIX as the extension used on
114 * this platform for loadable modules.
116 /* skip anything but files with G_MODULE_SUFFIX */
117 dot = strrchr(name, '.');
118 if (dot == NULL || strcmp(dot+1, G_MODULE_SUFFIX) != 0)
122 g_snprintf(filename, FILENAME_LEN, "%s" G_DIR_SEPARATOR_S "%s",
124 if ((handle = g_module_open(filename, 0)) == NULL)
126 g_warning("Couldn't load module %s: %s", filename,
130 if (!g_module_symbol(handle, "version", &gp))
132 g_warning("The plugin %s has no version symbol", name);
133 g_module_close(handle);
138 if (g_module_symbol(handle, "register_wtap_module", &gp))
140 void (*register_wtap_module)(void) = gp;
141 register_wtap_module();
146 #if GLIB_MAJOR_VERSION < 2