summaryrefslogtreecommitdiff
path: root/ui/gtk/gtk_iface_monitor.c
blob: bb64d7676a34f515883c2c678063cbdcfd99925b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#ifdef HAVE_LIBPCAP

#include <string.h>

#include <glib.h>

#include "../../iface_monitor.h"

#include "capture_opts.h"

#include "ui/gtk/iface_lists.h"
#include "ui/gtk/capture_globals.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;
}

#endif /* HAVE_LIBPCAP */