Add an interface list icon. Some of the new capture icons were 1 pixel
[metze/wireshark/wip.git] / ui / gtk / gtk_iface_monitor.c
1 /* gtk_iface_monitor.c
2  * interface monitor by Pontus Fuchs <pontus.fuchs@gmail.com>
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24
25 #include "config.h"
26
27 #ifdef HAVE_LIBPCAP
28
29 #include <string.h>
30
31 #include <glib.h>
32
33 #include "../../iface_monitor.h"
34
35 #include "capture_opts.h"
36
37 #include "ui/capture_globals.h"
38 #include "ui/iface_lists.h"
39
40 #include "ui/gtk/capture_dlg.h"
41
42 GIOChannel *iface_mon_channel;
43
44 static void
45 gtk_iface_mon_event_cb(const char *iface, int up)
46 {
47     int present = 0;
48     guint ifs;
49     interface_t device;
50
51     for (ifs = 0; ifs < global_capture_opts.all_ifaces->len; ifs++) {
52       device = g_array_index(global_capture_opts.all_ifaces, interface_t, ifs);
53       if (!strcmp(device.name, iface))
54           present = 1;
55     }
56
57     if (present == up)
58         return;
59
60     refresh_local_interface_lists();
61 }
62
63 static gboolean
64 gtk_iface_mon_event(GIOChannel *source _U_, GIOCondition condition _U_, gpointer data _U_)
65 {
66     iface_mon_event();
67     return TRUE;
68 }
69
70 int
71 gtk_iface_mon_start(void)
72 {
73     int sock, err;
74     err = iface_mon_start(&gtk_iface_mon_event_cb);
75     if (err)
76         return err;
77     sock = iface_mon_get_sock();
78
79     iface_mon_channel = g_io_channel_unix_new(sock);
80     g_io_channel_set_encoding(iface_mon_channel, NULL, NULL);
81     g_io_add_watch(iface_mon_channel,
82                              (GIOCondition)(G_IO_IN|G_IO_ERR|G_IO_HUP),
83                              &gtk_iface_mon_event,
84                              NULL);
85     return 0;
86 }
87
88 int
89 gtk_iface_mon_stop(void)
90 {
91     iface_mon_stop();
92     return 0;
93 }
94
95 #endif /* HAVE_LIBPCAP */