Replace extcap_interface_list() with append_extcap_interface_list().

Pull the "rebuild the list of extcap interfaces and, optionally, return
a list of if_infos for them" into a separate
extcap_reload_interface_list() routine, call it in the cases where we
don't want the if_infos list, and have append_extcap_interface_list()
call it, asking it for the if_infos list, and then append the interfaces
to that list.

Change-Id: I07478ab133859484b3e0916144971639f961224b
Reviewed-on: https://code.wireshark.org/review/14189
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2016-02-26 17:04:05 -08:00
parent 60f87ca919
commit 842a9b5100
3 changed files with 43 additions and 38 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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 *