summaryrefslogtreecommitdiff
path: root/ui/gtk/gtk_iface_monitor.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2012-06-28 16:21:51 +0000
committerGuy Harris <guy@alum.mit.edu>2012-06-28 16:21:51 +0000
commit1d1391ed47b9b81770f19c13081de78569050eb9 (patch)
tree167bef0c2bf598b8ed97e67b1a1663ec5aca4c94 /ui/gtk/gtk_iface_monitor.c
parent28f866815a08e4be3f3131f1e0ba365520af1417 (diff)
downloadwireshark-1d1391ed47b9b81770f19c13081de78569050eb9.tar.gz
From Pontus Fuchs:
Add an interface monitor that, on Linux distributions with libnl, watches for interfaces to appear or disappear and, on such an event, causes windows showing interface lists to update. svn path=/trunk/; revision=43521
Diffstat (limited to 'ui/gtk/gtk_iface_monitor.c')
-rw-r--r--ui/gtk/gtk_iface_monitor.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/ui/gtk/gtk_iface_monitor.c b/ui/gtk/gtk_iface_monitor.c
new file mode 100644
index 0000000000..553c707b66
--- /dev/null
+++ b/ui/gtk/gtk_iface_monitor.c
@@ -0,0 +1,93 @@
+/* gtk_iface_monitor.c
+ * interface monitor by Pontus Fuchs <pontus.fuchs@gmail.com>
+ *
+ * $Id$
+ *
+ * Wireshark - Network traffic analyzer
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include "../../iface_monitor.h"
+
+#include <gtk/gtk.h>
+
+#include "gtkglobals.h"
+
+#include "main.h"
+#include "main_toolbar.h"
+
+#include "ui/gtk/capture_globals.h"
+#include "ui/gtk/main_welcome.h"
+#include "ui/gtk/capture_if_dlg.h"
+#include "ui/gtk/capture_dlg.h"
+
+GIOChannel *iface_mon_channel;
+
+static void
+gtk_iface_mon_event_cb(const char *iface, int up)
+{
+ int present = 0;
+ guint ifs;
+ interface_t device;
+
+ for (ifs = 0; ifs < global_capture_opts.all_ifaces->len; ifs++) {
+ device = g_array_index(global_capture_opts.all_ifaces, interface_t, ifs);
+ if (!strcmp(device.name, iface))
+ present = 1;
+ }
+
+ if (present == up)
+ return;
+
+ refresh_local_interface_lists();
+}
+
+static gboolean
+gtk_iface_mon_event(GIOChannel *source _U_, GIOCondition condition _U_, gpointer data _U_)
+{
+ iface_mon_event();
+ return TRUE;
+}
+
+int
+gtk_iface_mon_start(void)
+{
+ int sock, err;
+ err = iface_mon_start(&gtk_iface_mon_event_cb);
+ if (err)
+ return err;
+ sock = iface_mon_get_sock();
+
+ iface_mon_channel = g_io_channel_unix_new(sock);
+ g_io_channel_set_encoding(iface_mon_channel, NULL, NULL);
+ g_io_add_watch(iface_mon_channel,
+ G_IO_IN|G_IO_ERR|G_IO_HUP,
+ &gtk_iface_mon_event,
+ NULL);
+ return 0;
+}
+
+int
+gtk_iface_mon_stop(void)
+{
+ iface_mon_stop();
+ return 0;
+}
+