Allow create_tempfile to support a suffix.
[metze/wireshark/wip.git] / extcap.c
index 93549ded443e3014dfcf45c6b0e77d3f5ca62214..29f931ac125a81f9c2178044e1e3301a67de4a55 100644 (file)
--- a/extcap.c
+++ b/extcap.c
@@ -49,8 +49,6 @@
 
 #include "capture_opts.h"
 
-#ifdef HAVE_EXTCAP
-
 #include "extcap.h"
 #include "extcap_parser.h"
 
@@ -116,6 +114,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)
 {
@@ -203,7 +211,7 @@ static void extcap_foreach(gint argc, gchar **args, extcap_cb_t cb,
                     &command_output, NULL, &exit_status, NULL);
 
             if (status && exit_status == 0)
-            keep_going = cb(extcap_path->str, ifname, command_output, cb_data, err_str);
+                keep_going = cb(extcap_path->str, ifname, command_output, cb_data, err_str);
 
             g_free(argv[0]);
             g_free(command_output);
@@ -282,7 +290,7 @@ extcap_get_if_dlts(const gchar *ifname, char **err_str) {
     gint i;
     if_capabilities_t *caps = NULL;
 
-    if (ifname != NULL && err_str != NULL)
+    if (err_str != NULL)
         *err_str = NULL;
 
     if ( extcap_if_exists(ifname) )
@@ -291,8 +299,6 @@ extcap_get_if_dlts(const gchar *ifname, char **err_str) {
         argv[1] = g_strdup(EXTCAP_ARGUMENT_INTERFACE);
         argv[2] = g_strdup(ifname);
 
-        if (err_str)
-            *err_str = NULL;
         extcap_foreach(3, argv, dlt_cb, &caps, err_str, ifname);
 
         for (i = 0; i < 3; ++i)
@@ -333,14 +339,16 @@ static gboolean interfaces_cb(const gchar *extcap, const gchar *ifname _U_, gcha
             g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "  Extcap [%s] ", int_iter->call);
 
         if ( int_iter->if_type == EXTCAP_SENTENCE_INTERFACE ) {
-            if_info = g_new0(if_info_t, 1);
-            if_info->name = g_strdup(int_iter->call);
-            if_info->friendly_name = g_strdup(int_iter->display);
+            if (il != NULL) {
+                if_info = g_new0(if_info_t, 1);
+                if_info->name = g_strdup(int_iter->call);
+                if_info->friendly_name = g_strdup(int_iter->display);
 
-            if_info->type = IF_EXTCAP;
+                if_info->type = IF_EXTCAP;
 
-            if_info->extcap = g_strdup(extcap);
-            *il = g_list_append(*il, if_info);
+                if_info->extcap = g_strdup(extcap);
+                *il = g_list_append(*il, if_info);
+            }
 
             extcap_if_add(int_iter->call, extcap);
         }
@@ -360,8 +368,8 @@ static gint
 if_info_compare(gconstpointer a, gconstpointer b)
 {
     gint comp = 0;
-    if_info_t * if_a = (if_info_t *)a;
-    if_info_t * if_b = (if_info_t *)b;
+    const if_info_t * if_a = (const if_info_t *)a;
+    const if_info_t * if_b = (const if_info_t *)b;
 
     if ( (comp = g_strcmp0(if_a->name, if_b->name)) == 0 )
         return g_strcmp0(if_a->friendly_name, if_b->friendly_name);
@@ -369,32 +377,12 @@ 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);
-
-    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);
-}
-
-GList *
-extcap_interface_list(char **err_str) {
+extcap_reload_interface_list(GList **retp, char **err_str) {
     gchar *argv;
-    /* gint i; */
-    GList *ret = NULL;
 
     if (err_str != NULL)
-    *err_str = NULL;
+        *err_str = NULL;
 
     /* ifaces is used as cache, do not destroy its contents when
      * returning or no extcap interfaces can be queried for options */
@@ -410,13 +398,39 @@ extcap_interface_list(char **err_str) {
 
     argv = g_strdup(EXTCAP_ARGUMENT_LIST_INTERFACES);
 
-    if (err_str)
-    *err_str = NULL;
-    extcap_foreach(1, &argv, interfaces_cb, &ret, err_str, NULL);
+    extcap_foreach(1, &argv, interfaces_cb, retp, err_str, NULL);
 
     g_free(argv);
+}
 
-    return 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);
+
+    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_) {
@@ -434,7 +448,7 @@ void extcap_register_preferences(void)
         return;
 
     if ( ! ifaces || g_hash_table_size(ifaces) == 0 )
-        extcap_interface_list(NULL);
+        extcap_reload_interface_list(NULL, NULL);
 
     interfaces = g_hash_table_get_keys(ifaces);
 
@@ -523,7 +537,7 @@ static gboolean search_cb(const gchar *extcap _U_, const gchar *ifname _U_, gcha
                         arg->storeval = g_strdup(arg->default_complex->_val);
 
                     prefs_register_string_preference(dev_module, g_strdup(pref_ifname),
-                            arg->display, arg->display, (const gchar **)&(arg->storeval));
+                            arg->display, arg->display, (const gchar **)(void*)(&arg->storeval));
                 } else {
                     /* Been here before, restore stored value */
                     if (! arg->storeval && pref->varp.string)
@@ -960,7 +974,7 @@ gboolean extcap_create_pipe(char ** fifo)
     gchar *temp_name = NULL;
     int fd = 0;
 
-    if ((fd = create_tempfile(&temp_name, EXTCAP_PIPE_PREFIX)) < 0 )
+    if ((fd = create_tempfile(&temp_name, EXTCAP_PIPE_PREFIX, NULL)) < 0 )
         return FALSE;
 
     ws_close(fd);
@@ -1048,7 +1062,6 @@ void extcap_debug_arguments ( extcap_arg *arg_iter )
     }
 }
 #endif
-#endif
 
 /*
  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html