aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Kaiser <wireshark@kaiser.cx>2014-07-04 18:18:07 -0400
committerEvan Huus <eapache@gmail.com>2014-07-12 14:06:03 +0000
commit55733ea17021b160c17df09b3d3a602386c8586f (patch)
tree643de689cebc98b02f41f4fc6f79170fa844d62f
parent5fda232659f25bedbf426dfc25f174119614229f (diff)
fix scan_local_interfaces()
when we delete an interface from all_ifaces, delete it from ifaces as well remove its selected status if it was selected at the moment, an interface that was used for capturing before will never be removed from the list of interfaces even if it becomes unavailable as it remains in ifaces and will be re-added to all_ifaces in scan_local_interfaces() new helper function capture_opts_del_iface() to delete an entry from ifaces and free all its components Change-Id: Ie3271a7ed086367e511d3a971f3b68cfc014115d Reviewed-on: https://code.wireshark.org/review/2965 Reviewed-by: Evan Huus <eapache@gmail.com>
-rw-r--r--capture_opts.c35
-rw-r--r--capture_opts.h3
-rw-r--r--ui/iface_lists.c19
3 files changed, 45 insertions, 12 deletions
diff --git a/capture_opts.c b/capture_opts.c
index 57139662a8..1d4921fa91 100644
--- a/capture_opts.c
+++ b/capture_opts.c
@@ -1013,20 +1013,14 @@ capture_opts_output_to_pipe(const char *save_file, gboolean *is_pipe)
return 0;
}
-/*
- * Add all non-hidden selected interfaces in the "all interfaces" list
- * to the list of interfaces for the capture.
- */
void
-collect_ifaces(capture_options *capture_opts)
+capture_opts_del_iface(capture_options *capture_opts, guint index)
{
- guint i;
- interface_t device;
interface_options interface_opts;
- /* Empty out the existing list of interfaces. */
- for (i = capture_opts->ifaces->len; i != 0; i--) {
- interface_opts = g_array_index(capture_opts->ifaces, interface_options, i - 1);
+ interface_opts = g_array_index(capture_opts->ifaces, interface_options, index);
+ /* XXX - check if found? */
+
g_free(interface_opts.name);
g_free(interface_opts.descr);
if (interface_opts.console_display_name != NULL)
@@ -1040,8 +1034,25 @@ collect_ifaces(capture_options *capture_opts)
g_free(interface_opts.auth_password);
}
#endif
- capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, i - 1);
- }
+ capture_opts->ifaces = g_array_remove_index(capture_opts->ifaces, index);
+}
+
+
+
+/*
+ * Add all non-hidden selected interfaces in the "all interfaces" list
+ * to the list of interfaces for the capture.
+ */
+void
+collect_ifaces(capture_options *capture_opts)
+{
+ guint i;
+ interface_t device;
+ interface_options interface_opts;
+
+ /* Empty out the existing list of interfaces. */
+ for (i = capture_opts->ifaces->len; i != 0; i--)
+ capture_opts_del_iface(capture_opts, i-1);
/* Now fill the list up again. */
for (i = 0; i < capture_opts->all_ifaces->len; i++) {
diff --git a/capture_opts.h b/capture_opts.h
index 69f4d2d7bd..3d88f647cb 100644
--- a/capture_opts.h
+++ b/capture_opts.h
@@ -339,6 +339,9 @@ capture_opts_default_iface_if_necessary(capture_options *capture_opts,
const char *capture_device);
extern void
+capture_opts_del_iface(capture_options *capture_opts, guint index);
+
+extern void
collect_ifaces(capture_options *capture_opts);
/* Default capture buffer size in Mbytes. */
diff --git a/ui/iface_lists.c b/ui/iface_lists.c
index b28236b177..a0b75af240 100644
--- a/ui/iface_lists.c
+++ b/ui/iface_lists.c
@@ -86,6 +86,25 @@ scan_local_interfaces(void (*update_cb)(void))
device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
if (device.local && device.type != IF_PIPE && device.type != IF_STDIN) {
global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i);
+
+ 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);
+ }
+ }
}
}
}