diff --git a/capchild/capture_ifinfo.c b/capchild/capture_ifinfo.c index 5c4f299415..3d848814d9 100644 --- a/capchild/capture_ifinfo.c +++ b/capchild/capture_ifinfo.c @@ -200,7 +200,7 @@ capture_interface_list(int *err, char **err_str, void (*update_cb)(void)) #ifdef HAVE_EXTCAP /* Add the extcap interfaces after the native and remote interfaces */ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Loading External Capture Interface List ..."); - extcap_interface_list(&if_list, err_str); + if_list = append_extcap_interface_list(if_list, err_str); #endif return if_list; diff --git a/extcap.c b/extcap.c index 2c4444b12a..d60d6aa0b5 100644 --- a/extcap.c +++ b/extcap.c @@ -116,6 +116,16 @@ extcap_if_add(const gchar *ifname, const gchar *extcap) g_hash_table_insert(ifaces, g_strdup(ifname), g_strdup(extcap)); } +static void +extcap_free_info (gpointer data) { + extcap_info * info = (extcap_info *)data; + + g_free (info->basename); + g_free (info->full_path); + g_free (info->version); + g_free (info); +} + static void extcap_tool_add(const gchar *extcap, const extcap_interface *interface) { @@ -369,31 +379,9 @@ if_info_compare(gconstpointer a, gconstpointer b) return comp; } -GHashTable * -extcap_tools_list(void) { - if ( tools == NULL || g_hash_table_size(tools) == 0 ) - extcap_interface_list(NULL, NULL); - - return tools; -} - static void -extcap_free_info (gpointer data) { - extcap_info * info = (extcap_info *)data; - - g_free (info->basename); - g_free (info->full_path); - g_free (info->version); - g_free (info); -} - -void -extcap_interface_list(GList **listp, char **err_str) { +extcap_reload_interface_list(GList **retp, char **err_str) { gchar *argv; - /* gint i; */ - GList *ret = NULL; - GList *entry; - void *data; if (err_str != NULL) *err_str = NULL; @@ -412,22 +400,39 @@ extcap_interface_list(GList **listp, char **err_str) { argv = g_strdup(EXTCAP_ARGUMENT_LIST_INTERFACES); - extcap_foreach(1, &argv, interfaces_cb, (listp != NULL) ? &ret : NULL, err_str, NULL); + extcap_foreach(1, &argv, interfaces_cb, retp, err_str, NULL); g_free(argv); +} - if (listp != NULL) { - /* Sort the list */ - ret = g_list_sort(ret, if_info_compare); +GHashTable * +extcap_tools_list(void) { + if ( tools == NULL || g_hash_table_size(tools) == 0 ) + extcap_reload_interface_list(NULL, NULL); - /* Append the interfaces to the list. */ - while (ret != NULL) { - entry = g_list_first(ret); - data = entry->data; - ret = g_list_delete_link(ret, entry); - *listp = g_list_append(*listp, data); - } + return tools; +} + +GList * +append_extcap_interface_list(GList *list, char **err_str) { + GList *ret = NULL; + GList *entry; + void *data; + + /* Update the extcap interfaces and get a list of their if_infos */ + extcap_reload_interface_list(&ret, err_str); + + /* Sort that list */ + ret = g_list_sort(ret, if_info_compare); + + /* Append the interfaces in that list to the list we're handed. */ + while (ret != NULL) { + entry = g_list_first(ret); + data = entry->data; + ret = g_list_delete_link(ret, entry); + list = g_list_append(list, data); } + return list; } static void extcap_free_arg_elem(gpointer data, gpointer user_data _U_) { @@ -445,7 +450,7 @@ void extcap_register_preferences(void) return; if ( ! ifaces || g_hash_table_size(ifaces) == 0 ) - extcap_interface_list(NULL, NULL); + extcap_reload_interface_list(NULL, NULL); interfaces = g_hash_table_get_keys(ifaces); diff --git a/extcap.h b/extcap.h index d63cb17cb5..9701ae52e3 100644 --- a/extcap.h +++ b/extcap.h @@ -72,8 +72,8 @@ if_capabilities_t * extcap_get_if_dlts(const gchar * ifname, char ** err_str); /* append a list of all extcap capture interfaces to the specified list */ -void -extcap_interface_list(GList **listp, char **err_str); +GList * +append_extcap_interface_list(GList *list, char **err_str); /* get a list of all available extcap tools */ GHashTable *