extcap: Sort extcap interfaces alphabetically
authorRoland Knall <roland.knall@br-automation.com>
Tue, 12 Jan 2016 09:47:19 +0000 (10:47 +0100)
committerRoland Knall <rknall@gmail.com>
Tue, 12 Jan 2016 11:07:35 +0000 (11:07 +0000)
The interface list is not sorted at all, leading to
a very chaotic list. This sorts it alphabetically, as
well as correct a type in extcap_init_interfaces.

Bug: 11998
Change-Id: Ib5381a1761e8f07f9ba7996b3e6276da063b3932
Reviewed-on: https://code.wireshark.org/review/13220
Petri-Dish: Roland Knall <rknall@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Roland Knall <rknall@gmail.com>
capchild/capture_sync.c
extcap.c
extcap.h

index 6f02219d60f7b13fa5bf6e272317f8451759a99c..5cb3881da8a6d503b9e4358eefb3a662acf8d950 100644 (file)
@@ -392,7 +392,7 @@ sync_pipe_start(capture_options *capture_opts, capture_session *cap_session, inf
     cap_session->fork_child = WS_INVALID_PID;
 
 #ifdef HAVE_EXTCAP
-    if (!extcaps_init_initerfaces(capture_opts)) {
+    if (!extcap_init_interfaces(capture_opts)) {
         report_failure("Unable to init extcaps. (tmp fifo already exists?)");
         return FALSE;
     }
index 6d66ad167cec9a269f2b1636cf804f8a4ea9dcb6..4d2a14a29dbf939dce563214ce5bc75c748697ab 100644 (file)
--- a/extcap.c
+++ b/extcap.c
@@ -57,7 +57,7 @@ static HANDLE pipe_h = NULL;
 
 /* internal container, for all the extcap interfaces that have been found.
  * will be resetted by every call to extcap_interface_list() and is being
- * used in extcap_get_if_* as well as extcaps_init_initerfaces to ensure,
+ * used in extcap_get_if_* as well as extcap_init_interfaces to ensure,
  * that only extcap interfaces are being given to underlying extcap programs
  */
 static GHashTable *ifaces = NULL;
@@ -345,6 +345,19 @@ static gboolean interfaces_cb(const gchar *extcap, gchar *output, void *data,
     return TRUE;
 }
 
+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;
+
+    if ( (comp = g_strcmp0(if_a->name, if_b->name)) == 0 )
+        return g_strcmp0(if_a->friendly_name, if_b->friendly_name);
+
+    return comp;
+}
+
 GList *
 extcap_interface_list(char **err_str) {
     gchar *argv;
@@ -366,12 +379,7 @@ extcap_interface_list(char **err_str) {
 
     g_free(argv);
 
-    return ret;
-}
-
-static void g_free_1(gpointer data, gpointer user_data _U_)
-{
-    g_free(data);
+    return g_list_sort ( ret, if_info_compare );
 }
 
 static void extcap_free_if_configuration(GList *list)
@@ -380,15 +388,8 @@ static void extcap_free_if_configuration(GList *list)
 
     for (elem = g_list_first(list); elem; elem = elem->next)
     {
-        GList *arg_list;
-        if (elem->data == NULL)
-        {
-            continue;
-        }
-
-        arg_list = g_list_first((GList *)elem->data);
-        g_list_foreach(arg_list, g_free_1, NULL);
-        g_list_free(arg_list);
+        if (elem->data != NULL)
+            g_list_free_full(g_list_first((GList *)elem->data), g_free);
     }
     g_list_free(list);
 }
@@ -568,7 +569,7 @@ static void extcap_child_watch_cb(GPid pid, gint status _U_, gpointer user_data)
 /* call mkfifo for each extcap,
  * returns FALSE if there's an error creating a FIFO */
 gboolean
-extcaps_init_initerfaces(capture_options *capture_opts)
+extcap_init_interfaces(capture_options *capture_opts)
 {
     guint i;
     interface_options interface_opts;
index 813d4bd740a631fe135faeca4c9dcb70503c2018..fa334c59c6e5cb3539a60887fdb7bdea629edcee 100644 (file)
--- a/extcap.h
+++ b/extcap.h
@@ -75,7 +75,7 @@ extcap_get_win32_handle();
 #endif
 
 gboolean
-extcaps_init_initerfaces(capture_options * capture_opts);
+extcap_init_interfaces(capture_options * capture_opts);
 
 gboolean
 extcap_create_pipe(char ** fifo);