diff options
Diffstat (limited to 'wsutil/filesystem.c')
-rw-r--r-- | wsutil/filesystem.c | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/wsutil/filesystem.c b/wsutil/filesystem.c index 6125236bd7..99b3e5340e 100644 --- a/wsutil/filesystem.c +++ b/wsutil/filesystem.c @@ -1062,6 +1062,117 @@ get_plugin_dir(void) #endif } +#if defined(HAVE_EXTCAP) +/* + * Find the directory where the extcap hooks are stored. + * + * On Windows, we use the "extcap" subdirectory of the datafile directory. + * + * On UN*X, we use the EXTCAP_DIR value supplied by the configure + * script, unless we think we're being run from the build directory, + * in which case we use the "extcap" subdirectory of the datafile directory. + * + * In both cases, we then use the subdirectory of that directory whose + * name is the version number. + * + * XXX - if we think we're being run from the build directory, perhaps we + * should have the extcap code not look in the version subdirectory + * of the extcap directory, but look in all of the subdirectories + * of the extcap directory, so it can just fetch the extcap hooks built + * as part of the build process. + */ +static const char *extcap_dir = NULL; + +static void init_extcap_dir(void) { +#ifdef _WIN32 + /* + * On Windows, the data file directory is the installation + * directory; the extcap hooks are stored under it. + * + * Assume we're running the installed version of Wireshark; + * on Windows, the data file directory is the directory + * in which the Wireshark binary resides. + */ + extcap_dir = g_strdup_printf("%s\\extcap\\%s", get_datafile_dir(), + VERSION); + + /* + * Make sure that pathname refers to a directory. + */ + if (test_for_directory(extcap_dir) != EISDIR) { + /* + * Either it doesn't refer to a directory or it + * refers to something that doesn't exist. + * + * Assume that means we're running a version of + * Wireshark we've built in a build directory, + * in which case {datafile dir}\plugins is the + * top-level extcap hooks source directory, and use + * that directory and set the "we're running in + * a build directory" flag, so the plugin + * scanner will check all subdirectories of that + * directory for extcap hooks. + */ + g_free( (gpointer) extcap_dir); + extcap_dir = g_strdup_printf("%s\\extcap", get_datafile_dir()); + running_in_build_directory_flag = TRUE; + } +#else + if (running_in_build_directory_flag) { + /* + * We're (probably) being run from the build directory and + * weren't started with special privileges, so we'll use + * the "extcap hooks" subdirectory of the directory where the program + * we're running is (that's the build directory). + */ + extcap_dir = g_strdup_printf("%s/extcap", get_progfile_dir()); + } else { + if (getenv("WIRESHARK_EXTCAP_DIR") && !started_with_special_privs()) { + /* + * The user specified a different directory for extcap hooks + * and we aren't running with special privileges. + */ + extcap_dir = g_strdup(getenv("WIRESHARK_EXTCAP_DIR")); + } +#ifdef __APPLE__ + /* + * If we're running from an app bundle and weren't started + * with special privileges, use the Contents/Resources/lib/wireshark/extcap + * subdirectory of the app bundle. + * + * (appbundle_dir is not set to a non-null value if we're + * started with special privileges, so we need only check + * it; we don't need to call started_with_special_privs().) + */ + else if (appbundle_dir != NULL) { + extcap_dir = g_strdup_printf("%s/Contents/Resources/lib/wireshark/extcap", + appbundle_dir); + } +#endif + else { + extcap_dir = EXTCAP_DIR; + } + } +#endif +} +#endif /* HAVE_EXTCAP */ + +/* + * Get the directory in which the extcap hooks are stored. + * + * XXX - A fix instead of HAVE_EXTCAP must be found + */ +const char * +get_extcap_dir(void) { +#if defined(HAVE_EXTCAP) + if (!extcap_dir) + init_extcap_dir(); + return extcap_dir; +#else + return NULL; +#endif +} + /* * Get the flag indicating whether we're running from a build * directory. |