extcap: Fix crash in extcap_verify_capture_filter
[metze/wireshark/wip.git] / extcap.c
index 260032096d260d61d0379e9afab9a5ed36c84eb5..c5f446a6d097e03ce275d046d05be6c5e4231ded 100644 (file)
--- a/extcap.c
+++ b/extcap.c
@@ -7,19 +7,7 @@
  * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
 #include <config.h>
 
 #include <epan/prefs.h>
 
+#include "ui/iface_toolbar.h"
+
+#include <wsutil/glib-compat.h>
 #include <wsutil/file_util.h>
 #include <wsutil/filesystem.h>
+#include <wsutil/ws_pipe.h>
 #include <wsutil/tempfile.h>
 
 #include "capture_opts.h"
 
 #include "extcap.h"
 #include "extcap_parser.h"
-#include "extcap_spawn.h"
+
+#include "version_info.h"
 
 #ifdef _WIN32
-static HANDLE pipe_h = NULL;
+static HANDLE pipe_h = INVALID_HANDLE_VALUE;
 #endif
 
 static void extcap_child_watch_cb(GPid pid, gint status, gpointer user_data);
@@ -73,25 +66,41 @@ static void extcap_child_watch_cb(GPid pid, gint status, gpointer user_data);
 static GHashTable * _loaded_interfaces = NULL;
 
 /* Internal container, which maps each ifname to the tool providing it, for faster
- * lookup.
+ * lookup. The key and string value are owned by this table.
  */
 static GHashTable * _tool_for_ifname = NULL;
 
+/* internal container, for all the extcap executables that have been found
+ * and that provides a toolbar with controls to be added to a Interface Toolbar
+ */
+static GHashTable *_toolbars = NULL;
+
 /* internal container, to map preference names to pointers that hold preference
  * values. These ensure that preferences can survive extcap if garbage
  * collection, and does not lead to dangling pointers in the prefs subsystem.
  */
 static GHashTable *extcap_prefs_dynamic_vals = NULL;
 
+typedef struct _extcap_callback_info_t
+{
+    const gchar * extcap;
+    const gchar * ifname;
+    gchar * output;
+    void * data;
+    gchar ** err_str;
+} extcap_callback_info_t;
+
 /* Callback definition for extcap_foreach */
-typedef gboolean(*extcap_cb_t)(const gchar *extcap, const gchar *ifname, gchar *output, void *data,
-                               gchar **err_str);
+typedef gboolean(*extcap_cb_t)(extcap_callback_info_t info_structure);
 
 static void extcap_load_interface_list(void);
 
 GHashTable *
 extcap_loaded_interfaces(void)
 {
+    if (prefs.capture_no_extcap)
+        return NULL;
+
     if ( !_loaded_interfaces || g_hash_table_size(_loaded_interfaces) == 0 )
         extcap_load_interface_list();
 
@@ -129,7 +138,8 @@ guint extcap_count(void)
             /* full path to extcap binary */
             g_string_printf(extcap_path, "%s" G_DIR_SEPARATOR_S "%s", dirname, file);
             /* treat anything executable as an extcap binary */
-            if (g_file_test(extcap_path->str, G_FILE_TEST_IS_EXECUTABLE))
+            if (g_file_test(extcap_path->str, G_FILE_TEST_IS_REGULAR) &&
+                g_file_test(extcap_path->str, G_FILE_TEST_IS_EXECUTABLE))
             {
                 count++;
             }
@@ -189,6 +199,56 @@ extcap_find_interface_for_ifname(const gchar *ifname)
     return result;
 }
 
+static void
+extcap_free_toolbar_value(iface_toolbar_value *value)
+{
+    if (!value)
+    {
+        return;
+    }
+
+    g_free(value->value);
+    g_free(value->display);
+    g_free(value);
+}
+
+static void
+extcap_free_toolbar_control(iface_toolbar_control *control)
+{
+    if (!control)
+    {
+        return;
+    }
+
+    g_free(control->display);
+    g_free(control->validation);
+    g_free(control->tooltip);
+    if (control->ctrl_type == INTERFACE_TYPE_STRING) {
+        g_free(control->default_value.string);
+    }
+    g_list_foreach(control->values, (GFunc)extcap_free_toolbar_value, NULL);
+    g_list_free(control->values);
+    g_free(control);
+}
+
+static void
+extcap_free_toolbar(gpointer data)
+{
+    if (!data)
+    {
+        return;
+    }
+
+    iface_toolbar *toolbar = (iface_toolbar *)data;
+
+    g_free(toolbar->menu_title);
+    g_free(toolbar->help);
+    g_list_free_full(toolbar->ifnames, g_free);
+    g_list_foreach(toolbar->controls, (GFunc)extcap_free_toolbar_control, NULL);
+    g_list_free(toolbar->controls);
+    g_free(toolbar);
+}
+
 static gboolean
 extcap_if_exists_for_extcap(const gchar *ifname, const gchar *extcap)
 {
@@ -209,20 +269,72 @@ extcap_if_executable(const gchar *ifname)
     return interface != NULL ? interface->extcap_path : NULL;
 }
 
+static void
+extcap_iface_toolbar_add(const gchar *extcap, iface_toolbar *toolbar_entry)
+{
+    char *toolname;
+
+    if (!extcap || !toolbar_entry)
+    {
+        return;
+    }
+
+    toolname = g_path_get_basename(extcap);
+
+    if (!g_hash_table_lookup(_toolbars, toolname))
+    {
+        g_hash_table_insert(_toolbars, g_strdup(toolname), toolbar_entry);
+    }
+
+    g_free(toolname);
+}
+
+static gchar **
+extcap_convert_arguments_to_array(GList * arguments)
+{
+    gchar ** result = NULL;
+    if ( arguments )
+    {
+        GList * walker = g_list_first(arguments);
+        int cnt = 0;
+
+        result = (gchar **) g_malloc0(sizeof(gchar *) * (g_list_length(arguments)));
+
+        while(walker)
+        {
+            result[cnt] = g_strdup((const gchar *)walker->data);
+            walker = g_list_next(walker);
+            cnt++;
+        }
+    }
+    return result;
+}
+
+static void extcap_free_array(gchar ** args, int argc)
+{
+    int cnt = 0;
+
+    for ( cnt = 0; cnt < argc; cnt++ )
+        g_free(args[cnt]);
+    g_free(args);
+}
+
 /* Note: args does not need to be NULL-terminated. */
-static void extcap_foreach(gint argc, gchar **args, extcap_cb_t cb,
-                           void *cb_data, char **err_str, const char *ifname)
+static gboolean extcap_foreach(GList * arguments,
+                                      extcap_cb_t cb, extcap_callback_info_t cb_info, GList * fallback_arguments)
 {
-    const char *dirname = get_extcap_dir();
     GDir *dir;
     gboolean keep_going;
+    const char *dirname = get_extcap_dir();
 
     keep_going = TRUE;
 
-    if ((dir = g_dir_open(dirname, 0, NULL)) != NULL)
+    if (arguments && (dir = g_dir_open(dirname, 0, NULL)) != NULL)
     {
         GString *extcap_path = NULL;
         const gchar *file;
+        gchar ** args = extcap_convert_arguments_to_array(arguments);
+        int cnt = g_list_length(arguments);
 
         extcap_path = g_string_new("");
         while (keep_going && (file = g_dir_read_name(dir)) != NULL)
@@ -231,23 +343,46 @@ static void extcap_foreach(gint argc, gchar **args, extcap_cb_t cb,
 
             /* full path to extcap binary */
             g_string_printf(extcap_path, "%s" G_DIR_SEPARATOR_S "%s", dirname, file);
-            if (extcap_if_exists(ifname) && !extcap_if_exists_for_extcap(ifname, extcap_path->str))
+            /* treat anything executable as an extcap binary */
+            if (g_file_test(extcap_path->str, G_FILE_TEST_IS_REGULAR) &&
+                g_file_test(extcap_path->str, G_FILE_TEST_IS_EXECUTABLE))
             {
-                continue;
-            }
+                if (extcap_if_exists(cb_info.ifname) && !extcap_if_exists_for_extcap(cb_info.ifname, extcap_path->str))
+                {
+                    continue;
+                }
 
-            if (extcap_spawn_sync((gchar *) dirname, extcap_path->str, argc, args, &command_output))
-            {
-                keep_going = cb(extcap_path->str, ifname, command_output, cb_data, err_str);
+                if (ws_pipe_spawn_sync((gchar *) dirname, extcap_path->str, cnt, args, &command_output))
+                {
+                    cb_info.output = command_output;
+                    cb_info.extcap = extcap_path->str;
+
+                    keep_going = cb(cb_info);
+                }
+                else if ( fallback_arguments )
+                {
+                    gchar ** fb_args = extcap_convert_arguments_to_array(fallback_arguments);
+
+                    if (ws_pipe_spawn_sync((gchar *) dirname, extcap_path->str, g_list_length(fallback_arguments), fb_args, &command_output))
+                    {
+                        cb_info.output = command_output;
+                        cb_info.extcap = extcap_path->str;
+
+                        keep_going = cb(cb_info);
+                    }
+                }
+
+                g_free(command_output);
             }
 
-            g_free(command_output);
         }
+        extcap_free_array(args, cnt);
 
         g_dir_close(dir);
         g_string_free(extcap_path, TRUE);
     }
 
+    return keep_going;
 }
 
 static void extcap_free_dlt(gpointer d, gpointer user_data _U_)
@@ -268,8 +403,7 @@ static void extcap_free_dlts(GList *dlts)
     g_list_free(dlts);
 }
 
-static gboolean dlt_cb(const gchar *extcap _U_, const gchar *ifname _U_, gchar *output, void *data,
-                       char **err_str)
+static gboolean cb_dlt(extcap_callback_info_t cb_info)
 {
     GList *dlts = NULL, *temp = NULL;
 
@@ -278,16 +412,17 @@ static gboolean dlt_cb(const gchar *extcap _U_, const gchar *ifname _U_, gchar *
     data_link_info_t *data_link_info;
     extcap_dlt *dlt_item;
 
-    dlts = extcap_parse_dlts(output);
+    dlts = extcap_parse_dlts(cb_info.output);
     temp = dlts;
 
-    g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "Extcap pipe %s ", extcap);
+    g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "Extcap pipe %s ", cb_info.extcap);
 
     /*
      * Allocate the interface capabilities structure.
      */
     caps = (if_capabilities_t *) g_malloc(sizeof * caps);
     caps->can_set_rfmon = FALSE;
+    caps->timestamp_types = NULL;
 
     while (dlts)
     {
@@ -309,17 +444,17 @@ static gboolean dlt_cb(const gchar *extcap _U_, const gchar *ifname _U_, gchar *
     }
 
     /* Check to see if we built a list */
-    if (linktype_list != NULL && data != NULL)
+    if (linktype_list != NULL && cb_info.data != NULL)
     {
         caps->data_link_types = linktype_list;
-        *(if_capabilities_t **) data = caps;
+        *(if_capabilities_t **) cb_info.data = caps;
     }
     else
     {
-        if (err_str)
+        if (cb_info.err_str)
         {
             g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "  returned no DLTs");
-            *err_str = g_strdup("Extcap returned no DLTs");
+            *(cb_info.err_str) = g_strdup("Extcap returned no DLTs");
         }
         g_free(caps);
     }
@@ -332,8 +467,7 @@ static gboolean dlt_cb(const gchar *extcap _U_, const gchar *ifname _U_, gchar *
 if_capabilities_t *
 extcap_get_if_dlts(const gchar *ifname, char **err_str)
 {
-    gchar *argv[3];
-    gint i;
+    GList * arguments = NULL;
     if_capabilities_t *caps = NULL;
 
     if (err_str != NULL)
@@ -343,16 +477,18 @@ extcap_get_if_dlts(const gchar *ifname, char **err_str)
 
     if (extcap_if_exists(ifname))
     {
-        argv[0] = g_strdup(EXTCAP_ARGUMENT_LIST_DLTS);
-        argv[1] = g_strdup(EXTCAP_ARGUMENT_INTERFACE);
-        argv[2] = g_strdup(ifname);
+        arguments = g_list_append(arguments, g_strdup(EXTCAP_ARGUMENT_LIST_DLTS));
+        arguments = g_list_append(arguments, g_strdup(EXTCAP_ARGUMENT_INTERFACE));
+        arguments = g_list_append(arguments, g_strdup(ifname));
 
-        extcap_foreach(3, argv, dlt_cb, &caps, err_str, ifname);
+        extcap_callback_info_t cb_info;
+        cb_info.data = &caps;
+        cb_info.err_str = err_str;
+        cb_info.ifname = ifname;
 
-        for (i = 0; i < 3; ++i)
-        {
-            g_free(argv[i]);
-        }
+        extcap_foreach(arguments, cb_dlt, cb_info, NULL);
+
+        g_list_free_full(arguments, g_free);
     }
 
     return caps;
@@ -414,13 +550,17 @@ append_extcap_interface_list(GList *list, char **err_str _U_)
 {
     GList *interface_list = NULL;
     extcap_interface *data = NULL;
-    GList * ifutilkeys = NULL;
+    GList *ifutilkeys_head = NULL, *ifutilkeys = NULL;
+
+    if (prefs.capture_no_extcap)
+        return list;
 
     /* Update the extcap interfaces and get a list of their if_infos */
     if ( !_loaded_interfaces || g_hash_table_size(_loaded_interfaces) == 0 )
         extcap_load_interface_list();
 
-    ifutilkeys = g_hash_table_get_keys(_loaded_interfaces);
+    ifutilkeys_head = g_hash_table_get_keys(_loaded_interfaces);
+    ifutilkeys = ifutilkeys_head;
     while ( ifutilkeys && ifutilkeys->data )
     {
         extcap_info * extinfo =
@@ -434,6 +574,7 @@ append_extcap_interface_list(GList *list, char **err_str _U_)
 
         ifutilkeys = g_list_next(ifutilkeys);
     }
+    g_list_free(ifutilkeys_head);
 
     /* Sort that list */
     interface_list = g_list_sort(interface_list, if_info_compare);
@@ -472,6 +613,9 @@ extcap_register_preferences_callback(gpointer key, gpointer value _U_, gpointer
 
 void extcap_register_preferences(void)
 {
+    if (prefs.capture_no_extcap)
+        return;
+
     module_t *dev_module = prefs_find_module("extcap");
 
     if (!dev_module)
@@ -502,16 +646,6 @@ void extcap_cleanup(void)
         g_hash_table_destroy(_tool_for_ifname);
 }
 
-void extcap_pref_store(extcap_arg *arg, const char *newval)
-{
-    if (arg && arg->pref_valptr != NULL)
-    {
-        g_free(*arg->pref_valptr);
-        *arg->pref_valptr = g_strdup(newval);
-    }
-
-}
-
 /**
  * Obtains a pointer which can store a value for the given preference name.
  * The preference name that can be passed to the prefs API is stored into
@@ -600,14 +734,13 @@ extcap_pref_for_argument(const gchar *ifname, struct _extcap_arg *arg)
     return pref;
 }
 
-static gboolean search_cb(const gchar *extcap _U_, const gchar *ifname _U_, gchar *output, void *data,
-                          char **err_str _U_)
+static gboolean cb_preference(extcap_callback_info_t cb_info)
 {
     GList *arguments = NULL;
-    GList **il = (GList **) data;
+    GList **il = (GList **) cb_info.data;
     module_t *dev_module = NULL;
 
-    arguments = extcap_parse_args(output);
+    arguments = extcap_parse_args(cb_info.output);
 
     dev_module = prefs_find_module("extcap");
 
@@ -622,14 +755,14 @@ static gboolean search_cb(const gchar *extcap _U_, const gchar *ifname _U_, gcha
             while (walker != NULL)
             {
                 extcap_arg *arg = (extcap_arg *)walker->data;
-                arg->device_name = g_strdup(ifname);
+                arg->device_name = g_strdup(cb_info.ifname);
 
                 if (arg->save)
                 {
                     struct preference *pref = NULL;
 
                     gchar *pref_name = g_regex_replace(regex_name, arg->call, strlen(arg->call), 0, "", (GRegexMatchFlags) 0, NULL);
-                    gchar *ifname_underscore = g_regex_replace(regex_ifname, ifname, strlen(ifname), 0, "_", (GRegexMatchFlags) 0, NULL);
+                    gchar *ifname_underscore = g_regex_replace(regex_ifname, cb_info.ifname, strlen(cb_info.ifname), 0, "_", (GRegexMatchFlags) 0, NULL);
                     gchar *ifname_lowercase = g_ascii_strdown(ifname_underscore, -1);
                     gchar *pref_ifname = g_strconcat(ifname_lowercase, ".", pref_name, NULL);
 
@@ -685,26 +818,90 @@ static gboolean search_cb(const gchar *extcap _U_, const gchar *ifname _U_, gcha
 GList *
 extcap_get_if_configuration(const char *ifname)
 {
-    gchar *argv[3];
+    GList * arguments = NULL;
     GList *ret = NULL;
     gchar **err_str = NULL;
-    int i;
 
     if (extcap_if_exists(ifname))
     {
         g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "Extcap path %s",
               get_extcap_dir());
 
-        argv[0] = g_strdup(EXTCAP_ARGUMENT_CONFIG);
-        argv[1] = g_strdup(EXTCAP_ARGUMENT_INTERFACE);
-        argv[2] = g_strdup(ifname);
+        arguments = g_list_append(arguments, g_strdup(EXTCAP_ARGUMENT_CONFIG));
+        arguments = g_list_append(arguments, g_strdup(EXTCAP_ARGUMENT_INTERFACE));
+        arguments = g_list_append(arguments, g_strdup(ifname));
+
+        extcap_callback_info_t cb_info;
+        cb_info.data = &ret;
+        cb_info.err_str = err_str;
+        cb_info.ifname = ifname;
 
-        extcap_foreach(3, argv, search_cb, &ret, err_str, ifname);
+        extcap_foreach(arguments, cb_preference, cb_info, NULL);
 
-        for (i = 0; i < 3; i++)
+        g_list_free_full(arguments, g_free);
+    }
+
+    return ret;
+}
+
+static gboolean cb_reload_preference(extcap_callback_info_t cb_info)
+{
+    GList *arguments = NULL, * walker = NULL;
+    GList **il = (GList **) cb_info.data;
+
+    arguments = extcap_parse_values(cb_info.output);
+
+    walker = g_list_first((GList *)(arguments));
+    while (walker != NULL)
+    {
+        extcap_value * val = (extcap_value *)walker->data;
+        *il = g_list_append(*il, val);
+        walker = g_list_next(walker);
+    }
+    g_list_free(arguments);
+
+    /* By returning false, extcap_foreach will break on first found */
+    return FALSE;
+}
+
+GList *
+extcap_get_if_configuration_values(const char * ifname, const char * argname, GHashTable *arguments)
+{
+    GList * args = NULL;
+    GList *ret = NULL;
+    gchar **err_str = NULL;
+
+    if (extcap_if_exists(ifname))
+    {
+        g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "Extcap path %s",
+              get_extcap_dir());
+
+        args = g_list_append(args, g_strdup(EXTCAP_ARGUMENT_CONFIG));
+        args = g_list_append(args, g_strdup(EXTCAP_ARGUMENT_INTERFACE));
+        args = g_list_append(args, g_strdup(ifname));
+        args = g_list_append(args, g_strdup(EXTCAP_ARGUMENT_RELOAD_OPTION));
+        args = g_list_append(args, g_strdup(argname));
+
+        if ( arguments )
         {
-            g_free(argv[i]);
+            GList * keys = g_hash_table_get_keys(arguments);
+            while ( keys )
+            {
+                const gchar * key_data = (const gchar *)keys->data;
+                args = g_list_append(args, g_strdup(key_data));
+                args = g_list_append(args, g_strdup((const gchar *)g_hash_table_lookup(arguments, key_data)));
+                keys = g_list_next(keys);
+            }
         }
+
+        extcap_callback_info_t cb_info;
+        cb_info.data = &ret;
+        cb_info.err_str = err_str;
+        cb_info.ifname = ifname;
+
+        extcap_foreach(args, cb_reload_preference, cb_info, NULL);
+
+        g_list_free_full(args, g_free);
     }
 
     return ret;
@@ -789,50 +986,81 @@ extcap_has_configuration(const char *ifname, gboolean is_required)
     return found;
 }
 
-/* taken from capchild/capture_sync.c */
-static gboolean pipe_data_available(int pipe_fd)
+static gboolean cb_verify_filter(extcap_callback_info_t cb_info)
 {
-#ifdef _WIN32 /* PeekNamedPipe */
-    HANDLE hPipe = (HANDLE) _get_osfhandle(pipe_fd);
-    DWORD bytes_avail;
-
-    if (hPipe == INVALID_HANDLE_VALUE)
-    {
-        return FALSE;
+    extcap_filter_status *status = (extcap_filter_status *)cb_info.data;
+    size_t output_size, i;
+
+    output_size = strlen(cb_info.output);
+    if (output_size == 0) {
+        *status = EXTCAP_FILTER_VALID;
+    } else {
+        *status = EXTCAP_FILTER_INVALID;
+        for (i = 0; i < output_size; i++) {
+            if (cb_info.output[i] == '\n' || cb_info.output[i] == '\r') {
+                cb_info.output[i] = '\0';
+                break;
+            }
+        }
+        *cb_info.err_str = g_strdup(cb_info.output);
     }
 
-    if (! PeekNamedPipe(hPipe, NULL, 0, NULL, &bytes_avail, NULL))
+    return TRUE;
+}
+
+extcap_filter_status
+extcap_verify_capture_filter(const char *ifname, const char *filter, gchar **err_str)
+{
+    GList * arguments = NULL;
+    extcap_filter_status status = EXTCAP_FILTER_UNKNOWN;
+
+    if (extcap_if_exists(ifname))
     {
-        return FALSE;
+        g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "Extcap path %s",
+              get_extcap_dir());
+
+        arguments = g_list_append(arguments, g_strdup(EXTCAP_ARGUMENT_CAPTURE_FILTER));
+        arguments = g_list_append(arguments, g_strdup(filter));
+        arguments = g_list_append(arguments, g_strdup(EXTCAP_ARGUMENT_INTERFACE));
+        arguments = g_list_append(arguments, g_strdup(ifname));
+
+        extcap_callback_info_t cb_info;
+        cb_info.data = &status;
+        cb_info.err_str = err_str;
+        cb_info.ifname = ifname;
+
+        extcap_foreach(arguments, cb_verify_filter, cb_info, NULL);
+        g_list_free_full(arguments, g_free);
     }
 
-    if (bytes_avail > 0)
+    return status;
+}
+
+gboolean
+extcap_has_toolbar(const char *ifname)
+{
+    if (!iface_toolbar_use())
     {
-        return TRUE;
+        return FALSE;
     }
-    return FALSE;
-#else /* select */
-    fd_set rfds;
-    struct timeval timeout;
 
-    FD_ZERO(&rfds);
-    FD_SET(pipe_fd, &rfds);
-    timeout.tv_sec = 0;
-    timeout.tv_usec = 0;
-
-    if (select(pipe_fd + 1, &rfds, NULL, NULL, &timeout) > 0)
+    GList *toolbar_list = g_hash_table_get_values (_toolbars);
+    for (GList *walker = toolbar_list; walker; walker = walker->next)
     {
-        return TRUE;
+        iface_toolbar *toolbar = (iface_toolbar *) walker->data;
+        if (g_list_find_custom(toolbar->ifnames, ifname, (GCompareFunc) strcmp))
+        {
+            return TRUE;
+        }
     }
 
     return FALSE;
-#endif
 }
 
 void extcap_if_cleanup(capture_options *capture_opts, gchar **errormsg)
 {
-    interface_options interface_opts;
-    extcap_userdata *userdata;
+    interface_options *interface_opts;
+    ws_pipe_t *pipedata;
     guint icnt = 0;
     gboolean overwrite_exitcode;
     gchar *buffer;
@@ -840,11 +1068,11 @@ void extcap_if_cleanup(capture_options *capture_opts, gchar **errormsg)
 
     for (icnt = 0; icnt < capture_opts->ifaces->len; icnt++)
     {
-        interface_opts = g_array_index(capture_opts->ifaces, interface_options,
+        interface_opts = &g_array_index(capture_opts->ifaces, interface_options,
                                        icnt);
 
         /* skip native interfaces */
-        if (interface_opts.if_type != IF_EXTCAP)
+        if (interface_opts->if_type != IF_EXTCAP)
         {
             continue;
         }
@@ -852,112 +1080,130 @@ void extcap_if_cleanup(capture_options *capture_opts, gchar **errormsg)
         overwrite_exitcode = FALSE;
 
         g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
-              "Extcap [%s] - Cleaning up fifo: %s; PID: %d", interface_opts.name,
-              interface_opts.extcap_fifo, interface_opts.extcap_pid);
+              "Extcap [%s] - Cleaning up fifo: %s; PID: %d", interface_opts->name,
+              interface_opts->extcap_fifo, interface_opts->extcap_pid);
 #ifdef _WIN32
-        if (pipe_h)
+        if (interface_opts->extcap_pipe_h != INVALID_HANDLE_VALUE)
         {
             g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
-                  "Extcap [%s] - Closing pipe", interface_opts.name);
-            FlushFileBuffers(pipe_h);
-            DisconnectNamedPipe(pipe_h);
-            CloseHandle(pipe_h);
+                  "Extcap [%s] - Closing pipe", interface_opts->name);
+            FlushFileBuffers(interface_opts->extcap_pipe_h);
+            DisconnectNamedPipe(interface_opts->extcap_pipe_h);
+            CloseHandle(interface_opts->extcap_pipe_h);
+            interface_opts->extcap_pipe_h = INVALID_HANDLE_VALUE;
+        }
+        if (interface_opts->extcap_control_in_h != INVALID_HANDLE_VALUE)
+        {
+            g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
+                  "Extcap [%s] - Closing control_in pipe", interface_opts->name);
+            FlushFileBuffers(interface_opts->extcap_control_in_h);
+            DisconnectNamedPipe(interface_opts->extcap_control_in_h);
+            CloseHandle(interface_opts->extcap_control_in_h);
+            interface_opts->extcap_control_in_h = INVALID_HANDLE_VALUE;
+        }
+        if (interface_opts->extcap_control_out_h != INVALID_HANDLE_VALUE)
+        {
+            g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
+                  "Extcap [%s] - Closing control_out pipe", interface_opts->name);
+            FlushFileBuffers(interface_opts->extcap_control_out_h);
+            DisconnectNamedPipe(interface_opts->extcap_control_out_h);
+            CloseHandle(interface_opts->extcap_control_out_h);
+            interface_opts->extcap_control_out_h = INVALID_HANDLE_VALUE;
         }
 #else
-        if (interface_opts.extcap_fifo != NULL && file_exists(interface_opts.extcap_fifo))
+        if (interface_opts->extcap_fifo != NULL && file_exists(interface_opts->extcap_fifo))
         {
             /* the fifo will not be freed here, but with the other capture_opts in capture_sync */
-            ws_unlink(interface_opts.extcap_fifo);
-            interface_opts.extcap_fifo = NULL;
+            ws_unlink(interface_opts->extcap_fifo);
+            interface_opts->extcap_fifo = NULL;
+        }
+        if (interface_opts->extcap_control_in && file_exists(interface_opts->extcap_control_in))
+        {
+            ws_unlink(interface_opts->extcap_control_in);
+            interface_opts->extcap_control_in = NULL;
+        }
+        if (interface_opts->extcap_control_out && file_exists(interface_opts->extcap_control_out))
+        {
+            ws_unlink(interface_opts->extcap_control_out);
+            interface_opts->extcap_control_out = NULL;
         }
 #endif
         /* Maybe the client closed and removed fifo, but ws should check if
          * pid should be closed */
         g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
-              "Extcap [%s] - Closing spawned PID: %d", interface_opts.name,
-              interface_opts.extcap_pid);
+              "Extcap [%s] - Closing spawned PID: %d", interface_opts->name,
+              interface_opts->extcap_pid);
 
-        userdata = (extcap_userdata *) interface_opts.extcap_userdata;
-        if (userdata)
+        pipedata = (ws_pipe_t *) interface_opts->extcap_pipedata;
+        if (pipedata)
         {
-            if (userdata->extcap_stderr_rd > 0 && pipe_data_available(userdata->extcap_stderr_rd))
+            if (pipedata->stderr_fd > 0 && ws_pipe_data_available(pipedata->stderr_fd))
             {
-                buffer = (gchar *)g_malloc0(sizeof(gchar) * STDERR_BUFFER_SIZE + 1);
-#ifdef _WIN32
-                win32_readfrompipe((HANDLE)_get_osfhandle(userdata->extcap_stderr_rd), STDERR_BUFFER_SIZE, buffer);
-#else
-                if (read(userdata->extcap_stderr_rd, buffer, sizeof(gchar) * STDERR_BUFFER_SIZE) <= 0)
-                {
-                    buffer[0] = '\0';
-                }
-#endif
+                buffer = (gchar *)g_malloc0(STDERR_BUFFER_SIZE + 1);
+                ws_read_string_from_pipe(ws_get_pipe_handle(pipedata->stderr_fd), buffer, STDERR_BUFFER_SIZE + 1);
                 if (strlen(buffer) > 0)
                 {
-                    userdata->extcap_stderr = g_strdup_printf("%s", buffer);
-                    userdata->exitcode = 1;
+                    pipedata->stderr_msg = g_strdup_printf("%s", buffer);
+                    pipedata->exitcode = 1;
                 }
                 g_free(buffer);
             }
 
 #ifndef _WIN32
             /* Final child watch may not have been called */
-            if (interface_opts.extcap_child_watch != 0)
+            if (interface_opts->extcap_child_watch != 0)
             {
-                extcap_child_watch_cb(userdata->pid, 0, capture_opts);
+                extcap_child_watch_cb(pipedata->pid, 0, capture_opts);
                 /* it will have changed in extcap_child_watch_cb */
-                interface_opts = g_array_index(capture_opts->ifaces, interface_options,
+                interface_opts = &g_array_index(capture_opts->ifaces, interface_options,
                                                icnt);
             }
 #endif
 
-            if (userdata->extcap_stderr != NULL)
+            if (pipedata->stderr_msg != NULL)
             {
                 overwrite_exitcode = TRUE;
             }
 
-            if (overwrite_exitcode || userdata->exitcode != 0)
+            if (overwrite_exitcode || pipedata->exitcode != 0)
             {
-                if (userdata->extcap_stderr != 0)
+                if (pipedata->stderr_msg != 0)
                 {
                     if (*errormsg == NULL)
                     {
-                        *errormsg = g_strdup_printf("Error by extcap pipe: %s", userdata->extcap_stderr);
+                        *errormsg = g_strdup_printf("Error by extcap pipe: %s", pipedata->stderr_msg);
                     }
                     else
                     {
-                        gchar *temp = g_strconcat(*errormsg, "\nError by extcap pipe: " , userdata->extcap_stderr, NULL);
+                        gchar *temp = g_strconcat(*errormsg, "\nError by extcap pipe: " , pipedata->stderr_msg, NULL);
                         g_free(*errormsg);
                         *errormsg = temp;
                     }
-                    g_free(userdata->extcap_stderr);
+                    g_free(pipedata->stderr_msg);
                 }
 
-                userdata->extcap_stderr = NULL;
-                userdata->exitcode = 0;
+                pipedata->stderr_msg = NULL;
+                pipedata->exitcode = 0;
             }
         }
 
-        if (interface_opts.extcap_child_watch > 0)
+        if (interface_opts->extcap_child_watch > 0)
         {
-            g_source_remove(interface_opts.extcap_child_watch);
-            interface_opts.extcap_child_watch = 0;
+            g_source_remove(interface_opts->extcap_child_watch);
+            interface_opts->extcap_child_watch = 0;
         }
 
-        if (interface_opts.extcap_pid != INVALID_EXTCAP_PID)
+        if (interface_opts->extcap_pid != WS_INVALID_PID)
         {
 #ifdef _WIN32
-            TerminateProcess(interface_opts.extcap_pid, 0);
+            TerminateProcess(interface_opts->extcap_pid, 0);
 #endif
-            g_spawn_close_pid(interface_opts.extcap_pid);
-            interface_opts.extcap_pid = INVALID_EXTCAP_PID;
+            g_spawn_close_pid(interface_opts->extcap_pid);
+            interface_opts->extcap_pid = WS_INVALID_PID;
 
-            g_free(interface_opts.extcap_userdata);
-            interface_opts.extcap_userdata = NULL;
+            g_free(interface_opts->extcap_pipedata);
+            interface_opts->extcap_pipedata = NULL;
         }
-
-        /* Make sure modified interface_opts is saved in capture_opts. */
-        capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, icnt);
-        g_array_insert_val(capture_opts->ifaces, icnt, interface_opts);
     }
 }
 
@@ -984,8 +1230,8 @@ extcap_add_arg_and_remove_cb(gpointer key, gpointer value, gpointer data)
 void extcap_child_watch_cb(GPid pid, gint status, gpointer user_data)
 {
     guint i;
-    interface_options interface_opts;
-    extcap_userdata *userdata = NULL;
+    interface_options *interface_opts;
+    ws_pipe_t *pipedata = NULL;
     capture_options *capture_opts = (capture_options *)(user_data);
 
     if (capture_opts == NULL || capture_opts->ifaces == NULL || capture_opts->ifaces->len == 0)
@@ -999,70 +1245,77 @@ void extcap_child_watch_cb(GPid pid, gint status, gpointer user_data)
     /* Update extcap_pid in interface options structure. */
     for (i = 0; i < capture_opts->ifaces->len; i++)
     {
-        interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
-        if (interface_opts.extcap_pid == pid)
+        interface_opts = &g_array_index(capture_opts->ifaces, interface_options, i);
+        if (interface_opts->extcap_pid == pid)
         {
-            userdata = (extcap_userdata *)interface_opts.extcap_userdata;
-            if (userdata != NULL)
+            pipedata = (ws_pipe_t *)interface_opts->extcap_pipedata;
+            if (pipedata != NULL)
             {
-                interface_opts.extcap_pid = INVALID_EXTCAP_PID;
-                userdata->exitcode = 0;
+                interface_opts->extcap_pid = WS_INVALID_PID;
+                pipedata->exitcode = 0;
 #ifndef _WIN32
                 if (WIFEXITED(status))
                 {
                     if (WEXITSTATUS(status) != 0)
                     {
-                        userdata->exitcode = WEXITSTATUS(status);
+                        pipedata->exitcode = WEXITSTATUS(status);
                     }
                 }
                 else
                 {
-                    userdata->exitcode = G_SPAWN_ERROR_FAILED;
+                    pipedata->exitcode = G_SPAWN_ERROR_FAILED;
                 }
 #else
                 if (status != 0)
                 {
-                    userdata->exitcode = status;
+                    pipedata->exitcode = status;
                 }
 #endif
-                if (status == 0 && userdata->extcap_stderr != NULL)
+                if (status == 0 && pipedata->stderr_msg != NULL)
                 {
-                    userdata->exitcode = 1;
+                    pipedata->exitcode = 1;
                 }
             }
-            g_source_remove(interface_opts.extcap_child_watch);
-            interface_opts.extcap_child_watch = 0;
-
-            capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, i);
-            g_array_insert_val(capture_opts->ifaces, i, interface_opts);
+            g_source_remove(interface_opts->extcap_child_watch);
+            interface_opts->extcap_child_watch = 0;
             break;
         }
     }
 }
 
 static
-GPtrArray *extcap_prepare_arguments(interface_options interface_opts)
+GPtrArray *extcap_prepare_arguments(interface_options *interface_opts)
 {
     GPtrArray *result = NULL;
 
-    if (interface_opts.if_type == IF_EXTCAP)
+    if (interface_opts->if_type == IF_EXTCAP)
     {
         result = g_ptr_array_new();
 
 #define add_arg(X) g_ptr_array_add(result, g_strdup(X))
 
-        add_arg(interface_opts.extcap);
+        add_arg(interface_opts->extcap);
         add_arg(EXTCAP_ARGUMENT_RUN_CAPTURE);
         add_arg(EXTCAP_ARGUMENT_INTERFACE);
-        add_arg(interface_opts.name);
-        if (interface_opts.cfilter && strlen(interface_opts.cfilter) > 0)
+        add_arg(interface_opts->name);
+        if (interface_opts->cfilter && strlen(interface_opts->cfilter) > 0)
         {
             add_arg(EXTCAP_ARGUMENT_CAPTURE_FILTER);
-            add_arg(interface_opts.cfilter);
+            add_arg(interface_opts->cfilter);
         }
         add_arg(EXTCAP_ARGUMENT_RUN_PIPE);
-        add_arg(interface_opts.extcap_fifo);
-        if (interface_opts.extcap_args == NULL || g_hash_table_size(interface_opts.extcap_args) == 0)
+        add_arg(interface_opts->extcap_fifo);
+        if (interface_opts->extcap_control_in)
+        {
+            add_arg(EXTCAP_ARGUMENT_CONTROL_OUT);
+            add_arg(interface_opts->extcap_control_in);
+        }
+        if (interface_opts->extcap_control_out)
+        {
+            add_arg(EXTCAP_ARGUMENT_CONTROL_IN);
+            add_arg(interface_opts->extcap_control_out);
+        }
+        if (interface_opts->extcap_args == NULL || g_hash_table_size(interface_opts->extcap_args) == 0)
         {
             /* User did not perform interface configuration.
              *
@@ -1072,7 +1325,7 @@ GPtrArray *extcap_prepare_arguments(interface_options interface_opts)
             GList *arglist;
             GList *elem;
 
-            arglist = extcap_get_if_configuration(interface_opts.name);
+            arglist = extcap_get_if_configuration(interface_opts->name);
             for (elem = g_list_first(arglist); elem; elem = elem->next)
             {
                 GList *arg_list;
@@ -1086,7 +1339,7 @@ GPtrArray *extcap_prepare_arguments(interface_options interface_opts)
                 arg_list = g_list_first((GList *)elem->data);
                 while (arg_list != NULL)
                 {
-                    const gchar *stored = NULL, * defval = NULL;
+                    const gchar *stored = NULL;
                     /* In case of boolflags only first element in arg_list is relevant. */
                     arg_iter = (extcap_arg *)(arg_list->data);
                     if (arg_iter->pref_valptr != NULL)
@@ -1094,32 +1347,22 @@ GPtrArray *extcap_prepare_arguments(interface_options interface_opts)
                         stored = *arg_iter->pref_valptr;
                     }
 
-                    if (arg_iter->default_complex != NULL && arg_iter->default_complex->_val != NULL)
+                    if (arg_iter->arg_type == EXTCAP_ARG_BOOLFLAG)
                     {
-                        defval = arg_iter->default_complex->_val;
-                    }
-
-                    /* Different data in storage then set for default */
-                    if (g_strcmp0(stored, defval) != 0)
-                    {
-                        if (arg_iter->arg_type == EXTCAP_ARG_BOOLFLAG)
+                        if (extcap_complex_get_bool(arg_iter->default_complex))
                         {
-                            if (g_strcmp0(stored, "true") == 0)
-                            {
-                                add_arg(arg_iter->call);
-                            }
+                            add_arg(arg_iter->call);
                         }
-                        else
+                        else if (g_strcmp0(stored, "true") == 0)
                         {
                             add_arg(arg_iter->call);
-                            add_arg(stored);
                         }
                     }
-                    else if (arg_iter->arg_type == EXTCAP_ARG_BOOLFLAG)
+                    else
                     {
-                        if (extcap_complex_get_bool(arg_iter->default_complex))
-                        {
+                        if (stored && strlen(stored) > 0) {
                             add_arg(arg_iter->call);
+                            add_arg(stored);
                         }
                     }
 
@@ -1131,7 +1374,7 @@ GPtrArray *extcap_prepare_arguments(interface_options interface_opts)
         }
         else
         {
-            g_hash_table_foreach_remove(interface_opts.extcap_args, extcap_add_arg_and_remove_cb, result);
+            g_hash_table_foreach_remove(interface_opts->extcap_args, extcap_add_arg_and_remove_cb, result);
         }
         add_arg(NULL);
 #undef add_arg
@@ -1147,47 +1390,67 @@ gboolean
 extcap_init_interfaces(capture_options *capture_opts)
 {
     guint i;
-    interface_options interface_opts;
-    extcap_userdata *userdata;
+    interface_options *interface_opts;
+    ws_pipe_t *pipedata;
 
     for (i = 0; i < capture_opts->ifaces->len; i++)
     {
         GPtrArray *args = NULL;
-        GPid pid = INVALID_EXTCAP_PID;
+        GPid pid = WS_INVALID_PID;
 
-        interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
+        interface_opts = &g_array_index(capture_opts->ifaces, interface_options, i);
 
         /* skip native interfaces */
-        if (interface_opts.if_type != IF_EXTCAP)
+        if (interface_opts->if_type != IF_EXTCAP)
         {
             continue;
         }
 
+        /* create control pipes if having toolbar */
+        if (extcap_has_toolbar(interface_opts->name))
+        {
+            extcap_create_pipe(interface_opts->name, &interface_opts->extcap_control_in,
+                               EXTCAP_CONTROL_IN_PREFIX);
+#ifdef _WIN32
+            interface_opts->extcap_control_in_h = pipe_h;
+#endif
+            extcap_create_pipe(interface_opts->name, &interface_opts->extcap_control_out,
+                               EXTCAP_CONTROL_OUT_PREFIX);
+#ifdef _WIN32
+            interface_opts->extcap_control_out_h = pipe_h;
+#endif
+        }
+
         /* create pipe for fifo */
-        if (!extcap_create_pipe(&interface_opts.extcap_fifo))
+        if (!extcap_create_pipe(interface_opts->name, &interface_opts->extcap_fifo,
+                                EXTCAP_PIPE_PREFIX))
         {
             return FALSE;
         }
+#ifdef _WIN32
+        interface_opts->extcap_pipe_h = pipe_h;
+#endif
 
         /* Create extcap call */
         args = extcap_prepare_arguments(interface_opts);
 
-        userdata = g_new0(extcap_userdata, 1);
+        pipedata = g_new0(ws_pipe_t, 1);
 
-        pid = extcap_spawn_async(userdata, args);
+        pid = ws_pipe_spawn_async(pipedata, args);
 
         g_ptr_array_foreach(args, (GFunc)g_free, NULL);
         g_ptr_array_free(args, TRUE);
 
-        if (pid == INVALID_EXTCAP_PID)
+        if (pid == WS_INVALID_PID)
         {
-            g_free(userdata);
+            g_free(pipedata);
             continue;
         }
 
-        interface_opts.extcap_pid = pid;
+        ws_close(pipedata->stdin_fd);
+        interface_opts->extcap_pid = pid;
 
-        interface_opts.extcap_child_watch =
+        interface_opts->extcap_child_watch =
             g_child_watch_add(pid, extcap_child_watch_cb, (gpointer)capture_opts);
 
 #ifdef _WIN32
@@ -1197,43 +1460,38 @@ extcap_init_interfaces(capture_options *capture_opts)
          * connect to named pipe (including user interaction).
          * Wait on multiple object in case of extcap termination
          * without opening pipe.
-         *
-         * Minimum supported version of Windows: XP / Server 2003.
          */
-        if (pid != INVALID_EXTCAP_PID)
+        if (pid != WS_INVALID_PID)
         {
-            extcap_wait_for_pipe(pipe_h, pid);
-        }
+            HANDLE pipe_handles[3];
+            int num_pipe_handles = 1;
+            pipe_handles[0] = interface_opts->extcap_pipe_h;
 
-#endif
+            if (extcap_has_toolbar(interface_opts->name))
+            {
+                pipe_handles[1] = interface_opts->extcap_control_in_h;
+                pipe_handles[2] = interface_opts->extcap_control_out_h;
+                num_pipe_handles += 2;
+             }
 
-        interface_opts.extcap_userdata = (gpointer) userdata;
+            ws_pipe_wait_for_pipe(pipe_handles, num_pipe_handles, pid);
+        }
+#endif
 
-        capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, i);
-        g_array_insert_val(capture_opts->ifaces, i, interface_opts);
+        interface_opts->extcap_pipedata = (gpointer) pipedata;
     }
 
     return TRUE;
 }
 
 #ifdef _WIN32
-/* called by capture_sync to get the CreatNamedPipe handle*/
-HANDLE
-extcap_get_win32_handle()
+gboolean extcap_create_pipe(const gchar *ifname, gchar **fifo, const gchar *pipe_prefix)
 {
-    return pipe_h;
-}
-#endif
-
-gboolean extcap_create_pipe(char **fifo)
-{
-#ifdef _WIN32
     gchar timestr[ 14 + 1 ];
     time_t current_time;
-
     gchar *pipename = NULL;
-
     SECURITY_ATTRIBUTES security;
+
     /* create pipename */
     current_time = time(NULL);
     /*
@@ -1241,7 +1499,7 @@ gboolean extcap_create_pipe(char **fifo)
      * so we won't get a null pointer back from localtime().
      */
     strftime(timestr, sizeof(timestr), "%Y%m%d%H%M%S", localtime(&current_time));
-    pipename = g_strconcat("\\\\.\\pipe\\", EXTCAP_PIPE_PREFIX, "_", timestr, NULL);
+    pipename = g_strconcat("\\\\.\\pipe\\", pipe_prefix, "_", ifname, "_", timestr, NULL);
 
     /* Security struct to enable Inheritable HANDLE */
     memset(&security, 0, sizeof(SECURITY_ATTRIBUTES));
@@ -1249,18 +1507,19 @@ gboolean extcap_create_pipe(char **fifo)
     security.bInheritHandle = TRUE;
     security.lpSecurityDescriptor = NULL;
 
-    /* create a namedPipe*/
+    /* create a namedPipe */
     pipe_h = CreateNamedPipe(
                  utf_8to16(pipename),
                  PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
-                 PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
-                 5, 65536, 65536,
+                 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT,
+                 1, 65536, 65536,
                  300,
                  &security);
 
     if (pipe_h == INVALID_HANDLE_VALUE)
     {
         g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "\nError creating pipe => (%d)", GetLastError());
+        g_free (pipename);
         return FALSE;
     }
     else
@@ -1268,14 +1527,22 @@ gboolean extcap_create_pipe(char **fifo)
         g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "\nWireshark Created pipe =>(%s)", pipename);
         *fifo = g_strdup(pipename);
     }
+
+    return TRUE;
+}
 #else
+gboolean extcap_create_pipe(const gchar *ifname, gchar **fifo, const gchar *pipe_prefix)
+{
     gchar *temp_name = NULL;
     int fd = 0;
 
-    if ((fd = create_tempfile(&temp_name, EXTCAP_PIPE_PREFIX, NULL)) < 0)
+    gchar *pfx = g_strconcat(pipe_prefix, "_", ifname, NULL);
+    if ((fd = create_tempfile(&temp_name, pfx, NULL)) < 0)
     {
+        g_free(pfx);
         return FALSE;
     }
+    g_free(pfx);
 
     ws_close(fd);
 
@@ -1291,10 +1558,10 @@ gboolean extcap_create_pipe(char **fifo)
     {
         *fifo = g_strdup(temp_name);
     }
-#endif
 
     return TRUE;
 }
+#endif
 
 /************* EXTCAP LOAD INTERFACE LIST ***************
  *
@@ -1304,13 +1571,14 @@ gboolean extcap_create_pipe(char **fifo)
 
 
 static void
-extcap_free_interface_info(gpointer data _U_)
+extcap_free_interface_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->help);
 
     extcap_free_interfaces(info->interfaces);
 
@@ -1318,17 +1586,21 @@ extcap_free_interface_info(gpointer data _U_)
 }
 
 static extcap_info *
-extcap_ensure_interface(const gchar * toolname)
+extcap_ensure_interface(const gchar * toolname, gboolean create_if_nonexist)
 {
     extcap_info * element = 0;
 
+    if ( prefs.capture_no_extcap )
+        return NULL;
+
     if ( ! toolname )
         return element;
 
     if ( ! _loaded_interfaces )
         _loaded_interfaces = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, extcap_free_interface);
 
-    if ( ( element = (extcap_info *) g_hash_table_lookup(_loaded_interfaces, toolname ) ) == NULL )
+    element = (extcap_info *) g_hash_table_lookup(_loaded_interfaces, toolname );
+    if ( ! element && create_if_nonexist )
     {
         g_hash_table_insert(_loaded_interfaces, g_strdup(toolname), g_new0(extcap_info, 1));
         element = (extcap_info *) g_hash_table_lookup(_loaded_interfaces, toolname );
@@ -1337,26 +1609,77 @@ extcap_ensure_interface(const gchar * toolname)
     return element;
 }
 
+extcap_info *
+extcap_get_tool_by_ifname(const gchar *ifname)
+{
+    if ( ifname && _tool_for_ifname )
+    {
+        gchar * toolname = (gchar *)g_hash_table_lookup(_tool_for_ifname, ifname);
+        if ( toolname )
+            return extcap_ensure_interface(toolname, FALSE);
+    }
+
+    return NULL;
+}
+
+extcap_info *
+extcap_get_tool_info(const gchar * toolname)
+{
+    return extcap_ensure_interface(toolname, FALSE);
+}
+
 static void remove_extcap_entry(gpointer entry, gpointer data _U_)
 {
     extcap_interface *int_iter = (extcap_interface*)entry;
 
     if (int_iter->if_type == EXTCAP_SENTENCE_EXTCAP)
-        g_free(int_iter);
+        extcap_free_interface(entry);
 }
 
-static gboolean cb_load_interfaces(const gchar *extcap, const gchar *ifname _U_, gchar *output _U_, void *data _U_,
-                              char **err_str _U_)
+static gboolean cb_load_interfaces(extcap_callback_info_t cb_info)
 {
-    GList *interfaces = NULL, *walker = NULL;
-    extcap_interface *int_iter = NULL;
-    gchar *toolname = g_path_get_basename(extcap);
+    GList * interfaces = NULL, * control_items = NULL, * walker = NULL;
+    extcap_interface * int_iter = NULL;
+    extcap_info * element = NULL;
+    iface_toolbar * toolbar_entry = NULL;
+    gchar * toolname = g_path_get_basename(cb_info.extcap);
 
     GList * interface_keys = g_hash_table_get_keys(_loaded_interfaces);
 
-    interfaces = extcap_parse_interfaces(output);
+    /* Load interfaces from utility */
+    interfaces = extcap_parse_interfaces(cb_info.output, &control_items);
+
+    if (control_items)
+    {
+        toolbar_entry = g_new0(iface_toolbar, 1);
+        toolbar_entry->controls = control_items;
+    }
+
+    g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "Loading interface list for %s ", cb_info.extcap);
+
+    /* Seems, that there where no interfaces to be loaded */
+    if ( ! interfaces || g_list_length(interfaces) == 0 )
+    {
+        g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "Cannot load interfaces for %s", cb_info.extcap );
+        /* Some utilities, androiddump for example, may actually don't present any interfaces, even
+         * if the utility itself is present. In such a case, we return here, but do not return
+         * FALSE, or otherwise further loading of other utilities will be stopped */
+        g_list_free(interface_keys);
+        g_free(toolname);
+        return TRUE;
+    }
 
-    g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "Loading interface list for %s ", extcap);
+    /* Load or create the storage element for the tool */
+    element = extcap_ensure_interface(toolname, TRUE);
+    if ( element == NULL )
+    {
+        g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_ERROR, "Cannot store interface %s, maybe duplicate?", cb_info.extcap );
+        g_list_foreach(interfaces, remove_extcap_entry, NULL);
+        g_list_free(interfaces);
+        g_list_free(interface_keys);
+        g_free(toolname);
+        return FALSE;
+    }
 
     walker = interfaces;
     gchar* help = NULL;
@@ -1364,32 +1687,32 @@ static gboolean cb_load_interfaces(const gchar *extcap, const gchar *ifname _U_,
     {
         int_iter = (extcap_interface *)walker->data;
 
-        extcap_info * element = extcap_ensure_interface(toolname);
-
-        if ( element == NULL )
-        {
-            g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_ERROR, "Cannot store interface %s", extcap);
-            walker = g_list_next(walker);
-            continue;
-        }
-
-        g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "Interface found %s\n", int_iter->call);
+        if (int_iter->call != NULL)
+            g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "Interface found %s\n", int_iter->call);
 
         /* Help is not necessarily stored with the interface, but rather with the version string.
          * As the version string allways comes in front of the interfaces, this ensures, that it get's
          * properly stored with the interface */
         if (int_iter->if_type == EXTCAP_SENTENCE_EXTCAP)
         {
-            g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "  Extcap [%s] ", int_iter->call);
+            if (int_iter->call != NULL)
+                g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "  Extcap [%s] ", int_iter->call);
+
             /* Only initialize values if none are set. Need to check only one element here */
             if ( ! element->version )
             {
                 element->version = g_strdup(int_iter->version);
                 element->basename = g_strdup(toolname);
-                element->full_path = g_strdup(extcap);
+                element->full_path = g_strdup(cb_info.extcap);
+                element->help = g_strdup(int_iter->help);
             }
 
             help = int_iter->help;
+            if (toolbar_entry)
+            {
+                toolbar_entry->menu_title = g_strdup(int_iter->display);
+                toolbar_entry->help = g_strdup(int_iter->help);
+            }
 
             walker = g_list_next(walker);
             continue;
@@ -1408,10 +1731,10 @@ static gboolean cb_load_interfaces(const gchar *extcap, const gchar *ifname _U_,
                 continue;
             }
 
-            g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "  Interface [%s] \"%s\" ",
-                  int_iter->call, int_iter->display);
+            if ((int_iter->call != NULL) && (int_iter->display))
+                g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "  Interface [%s] \"%s\" ", int_iter->call, int_iter->display);
 
-            int_iter->extcap_path = g_strdup(extcap);
+            int_iter->extcap_path = g_strdup(cb_info.extcap);
 
             /* Only set the help, if it exists and no parsed help information is present */
             if ( ! int_iter->help && help )
@@ -1419,11 +1742,26 @@ static gboolean cb_load_interfaces(const gchar *extcap, const gchar *ifname _U_,
 
             element->interfaces = g_list_append(element->interfaces, int_iter);
             g_hash_table_insert(_tool_for_ifname, g_strdup(int_iter->call), g_strdup(toolname));
+
+            if (toolbar_entry)
+            {
+                if (!toolbar_entry->menu_title)
+                {
+                    toolbar_entry->menu_title = g_strdup(int_iter->display);
+                }
+                toolbar_entry->ifnames = g_list_append(toolbar_entry->ifnames, g_strdup(int_iter->call));
+            }
         }
 
         walker = g_list_next(walker);
     }
 
+    if (toolbar_entry && toolbar_entry->menu_title)
+    {
+        iface_toolbar_add(toolbar_entry);
+        extcap_iface_toolbar_add(cb_info.extcap, toolbar_entry);
+    }
+
     g_list_foreach(interfaces, remove_extcap_entry, NULL);
     g_list_free(interfaces);
     g_list_free(interface_keys);
@@ -1439,25 +1777,58 @@ static gboolean cb_load_interfaces(const gchar *extcap, const gchar *ifname _U_,
 static void
 extcap_load_interface_list(void)
 {
-    gchar *argv;
-    gchar *error;
+    gchar *error = NULL;
+
+    if (prefs.capture_no_extcap)
+        return;
+
+    if (_toolbars)
+    {
+        // Remove existing interface toolbars here instead of in extcap_clear_interfaces()
+        // to avoid flicker in shown toolbars when refreshing interfaces.
+        GList *toolbar_list = g_hash_table_get_values (_toolbars);
+        for (GList *walker = toolbar_list; walker; walker = walker->next)
+        {
+            iface_toolbar *toolbar = (iface_toolbar *) walker->data;
+            iface_toolbar_remove(toolbar->menu_title);
+        }
+        g_hash_table_remove_all(_toolbars);
+    } else {
+        _toolbars = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, extcap_free_toolbar);
+    }
 
     if (_loaded_interfaces == NULL)
     {
+        GList * arguments = NULL;
+        GList * fallback = NULL;
+        int major = 0;
+        int minor = 0;
+
         _loaded_interfaces = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, extcap_free_interface_info);
         /* Cleanup lookup table */
         if ( _tool_for_ifname )
         {
             g_hash_table_remove_all(_tool_for_ifname);
             _tool_for_ifname = 0;
+        } else {
+            _tool_for_ifname = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
         }
-        _tool_for_ifname = g_hash_table_new(g_str_hash, g_str_equal);
 
-        argv = g_strdup(EXTCAP_ARGUMENT_LIST_INTERFACES);
+        arguments = g_list_append(arguments, g_strdup(EXTCAP_ARGUMENT_LIST_INTERFACES));
+        fallback = g_list_append(fallback, g_strdup(EXTCAP_ARGUMENT_LIST_INTERFACES));
+
+        get_ws_version_number(&major, &minor, NULL);
+        arguments = g_list_append(arguments, g_strdup_printf("%s=%d.%d", EXTCAP_ARGUMENT_VERSION, major, minor));
+
+        extcap_callback_info_t cb_info;
+        cb_info.data = NULL;
+        cb_info.ifname = NULL;
+        cb_info.err_str = &error;
 
-        extcap_foreach(1, &argv, cb_load_interfaces, NULL, &error, NULL);
+        extcap_foreach(arguments, cb_load_interfaces, cb_info, fallback);
 
-        g_free(argv);
+        g_list_free_full(fallback, g_free);
+        g_list_free_full(arguments, g_free);
     }
 }