2012-06-28 18:16:18 +00:00
|
|
|
/* iface_lists.c
|
|
|
|
* Code to manage the global list of interfaces and to update widgets/windows
|
|
|
|
* displaying items from those lists
|
|
|
|
*
|
|
|
|
* 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
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2012-06-28 18:16:18 +00:00
|
|
|
*/
|
|
|
|
|
2012-09-20 01:48:30 +00:00
|
|
|
#include "config.h"
|
2012-06-28 18:16:18 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LIBPCAP
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include <epan/prefs.h>
|
|
|
|
#include <epan/to_str.h>
|
|
|
|
|
2014-06-30 01:36:22 +00:00
|
|
|
#include "ui/capture_ui_utils.h"
|
2012-08-04 00:01:59 +00:00
|
|
|
#include "ui/capture_globals.h"
|
2012-08-01 22:32:14 +00:00
|
|
|
#include "ui/iface_lists.h"
|
2013-06-04 04:36:19 +00:00
|
|
|
#include "../log.h"
|
2012-06-28 18:16:18 +00:00
|
|
|
|
2012-06-28 20:52:26 +00:00
|
|
|
/*
|
|
|
|
* Used when sorting an interface list into alphabetical order by
|
2012-11-22 06:02:49 +00:00
|
|
|
* their friendly names.
|
2012-06-28 20:52:26 +00:00
|
|
|
*/
|
|
|
|
gint
|
|
|
|
if_list_comparator_alph(const void *first_arg, const void *second_arg)
|
|
|
|
{
|
2013-03-19 04:54:30 +00:00
|
|
|
const if_info_t *first = (const if_info_t *)first_arg, *second = (const if_info_t *)second_arg;
|
2012-06-28 20:52:26 +00:00
|
|
|
|
2012-11-22 06:02:49 +00:00
|
|
|
if (first != NULL && first->friendly_name != NULL &&
|
|
|
|
second != NULL && second->friendly_name != NULL) {
|
|
|
|
return g_ascii_strcasecmp(first->friendly_name, second->friendly_name);
|
2012-06-28 20:52:26 +00:00
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-02 08:13:40 +00:00
|
|
|
static void
|
|
|
|
fill_from_ifaces (interface_t *device)
|
|
|
|
{
|
|
|
|
interface_options interface_opts;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < global_capture_opts.ifaces->len; i++) {
|
|
|
|
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, i);
|
|
|
|
if (strcmp(interface_opts.name, device->name) != 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(HAVE_PCAP_CREATE)
|
|
|
|
device->buffer = interface_opts.buffer_size;
|
|
|
|
device->monitor_mode_enabled = interface_opts.monitor_mode;
|
|
|
|
#endif
|
|
|
|
device->pmode = interface_opts.promisc_mode;
|
|
|
|
device->has_snaplen = interface_opts.has_snaplen;
|
|
|
|
device->snaplen = interface_opts.snaplen;
|
2015-11-26 08:27:51 +00:00
|
|
|
g_free(device->cfilter);
|
2015-12-02 08:13:40 +00:00
|
|
|
device->cfilter = g_strdup(interface_opts.cfilter);
|
|
|
|
if (interface_opts.linktype != -1) {
|
|
|
|
device->active_dlt = interface_opts.linktype;
|
|
|
|
}
|
2016-03-31 10:47:07 +00:00
|
|
|
if (!device->selected) {
|
|
|
|
device->selected = TRUE;
|
|
|
|
global_capture_opts.num_selected++;
|
|
|
|
}
|
2015-12-02 08:13:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-28 18:16:18 +00:00
|
|
|
/*
|
|
|
|
* Fetch the list of local interfaces with capture_interface_list()
|
|
|
|
* and set the list of "all interfaces" in *capture_opts to include
|
|
|
|
* those interfaces.
|
|
|
|
*/
|
2012-08-01 22:32:14 +00:00
|
|
|
void
|
2013-06-27 17:10:50 +00:00
|
|
|
scan_local_interfaces(void (*update_cb)(void))
|
2012-06-28 18:16:18 +00:00
|
|
|
{
|
|
|
|
GList *if_entry, *lt_entry, *if_list;
|
2015-10-04 09:31:19 +00:00
|
|
|
if_info_t *if_info, temp;
|
2012-06-28 18:16:18 +00:00
|
|
|
gchar *descr;
|
|
|
|
if_capabilities_t *caps=NULL;
|
|
|
|
gint linktype_count;
|
2012-08-01 23:35:18 +00:00
|
|
|
gboolean monitor_mode;
|
2012-06-28 18:16:18 +00:00
|
|
|
GSList *curr_addr;
|
2014-07-25 02:25:44 +00:00
|
|
|
int ips = 0, i;
|
2012-06-28 18:16:18 +00:00
|
|
|
guint count = 0, j;
|
|
|
|
if_addr_t *addr, *temp_addr;
|
|
|
|
link_row *link = NULL;
|
|
|
|
data_link_info_t *data_link_info;
|
|
|
|
interface_t device;
|
|
|
|
GString *ip_str;
|
|
|
|
interface_options interface_opts;
|
|
|
|
gboolean found = FALSE;
|
|
|
|
|
2012-08-01 22:32:14 +00:00
|
|
|
|
|
|
|
if (global_capture_opts.all_ifaces->len > 0) {
|
|
|
|
for (i = (int)global_capture_opts.all_ifaces->len-1; i >= 0; i--) {
|
|
|
|
device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
|
2013-04-16 15:12:38 +00:00
|
|
|
if (device.local && device.type != IF_PIPE && device.type != IF_STDIN) {
|
2012-08-01 22:32:14 +00:00
|
|
|
global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i);
|
2014-07-04 22:18:07 +00:00
|
|
|
|
|
|
|
if (device.selected) {
|
|
|
|
global_capture_opts.num_selected--;
|
|
|
|
/* if device was to be used after this statement,
|
|
|
|
we should set device.selected=FALSE here */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if we remove an interface from all_interfaces,
|
|
|
|
it must also be removed from ifaces if it is present there
|
|
|
|
otherwise, it would be re-added to all_interfaces below
|
|
|
|
(interfaces set with -i on the command line are initially present in ifaces but not
|
|
|
|
in all_interfaces, but these interfaces are not removed here) */
|
|
|
|
for (j = 0; j < global_capture_opts.ifaces->len; j++) {
|
|
|
|
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, j);
|
|
|
|
if (strcmp(device.name, interface_opts.name) == 0) {
|
|
|
|
/* 2nd param must be the index of ifaces (not all_ifaces) */
|
|
|
|
capture_opts_del_iface(&global_capture_opts, j);
|
|
|
|
}
|
|
|
|
}
|
2015-11-26 08:27:51 +00:00
|
|
|
capture_opts_free_interface_t(&device);
|
2012-06-28 18:16:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Scan through the list and build a list of strings to display. */
|
2014-07-25 02:25:44 +00:00
|
|
|
g_free(global_capture_opts.ifaces_err_info);
|
|
|
|
if_list = capture_interface_list(&global_capture_opts.ifaces_err,
|
|
|
|
&global_capture_opts.ifaces_err_info,
|
|
|
|
update_cb);
|
2012-06-28 18:16:18 +00:00
|
|
|
count = 0;
|
|
|
|
for (if_entry = if_list; if_entry != NULL; if_entry = g_list_next(if_entry)) {
|
2015-11-26 08:27:51 +00:00
|
|
|
memset(&device, 0, sizeof(device));
|
2013-03-19 04:54:30 +00:00
|
|
|
if_info = (if_info_t *)if_entry->data;
|
2012-06-28 18:16:18 +00:00
|
|
|
ip_str = g_string_new("");
|
|
|
|
ips = 0;
|
|
|
|
if (strstr(if_info->name, "rpcap:")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
device.name = g_strdup(if_info->name);
|
From Mike Garratt:
Friendly Names for interfaces on Windows
Notes on the changes the patch covers:
* if_info_t struct: addition of friendly_name
* Dumpcap Interface list format changes:
+ Win32: "dumpcap -D" shows friendly_name in place of descript if known
+ All: machine interface "dumpcap -D -Z none" includes friendly_name in the
list in addition to the existing parameters
* interface_options struct: addition of console_display_name
+ When an interface name is displayed in a console, it will typically be the
console_display_name (instead of name).
+ console_display_name is used as the basis of the autogenerated temp
filenames
+ console_display_name is typically set to the friendly_name if known,
otherwise it is set to the interface name
* Enhancements to capture_opts_add_iface_opt() (the function which process -i
options).
+ Can now specify the interface using its name and friendly_name
+ Interface name matching is case insenstive
+ Name matching first attempts exact matching, then falls back to prefix
matching
(e.g. dumpcap -i local)
+ Validates interface names, instead of blindly sending them off to
winpcap/libpcap
+ Interface specification by number is still supported.
* capture_opts_trim_iface() has been refactored:
+ Instead of repeating a decent chunk of the cost in
capture_opts_add_iface_opt(), it calls capture_opts_trim_iface() to specify the
interface.
* introduction of capture_win_ifnames.[ch] (windows only code)
+ Implements static function GetInterfaceFriendlyNameFromDeviceGuid() - a
windows version independant function to convert an interface guid into its
friendly name. Uses published api functions on windows vista and higher, but
falls back to unpublished API functions on older windows releases.
+ void get_windows_interface_friendlyname(/* IN */ char
*interface_devicename, /* OUT */char **interface_friendlyname); - extracts the
GUID from the interface_devicename, then uses
GetInterfaceFriendlyNameFromDeviceGuid() to do the resolution
* Auto temp filename generation:
+ Now uses wireshark_pcapng_* or wireshark_pcap_* depending on file format
+ Basis temp filename format on console_display_name
+ Win32: if console_display_name is a windows interface guid, extracts
numbers from GUID here (instead of in interface option processing)
GUI CHANGES:
* Dialog that displays when you click the "Manage Interfaces" button (within
Capture Options dialog) has been renamed from "Add new interfaces" to
"Interface Management"
* ui/gtk/capture_dlg.c: new_interfaces_w variable renamed to
interface_management_w
* Win32: Local Interfaces tab on Interface Management dialog, shows includes
friendly name as far left column
* Interface Management dialog defaults to larger size on win32 - so it fits
without resizing local interfaces tab
* Interface Management dialog now saves preferences when you click the apply
button (local hidden interfaces was not persisting across restarts)
* Tweaks: "Interface Details" dialog (Interface list->Capture Interfaces ->
Details):
+ "Friendly Name" renamed to "NDIS Friendly Name"
+ Added "OS Friendly Name" to the top of the list
* Win32: The "Capture Interfaces" dialog now shows the friendly name instead of
device guid
* Welcome screen:
+ The height of the interface list scrollbox dynamically adjusts & updates to
the number visible interfaces.
Up to 10 interfaces can be listed without a scroll bar, the minimum height
is for 2 interfaces.
+ Win32: now shows just the Friendly Name if known - in place of
"Interfacename_Guid:(Description)"
svn path=/trunk/; revision=46083
2012-11-19 20:07:27 +00:00
|
|
|
if (if_info->friendly_name != NULL) {
|
|
|
|
device.friendly_name = g_strdup(if_info->friendly_name);
|
2012-11-19 22:01:07 +00:00
|
|
|
} else {
|
From Mike Garratt:
Friendly Names for interfaces on Windows
Notes on the changes the patch covers:
* if_info_t struct: addition of friendly_name
* Dumpcap Interface list format changes:
+ Win32: "dumpcap -D" shows friendly_name in place of descript if known
+ All: machine interface "dumpcap -D -Z none" includes friendly_name in the
list in addition to the existing parameters
* interface_options struct: addition of console_display_name
+ When an interface name is displayed in a console, it will typically be the
console_display_name (instead of name).
+ console_display_name is used as the basis of the autogenerated temp
filenames
+ console_display_name is typically set to the friendly_name if known,
otherwise it is set to the interface name
* Enhancements to capture_opts_add_iface_opt() (the function which process -i
options).
+ Can now specify the interface using its name and friendly_name
+ Interface name matching is case insenstive
+ Name matching first attempts exact matching, then falls back to prefix
matching
(e.g. dumpcap -i local)
+ Validates interface names, instead of blindly sending them off to
winpcap/libpcap
+ Interface specification by number is still supported.
* capture_opts_trim_iface() has been refactored:
+ Instead of repeating a decent chunk of the cost in
capture_opts_add_iface_opt(), it calls capture_opts_trim_iface() to specify the
interface.
* introduction of capture_win_ifnames.[ch] (windows only code)
+ Implements static function GetInterfaceFriendlyNameFromDeviceGuid() - a
windows version independant function to convert an interface guid into its
friendly name. Uses published api functions on windows vista and higher, but
falls back to unpublished API functions on older windows releases.
+ void get_windows_interface_friendlyname(/* IN */ char
*interface_devicename, /* OUT */char **interface_friendlyname); - extracts the
GUID from the interface_devicename, then uses
GetInterfaceFriendlyNameFromDeviceGuid() to do the resolution
* Auto temp filename generation:
+ Now uses wireshark_pcapng_* or wireshark_pcap_* depending on file format
+ Basis temp filename format on console_display_name
+ Win32: if console_display_name is a windows interface guid, extracts
numbers from GUID here (instead of in interface option processing)
GUI CHANGES:
* Dialog that displays when you click the "Manage Interfaces" button (within
Capture Options dialog) has been renamed from "Add new interfaces" to
"Interface Management"
* ui/gtk/capture_dlg.c: new_interfaces_w variable renamed to
interface_management_w
* Win32: Local Interfaces tab on Interface Management dialog, shows includes
friendly name as far left column
* Interface Management dialog defaults to larger size on win32 - so it fits
without resizing local interfaces tab
* Interface Management dialog now saves preferences when you click the apply
button (local hidden interfaces was not persisting across restarts)
* Tweaks: "Interface Details" dialog (Interface list->Capture Interfaces ->
Details):
+ "Friendly Name" renamed to "NDIS Friendly Name"
+ Added "OS Friendly Name" to the top of the list
* Win32: The "Capture Interfaces" dialog now shows the friendly name instead of
device guid
* Welcome screen:
+ The height of the interface list scrollbox dynamically adjusts & updates to
the number visible interfaces.
Up to 10 interfaces can be listed without a scroll bar, the minimum height
is for 2 interfaces.
+ Win32: now shows just the Friendly Name if known - in place of
"Interfacename_Guid:(Description)"
svn path=/trunk/; revision=46083
2012-11-19 20:07:27 +00:00
|
|
|
device.friendly_name = NULL;
|
|
|
|
}
|
2012-06-28 18:16:18 +00:00
|
|
|
device.hidden = FALSE;
|
|
|
|
device.locked = FALSE;
|
2015-10-04 09:31:19 +00:00
|
|
|
memset(&temp, 0, sizeof(temp));
|
|
|
|
temp.name = g_strdup(if_info->name);
|
|
|
|
temp.friendly_name = g_strdup(if_info->friendly_name);
|
|
|
|
temp.vendor_description = g_strdup(if_info->vendor_description);
|
|
|
|
temp.loopback = if_info->loopback;
|
|
|
|
temp.type = if_info->type;
|
2014-02-25 13:05:11 +00:00
|
|
|
#ifdef HAVE_EXTCAP
|
2015-10-04 09:31:19 +00:00
|
|
|
temp.extcap = g_strdup(if_info->extcap);
|
2014-02-25 13:05:11 +00:00
|
|
|
#endif
|
2012-06-28 18:16:18 +00:00
|
|
|
/* Is this interface hidden and, if so, should we include it anyway? */
|
|
|
|
|
|
|
|
descr = capture_dev_user_descr_find(if_info->name);
|
2015-12-02 06:32:48 +00:00
|
|
|
device.display_name = get_iface_display_name(descr, if_info);
|
|
|
|
g_free(descr);
|
2012-06-28 18:16:18 +00:00
|
|
|
device.selected = FALSE;
|
|
|
|
if (prefs_is_capture_device_hidden(if_info->name)) {
|
|
|
|
device.hidden = TRUE;
|
2012-08-01 22:32:14 +00:00
|
|
|
}
|
2013-05-22 01:19:18 +00:00
|
|
|
device.type = if_info->type;
|
2012-08-01 23:35:18 +00:00
|
|
|
monitor_mode = prefs_capture_device_monitor_mode(if_info->name);
|
2015-07-17 15:01:27 +00:00
|
|
|
caps = capture_get_if_capabilities(if_info->name, monitor_mode, NULL, NULL, update_cb);
|
2012-06-28 18:16:18 +00:00
|
|
|
for (; (curr_addr = g_slist_nth(if_info->addrs, ips)) != NULL; ips++) {
|
2013-03-19 04:54:30 +00:00
|
|
|
temp_addr = (if_addr_t *)g_malloc0(sizeof(if_addr_t));
|
2012-06-28 18:16:18 +00:00
|
|
|
if (ips != 0) {
|
|
|
|
g_string_append(ip_str, "\n");
|
|
|
|
}
|
|
|
|
addr = (if_addr_t *)curr_addr->data;
|
|
|
|
if (addr) {
|
2014-12-21 13:02:26 +00:00
|
|
|
address addr_str;
|
2015-01-05 16:12:08 +00:00
|
|
|
char* temp_addr_str = NULL;
|
2012-06-28 18:16:18 +00:00
|
|
|
temp_addr->ifat_type = addr->ifat_type;
|
|
|
|
switch (addr->ifat_type) {
|
|
|
|
case IF_AT_IPv4:
|
|
|
|
temp_addr->addr.ip4_addr = addr->addr.ip4_addr;
|
2015-10-21 18:46:49 +00:00
|
|
|
set_address(&addr_str, AT_IPv4, 4, &addr->addr.ip4_addr);
|
2015-01-05 16:12:08 +00:00
|
|
|
temp_addr_str = address_to_str(NULL, &addr_str);
|
|
|
|
g_string_append(ip_str, temp_addr_str);
|
2012-06-28 18:16:18 +00:00
|
|
|
break;
|
|
|
|
case IF_AT_IPv6:
|
|
|
|
memcpy(temp_addr->addr.ip6_addr, addr->addr.ip6_addr, sizeof(addr->addr));
|
2015-10-21 18:46:49 +00:00
|
|
|
set_address(&addr_str, AT_IPv6, 16, addr->addr.ip6_addr);
|
2015-01-05 16:12:08 +00:00
|
|
|
temp_addr_str = address_to_str(NULL, &addr_str);
|
|
|
|
g_string_append(ip_str, temp_addr_str);
|
2012-06-28 18:16:18 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* In case we add non-IP addresses */
|
|
|
|
break;
|
|
|
|
}
|
2015-01-05 16:12:08 +00:00
|
|
|
wmem_free(NULL, temp_addr_str);
|
2012-06-28 18:16:18 +00:00
|
|
|
} else {
|
|
|
|
g_free(temp_addr);
|
|
|
|
temp_addr = NULL;
|
|
|
|
}
|
|
|
|
if (temp_addr) {
|
2015-10-04 09:31:19 +00:00
|
|
|
temp.addrs = g_slist_append(temp.addrs, temp_addr);
|
2012-06-28 18:16:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef HAVE_PCAP_REMOTE
|
|
|
|
device.local = TRUE;
|
|
|
|
device.remote_opts.src_type = CAPTURE_IFLOCAL;
|
2012-08-01 22:32:14 +00:00
|
|
|
device.remote_opts.remote_host_opts.remote_host = g_strdup(global_capture_opts.default_options.remote_host);
|
|
|
|
device.remote_opts.remote_host_opts.remote_port = g_strdup(global_capture_opts.default_options.remote_port);
|
|
|
|
device.remote_opts.remote_host_opts.auth_type = global_capture_opts.default_options.auth_type;
|
|
|
|
device.remote_opts.remote_host_opts.auth_username = g_strdup(global_capture_opts.default_options.auth_username);
|
|
|
|
device.remote_opts.remote_host_opts.auth_password = g_strdup(global_capture_opts.default_options.auth_password);
|
|
|
|
device.remote_opts.remote_host_opts.datatx_udp = global_capture_opts.default_options.datatx_udp;
|
|
|
|
device.remote_opts.remote_host_opts.nocap_rpcap = global_capture_opts.default_options.nocap_rpcap;
|
|
|
|
device.remote_opts.remote_host_opts.nocap_local = global_capture_opts.default_options.nocap_local;
|
2012-06-28 18:16:18 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_PCAP_SETSAMPLING
|
2012-08-01 22:32:14 +00:00
|
|
|
device.remote_opts.sampling_method = global_capture_opts.default_options.sampling_method;
|
|
|
|
device.remote_opts.sampling_param = global_capture_opts.default_options.sampling_param;
|
2012-06-28 18:16:18 +00:00
|
|
|
#endif
|
|
|
|
linktype_count = 0;
|
|
|
|
device.links = NULL;
|
|
|
|
if (caps != NULL) {
|
|
|
|
#if defined(HAVE_PCAP_CREATE)
|
2012-08-01 23:35:18 +00:00
|
|
|
device.monitor_mode_enabled = monitor_mode;
|
2012-06-28 18:16:18 +00:00
|
|
|
device.monitor_mode_supported = caps->can_set_rfmon;
|
2012-08-01 22:32:14 +00:00
|
|
|
#endif
|
2013-11-25 21:21:25 +00:00
|
|
|
/*
|
|
|
|
* Process the list of link-layer header types.
|
|
|
|
*/
|
2012-06-28 18:16:18 +00:00
|
|
|
for (lt_entry = caps->data_link_types; lt_entry != NULL; lt_entry = g_list_next(lt_entry)) {
|
2013-03-19 04:54:30 +00:00
|
|
|
data_link_info = (data_link_info_t *)lt_entry->data;
|
2012-06-28 18:16:18 +00:00
|
|
|
link = (link_row *)g_malloc(sizeof(link_row));
|
|
|
|
if (data_link_info->description != NULL) {
|
|
|
|
link->dlt = data_link_info->dlt;
|
2016-06-06 02:24:47 +00:00
|
|
|
link->name = g_strdup(data_link_info->description);
|
2012-06-28 18:16:18 +00:00
|
|
|
} else {
|
|
|
|
link->dlt = -1;
|
|
|
|
link->name = g_strdup_printf("%s (not supported)", data_link_info->name);
|
|
|
|
}
|
|
|
|
device.links = g_list_append(device.links, link);
|
|
|
|
linktype_count++;
|
|
|
|
}
|
2015-03-22 23:58:42 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the active DLT for the device appropriately.
|
|
|
|
*/
|
|
|
|
set_active_dlt(&device, global_capture_opts.default_options.linktype);
|
2012-06-28 18:16:18 +00:00
|
|
|
} else {
|
|
|
|
#if defined(HAVE_PCAP_CREATE)
|
|
|
|
device.monitor_mode_enabled = FALSE;
|
|
|
|
device.monitor_mode_supported = FALSE;
|
|
|
|
#endif
|
|
|
|
device.active_dlt = -1;
|
|
|
|
}
|
|
|
|
device.addresses = g_strdup(ip_str->str);
|
|
|
|
device.no_addresses = ips;
|
|
|
|
device.local = TRUE;
|
2015-10-04 09:31:19 +00:00
|
|
|
device.if_info = temp;
|
2012-06-28 18:16:18 +00:00
|
|
|
device.last_packets = 0;
|
2015-04-04 21:01:56 +00:00
|
|
|
if (!capture_dev_user_pmode_find(if_info->name, &device.pmode)) {
|
2013-03-13 12:38:08 +00:00
|
|
|
device.pmode = global_capture_opts.default_options.promisc_mode;
|
|
|
|
}
|
2015-03-18 23:58:15 +00:00
|
|
|
if (!capture_dev_user_snaplen_find(if_info->name, &device.has_snaplen,
|
|
|
|
&device.snaplen)) {
|
2013-03-13 12:38:08 +00:00
|
|
|
device.has_snaplen = global_capture_opts.default_options.has_snaplen;
|
|
|
|
device.snaplen = global_capture_opts.default_options.snaplen;
|
|
|
|
}
|
2012-08-01 22:32:14 +00:00
|
|
|
device.cfilter = g_strdup(global_capture_opts.default_options.cfilter);
|
2015-03-25 03:22:00 +00:00
|
|
|
#ifdef CAN_SET_CAPTURE_BUFFER_SIZE
|
2013-03-13 12:38:08 +00:00
|
|
|
if ((device.buffer = capture_dev_user_buffersize_find(if_info->name)) == -1) {
|
|
|
|
device.buffer = global_capture_opts.default_options.buffer_size;
|
|
|
|
}
|
2012-06-28 18:16:18 +00:00
|
|
|
#endif
|
2012-08-01 22:32:14 +00:00
|
|
|
|
2015-12-02 08:13:40 +00:00
|
|
|
fill_from_ifaces(&device);
|
2014-02-25 13:05:11 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_EXTCAP
|
|
|
|
/* Extcap devices start with no cached args */
|
|
|
|
device.external_cap_args_settings = NULL;
|
|
|
|
#endif
|
2012-08-01 22:32:14 +00:00
|
|
|
if (global_capture_opts.all_ifaces->len <= count) {
|
|
|
|
g_array_append_val(global_capture_opts.all_ifaces, device);
|
|
|
|
count = global_capture_opts.all_ifaces->len;
|
2012-06-28 18:16:18 +00:00
|
|
|
} else {
|
2012-08-01 22:32:14 +00:00
|
|
|
g_array_insert_val(global_capture_opts.all_ifaces, count, device);
|
2012-06-28 18:16:18 +00:00
|
|
|
}
|
|
|
|
if (caps != NULL) {
|
|
|
|
free_if_capabilities(caps);
|
|
|
|
}
|
2012-08-01 22:32:14 +00:00
|
|
|
|
2012-06-28 18:16:18 +00:00
|
|
|
g_string_free(ip_str, TRUE);
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
free_interface_list(if_list);
|
|
|
|
/* see whether there are additional interfaces in ifaces */
|
2012-08-01 22:32:14 +00:00
|
|
|
for (j = 0; j < global_capture_opts.ifaces->len; j++) {
|
|
|
|
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, j);
|
2012-06-28 18:16:18 +00:00
|
|
|
found = FALSE;
|
2012-08-01 22:32:14 +00:00
|
|
|
for (i = 0; i < (int)global_capture_opts.all_ifaces->len; i++) {
|
|
|
|
device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
|
2012-06-28 18:16:18 +00:00
|
|
|
if (strcmp(device.name, interface_opts.name) == 0) {
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) { /* new interface, maybe a pipe */
|
2015-11-26 08:27:51 +00:00
|
|
|
memset(&device, 0, sizeof(device));
|
2012-06-28 18:16:18 +00:00
|
|
|
device.name = g_strdup(interface_opts.name);
|
2014-07-07 03:28:37 +00:00
|
|
|
device.display_name = interface_opts.descr ?
|
|
|
|
g_strdup_printf("%s: %s", device.name, interface_opts.descr) :
|
2016-06-06 02:24:47 +00:00
|
|
|
g_strdup(device.name);
|
2012-06-28 18:16:18 +00:00
|
|
|
device.hidden = FALSE;
|
|
|
|
device.selected = TRUE;
|
|
|
|
device.type = IF_PIPE;
|
2015-03-25 03:22:00 +00:00
|
|
|
#ifdef CAN_SET_CAPTURE_BUFFER_SIZE
|
2012-06-28 18:16:18 +00:00
|
|
|
device.buffer = interface_opts.buffer_size;
|
|
|
|
#endif
|
|
|
|
#if defined(HAVE_PCAP_CREATE)
|
|
|
|
device.monitor_mode_enabled = interface_opts.monitor_mode;
|
|
|
|
device.monitor_mode_supported = FALSE;
|
|
|
|
#endif
|
|
|
|
device.pmode = interface_opts.promisc_mode;
|
|
|
|
device.has_snaplen = interface_opts.has_snaplen;
|
2012-08-01 22:32:14 +00:00
|
|
|
device.snaplen = interface_opts.snaplen;
|
2012-06-28 18:16:18 +00:00
|
|
|
device.cfilter = g_strdup(interface_opts.cfilter);
|
|
|
|
device.active_dlt = interface_opts.linktype;
|
|
|
|
device.addresses = NULL;
|
|
|
|
device.no_addresses = 0;
|
|
|
|
device.last_packets = 0;
|
|
|
|
device.links = NULL;
|
|
|
|
device.local = TRUE;
|
|
|
|
device.locked = FALSE;
|
2012-07-22 22:09:46 +00:00
|
|
|
device.if_info.name = g_strdup(interface_opts.name);
|
2012-11-22 06:02:49 +00:00
|
|
|
device.if_info.friendly_name = NULL;
|
|
|
|
device.if_info.vendor_description = g_strdup(interface_opts.descr);
|
2012-07-22 22:09:46 +00:00
|
|
|
device.if_info.addrs = NULL;
|
|
|
|
device.if_info.loopback = FALSE;
|
2014-02-25 13:05:11 +00:00
|
|
|
#ifdef HAVE_EXTCAP
|
|
|
|
device.if_info.extcap = g_strdup(interface_opts.extcap);
|
|
|
|
#endif
|
2012-06-28 18:16:18 +00:00
|
|
|
|
2012-08-01 22:32:14 +00:00
|
|
|
g_array_append_val(global_capture_opts.all_ifaces, device);
|
|
|
|
global_capture_opts.num_selected++;
|
2012-06-28 18:16:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-02-25 20:42:35 +00:00
|
|
|
* Get the global interface list. Generate it if we haven't done so
|
|
|
|
* already. This can be quite time consuming the first time, so
|
2013-06-04 04:36:19 +00:00
|
|
|
* record how long it takes in the info log.
|
2012-06-28 18:16:18 +00:00
|
|
|
*/
|
|
|
|
void
|
2013-06-27 17:10:50 +00:00
|
|
|
fill_in_local_interfaces(void(*update_cb)(void))
|
2012-06-28 18:16:18 +00:00
|
|
|
{
|
2014-10-06 02:14:57 +00:00
|
|
|
GTimeVal start_time;
|
|
|
|
GTimeVal end_time;
|
|
|
|
float elapsed;
|
|
|
|
static gboolean initialized = FALSE;
|
2012-06-28 18:16:18 +00:00
|
|
|
|
2014-10-06 02:14:57 +00:00
|
|
|
/* record the time we started, so we can log total time later */
|
|
|
|
g_get_current_time(&start_time);
|
|
|
|
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_INFO, "fill_in_local_interfaces() starts");
|
2014-02-25 20:42:35 +00:00
|
|
|
|
2012-06-28 18:16:18 +00:00
|
|
|
if (!initialized) {
|
2014-10-06 02:14:57 +00:00
|
|
|
/* do the actual work */
|
2013-06-27 17:10:50 +00:00
|
|
|
scan_local_interfaces(update_cb);
|
2012-06-28 18:16:18 +00:00
|
|
|
initialized = TRUE;
|
|
|
|
}
|
2014-10-06 02:14:57 +00:00
|
|
|
/* log how long it took */
|
2013-06-04 04:36:19 +00:00
|
|
|
g_get_current_time(&end_time);
|
|
|
|
elapsed = (float) ((end_time.tv_sec - start_time.tv_sec) +
|
2014-10-06 02:14:57 +00:00
|
|
|
((end_time.tv_usec - start_time.tv_usec) / 1e6));
|
2013-06-04 04:36:19 +00:00
|
|
|
|
|
|
|
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_INFO, "fill_in_local_interfaces() ends, taking %.3fs", elapsed);
|
2012-06-28 18:16:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
hide_interface(gchar* new_hide)
|
|
|
|
{
|
|
|
|
gchar *tok;
|
|
|
|
guint i;
|
|
|
|
interface_t device;
|
|
|
|
gboolean found = FALSE;
|
|
|
|
GList *hidden_devices = NULL, *entry;
|
|
|
|
if (new_hide != NULL) {
|
|
|
|
for (tok = strtok (new_hide, ","); tok; tok = strtok(NULL, ",")) {
|
|
|
|
hidden_devices = g_list_append(hidden_devices, tok);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < global_capture_opts.all_ifaces->len; i++) {
|
|
|
|
device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
|
|
|
|
found = FALSE;
|
|
|
|
for (entry = hidden_devices; entry != NULL; entry = g_list_next(entry)) {
|
2013-03-19 04:54:30 +00:00
|
|
|
if (strcmp((char *)entry->data, device.name)==0) {
|
2012-06-28 18:16:18 +00:00
|
|
|
device.hidden = TRUE;
|
|
|
|
if (device.selected) {
|
|
|
|
device.selected = FALSE;
|
|
|
|
global_capture_opts.num_selected--;
|
|
|
|
}
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2012-08-01 22:32:14 +00:00
|
|
|
}
|
2012-06-28 18:16:18 +00:00
|
|
|
if (!found) {
|
|
|
|
device.hidden = FALSE;
|
|
|
|
}
|
|
|
|
global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i);
|
|
|
|
g_array_insert_val(global_capture_opts.all_ifaces, i, device);
|
|
|
|
}
|
Fix memory leaks related to hide_interface function
Valgrind report leaks like these:
6 bytes in 6 blocks are definitely lost in loss record 2,197 of 46,703
at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0xA5C1610: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
by 0xA5D8B0E: g_strdup (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
by 0x69A211: ManageInterfacesDialog::localAccepted() (manage_interfaces_dialog.cpp:454)
by 0x69A500: ManageInterfacesDialog::on_buttonBox_accepted() (manage_interfaces_dialog.cpp:211)
by 0x71DB32: ManageInterfacesDialog::qt_metacall(QMetaObject::Call, int, void**) (manage_interfaces_dialog.moc.cpp:245)
by 0xBEBE36C: QMetaObject::activate(QObject*, int, int, void**) (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1)
by 0xBEBE2A5: QMetaObject::activate(QObject*, int, int, void**) (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1)
by 0xAF87E41: QAbstractButton::clicked(bool) (in /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5.2.1)
by 0xAD11095: ??? (in /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5.2.1)
by 0xAD11BAD: ??? (in /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5.2.1)
by 0xAD11D23: QAbstractButton::mouseReleaseEvent(QMouseEvent*) (in /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5.2.1)
96 bytes in 4 blocks are definitely lost in loss record 42,458 of 52,779
at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0xA5C1610: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
by 0xA5D722D: g_slice_alloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
by 0xA5B84F3: g_list_append (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0)
by 0x731F9A: hide_interface (iface_lists.c:426)
by 0x69A211: ManageInterfacesDialog::localAccepted() (manage_interfaces_dialog.cpp:454)
by 0x69A4F0: ManageInterfacesDialog::on_buttonBox_accepted() (manage_interfaces_dialog.cpp:211)
by 0x71DB22: ManageInterfacesDialog::qt_metacall(QMetaObject::Call, int, void**) (manage_interfaces_dialog.moc.cpp:245)
by 0xBEBE36C: QMetaObject::activate(QObject*, int, int, void**) (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1)
by 0xBEBE2A5: QMetaObject::activate(QObject*, int, int, void**) (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1)
by 0xAF87E41: QAbstractButton::clicked(bool) (in /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5.2.1)
by 0xAD11095: ??? (in /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5.2.1)
These are caused by leaks inside hide_interface function and among
its users. Fixed by letting hide_interface function free its
resources properly and making sure the users follow the pattern.
Change-Id: I91527b83d36dc38b402d0f4a1db4b7db40fd83f9
Reviewed-on: https://code.wireshark.org/review/12113
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2015-11-23 15:33:41 +00:00
|
|
|
g_list_free(hidden_devices);
|
|
|
|
g_free(new_hide);
|
2012-06-28 18:16:18 +00:00
|
|
|
}
|
2015-12-02 08:13:40 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
update_local_interfaces(void)
|
|
|
|
{
|
|
|
|
interface_t device;
|
|
|
|
gchar *descr;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < global_capture_opts.all_ifaces->len; i++) {
|
|
|
|
device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
|
|
|
|
device.type = capture_dev_user_linktype_find(device.name);
|
|
|
|
g_free (device.display_name);
|
|
|
|
descr = capture_dev_user_descr_find(device.name);
|
|
|
|
device.display_name = get_iface_display_name(descr, &device.if_info);
|
|
|
|
g_free (descr);
|
|
|
|
device.hidden = prefs_is_capture_device_hidden(device.name);
|
|
|
|
fill_from_ifaces(&device);
|
|
|
|
|
|
|
|
global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i);
|
|
|
|
g_array_insert_val(global_capture_opts.all_ifaces, i, device);
|
|
|
|
}
|
|
|
|
}
|
2012-06-28 18:16:18 +00:00
|
|
|
#endif /* HAVE_LIBPCAP */
|
2012-10-24 15:52:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* ex: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
|
|
|
*/
|