diff options
author | Mikael Kanstrup <mikael.kanstrup@gmail.com> | 2017-08-24 16:16:34 +0200 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2017-08-28 14:41:43 +0000 |
commit | 8873c7e494018637449a17a7f7ddaf88ad43f3c6 (patch) | |
tree | 162c283b967e7dc5f98a54575ff2ed25444997a8 /wireshark-qt.cpp | |
parent | 76c231bd683410bed4fa803bcbc91e613e201ab0 (diff) |
iface_lists: Access all_ifaces member by reference
Change access of all_ifaces elements from by val to by reference.
With this change unnecessary copying of the whole struct is avoided
but even more important is that elements no longer have to be
removed and inserted whenever data is updated.
This change aims to make it more clear that all_ifaces elements
shall never be removed from the array without freeing resources
via the capture_opts_free_interface_t function.
NOTE: Code for GTK UI not updated
Ping-Bug: 13864
Change-Id: I36742cb1d5c8daa136c9d3732a044a7c8e5c7fe7
Reviewed-on: https://code.wireshark.org/review/23201
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'wireshark-qt.cpp')
-rw-r--r-- | wireshark-qt.cpp | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/wireshark-qt.cpp b/wireshark-qt.cpp index 19687f65b5..40edbea0a5 100644 --- a/wireshark-qt.cpp +++ b/wireshark-qt.cpp @@ -737,15 +737,15 @@ int main(int argc, char *qt_argv[]) /* Get the list of link-layer types for the capture devices. */ if_capabilities_t *caps; guint i; - interface_t device; + interface_t *device; for (i = 0; i < global_capture_opts.all_ifaces->len; i++) { int if_caps_queries = caps_queries; - device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); - if (device.selected) { + device = &g_array_index(global_capture_opts.all_ifaces, interface_t, i); + if (device->selected) { #if defined(HAVE_PCAP_CREATE) - caps = capture_get_if_capabilities(device.name, device.monitor_mode_supported, NULL, &err_str, main_window_update); + caps = capture_get_if_capabilities(device->name, device->monitor_mode_supported, NULL, &err_str, main_window_update); #else - caps = capture_get_if_capabilities(device.name, FALSE, NULL, &err_str,main_window_update); + caps = capture_get_if_capabilities(device->name, FALSE, NULL, &err_str,main_window_update); #endif if (caps == NULL) { cmdarg_err("%s", err_str); @@ -754,7 +754,7 @@ int main(int argc, char *qt_argv[]) goto clean_exit; } if (caps->data_link_types == NULL) { - cmdarg_err("The capture device \"%s\" has no data link types.", device.name); + cmdarg_err("The capture device \"%s\" has no data link types.", device->name); ret_val = INVALID_LINK_TYPE; goto clean_exit; } @@ -762,10 +762,10 @@ int main(int argc, char *qt_argv[]) create_console(); #endif /* _WIN32 */ #if defined(HAVE_PCAP_CREATE) - if (device.monitor_mode_supported) + if (device->monitor_mode_supported) if_caps_queries |= CAPS_MONITOR_MODE; #endif - capture_opts_print_if_capabilities(caps, device.name, if_caps_queries); + capture_opts_print_if_capabilities(caps, device->name, if_caps_queries); #ifdef _WIN32 destroy_console(); #endif /* _WIN32 */ @@ -794,14 +794,12 @@ int main(int argc, char *qt_argv[]) if ((global_capture_opts.num_selected == 0) && (prefs.capture_device != NULL)) { guint i; - interface_t device; + interface_t *device; for (i = 0; i < global_capture_opts.all_ifaces->len; i++) { - device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); - if (!device.hidden && strcmp(device.display_name, prefs.capture_device) == 0) { - device.selected = TRUE; + device = &g_array_index(global_capture_opts.all_ifaces, interface_t, i); + if (!device->hidden && strcmp(device->display_name, prefs.capture_device) == 0) { + device->selected = TRUE; global_capture_opts.num_selected++; - 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); break; } } |