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>
This commit is contained in:
Mikael Kanstrup 2017-08-24 16:16:34 +02:00 committed by Anders Broman
parent 76c231bd68
commit 8873c7e494
17 changed files with 233 additions and 270 deletions

View File

@ -1206,7 +1206,7 @@ void
collect_ifaces(capture_options *capture_opts) collect_ifaces(capture_options *capture_opts)
{ {
guint i; guint i;
interface_t device; interface_t *device;
interface_options interface_opts; interface_options interface_opts;
/* Empty out the existing list of interfaces. */ /* Empty out the existing list of interfaces. */
@ -1215,23 +1215,23 @@ collect_ifaces(capture_options *capture_opts)
/* Now fill the list up again. */ /* Now fill the list up again. */
for (i = 0; i < capture_opts->all_ifaces->len; i++) { for (i = 0; i < capture_opts->all_ifaces->len; i++) {
device = g_array_index(capture_opts->all_ifaces, interface_t, i); device = &g_array_index(capture_opts->all_ifaces, interface_t, i);
if (!device.hidden && device.selected) { if (!device->hidden && device->selected) {
interface_opts.name = g_strdup(device.name); interface_opts.name = g_strdup(device->name);
interface_opts.descr = g_strdup(device.display_name); interface_opts.descr = g_strdup(device->display_name);
interface_opts.console_display_name = g_strdup(device.name); interface_opts.console_display_name = g_strdup(device->name);
interface_opts.linktype = device.active_dlt; interface_opts.linktype = device->active_dlt;
interface_opts.cfilter = g_strdup(device.cfilter); interface_opts.cfilter = g_strdup(device->cfilter);
interface_opts.timestamp_type = g_strdup(device.timestamp_type); interface_opts.timestamp_type = g_strdup(device->timestamp_type);
interface_opts.snaplen = device.snaplen; interface_opts.snaplen = device->snaplen;
interface_opts.has_snaplen = device.has_snaplen; interface_opts.has_snaplen = device->has_snaplen;
interface_opts.promisc_mode = device.pmode; interface_opts.promisc_mode = device->pmode;
interface_opts.if_type = device.if_info.type; interface_opts.if_type = device->if_info.type;
#ifdef HAVE_EXTCAP #ifdef HAVE_EXTCAP
interface_opts.extcap = g_strdup(device.if_info.extcap); interface_opts.extcap = g_strdup(device->if_info.extcap);
interface_opts.extcap_fifo = NULL; interface_opts.extcap_fifo = NULL;
interface_opts.extcap_userdata = NULL; interface_opts.extcap_userdata = NULL;
interface_opts.extcap_args = device.external_cap_args_settings; interface_opts.extcap_args = device->external_cap_args_settings;
interface_opts.extcap_pid = INVALID_EXTCAP_PID; interface_opts.extcap_pid = INVALID_EXTCAP_PID;
if (interface_opts.extcap_args) if (interface_opts.extcap_args)
g_hash_table_ref(interface_opts.extcap_args); g_hash_table_ref(interface_opts.extcap_args);
@ -1245,25 +1245,25 @@ collect_ifaces(capture_options *capture_opts)
interface_opts.extcap_control_out = NULL; interface_opts.extcap_control_out = NULL;
#endif #endif
#ifdef CAN_SET_CAPTURE_BUFFER_SIZE #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
interface_opts.buffer_size = device.buffer; interface_opts.buffer_size = device->buffer;
#endif #endif
#ifdef HAVE_PCAP_CREATE #ifdef HAVE_PCAP_CREATE
interface_opts.monitor_mode = device.monitor_mode_enabled; interface_opts.monitor_mode = device->monitor_mode_enabled;
#endif #endif
#ifdef HAVE_PCAP_REMOTE #ifdef HAVE_PCAP_REMOTE
interface_opts.src_type = CAPTURE_IFREMOTE; interface_opts.src_type = CAPTURE_IFREMOTE;
interface_opts.remote_host = g_strdup(device.remote_opts.remote_host_opts.remote_host); interface_opts.remote_host = g_strdup(device->remote_opts.remote_host_opts.remote_host);
interface_opts.remote_port = g_strdup(device.remote_opts.remote_host_opts.remote_port); interface_opts.remote_port = g_strdup(device->remote_opts.remote_host_opts.remote_port);
interface_opts.auth_type = device.remote_opts.remote_host_opts.auth_type; interface_opts.auth_type = device->remote_opts.remote_host_opts.auth_type;
interface_opts.auth_username = g_strdup(device.remote_opts.remote_host_opts.auth_username); interface_opts.auth_username = g_strdup(device->remote_opts.remote_host_opts.auth_username);
interface_opts.auth_password = g_strdup(device.remote_opts.remote_host_opts.auth_password); interface_opts.auth_password = g_strdup(device->remote_opts.remote_host_opts.auth_password);
interface_opts.datatx_udp = device.remote_opts.remote_host_opts.datatx_udp; interface_opts.datatx_udp = device->remote_opts.remote_host_opts.datatx_udp;
interface_opts.nocap_rpcap = device.remote_opts.remote_host_opts.nocap_rpcap; interface_opts.nocap_rpcap = device->remote_opts.remote_host_opts.nocap_rpcap;
interface_opts.nocap_local = device.remote_opts.remote_host_opts.nocap_local; interface_opts.nocap_local = device->remote_opts.remote_host_opts.nocap_local;
#endif #endif
#ifdef HAVE_PCAP_SETSAMPLING #ifdef HAVE_PCAP_SETSAMPLING
interface_opts.sampling_method = device.remote_opts.sampling_method; interface_opts.sampling_method = device->remote_opts.sampling_method;
interface_opts.sampling_param = device.remote_opts.sampling_param; interface_opts.sampling_param = device->remote_opts.sampling_param;
#endif #endif
g_array_append_val(capture_opts->ifaces, interface_opts); g_array_append_val(capture_opts->ifaces, interface_opts);
} else { } else {

View File

@ -203,7 +203,7 @@ void
summary_fill_in_capture(capture_file *cf,capture_options *capture_opts, summary_tally *st) summary_fill_in_capture(capture_file *cf,capture_options *capture_opts, summary_tally *st)
{ {
iface_options iface; iface_options iface;
interface_t device; interface_t *device;
guint i; guint i;
if (st->ifaces->len == 0) { if (st->ifaces->len == 0) {
@ -211,17 +211,17 @@ summary_fill_in_capture(capture_file *cf,capture_options *capture_opts, summary_
* XXX - do this only if we have a live capture. * XXX - do this only if we have a live capture.
*/ */
for (i = 0; i < capture_opts->all_ifaces->len; i++) { for (i = 0; i < capture_opts->all_ifaces->len; i++) {
device = g_array_index(capture_opts->all_ifaces, interface_t, i); device = &g_array_index(capture_opts->all_ifaces, interface_t, i);
if (!device.selected) { if (!device->selected) {
continue; continue;
} }
iface.cfilter = g_strdup(device.cfilter); iface.cfilter = g_strdup(device->cfilter);
iface.name = g_strdup(device.name); iface.name = g_strdup(device->name);
iface.descr = g_strdup(device.display_name); iface.descr = g_strdup(device->display_name);
iface.drops_known = cf->drops_known; iface.drops_known = cf->drops_known;
iface.drops = cf->drops; iface.drops = cf->drops;
iface.snap = device.snaplen; iface.snap = device->snaplen;
iface.encap_type = wtap_pcap_encap_to_wtap_encap(device.active_dlt); iface.encap_type = wtap_pcap_encap_to_wtap_encap(device->active_dlt);
g_array_append_val(st->ifaces, iface); g_array_append_val(st->ifaces, iface);
} }
} }

View File

@ -641,7 +641,7 @@ capture_stat_start(capture_options *capture_opts) {
if_stat_cache_t *sc = NULL; if_stat_cache_t *sc = NULL;
if_stat_cache_item_t *sc_item; if_stat_cache_item_t *sc_item;
guint i; guint i;
interface_t device; interface_t *device;
/* Fire up dumpcap. */ /* Fire up dumpcap. */
/* /*
@ -670,11 +670,11 @@ capture_stat_start(capture_options *capture_opts) {
/* Initialize the cache */ /* Initialize the cache */
for (i = 0; i < capture_opts->all_ifaces->len; i++) { for (i = 0; i < capture_opts->all_ifaces->len; i++) {
device = g_array_index(capture_opts->all_ifaces, interface_t, i); device = &g_array_index(capture_opts->all_ifaces, interface_t, i);
if (device.type != IF_PIPE) { if (device->type != IF_PIPE) {
sc_item = (if_stat_cache_item_t *)g_malloc0(sizeof(if_stat_cache_item_t)); sc_item = (if_stat_cache_item_t *)g_malloc0(sizeof(if_stat_cache_item_t));
g_assert(device.if_info.name); g_assert(device->if_info.name);
sc_item->name = g_strdup(device.if_info.name); sc_item->name = g_strdup(device->if_info.name);
sc->cache_list = g_list_append(sc->cache_list, sc_item); sc->cache_list = g_list_append(sc->cache_list, sc_item);
} }
} }

View File

@ -435,7 +435,7 @@ hide_interface(gchar* new_hide)
{ {
gchar *tok; gchar *tok;
guint i; guint i;
interface_t device; interface_t *device;
gboolean found = FALSE; gboolean found = FALSE;
GList *hidden_devices = NULL, *entry; GList *hidden_devices = NULL, *entry;
if (new_hide != NULL) { if (new_hide != NULL) {
@ -444,13 +444,13 @@ hide_interface(gchar* new_hide)
} }
} }
for (i = 0; i < global_capture_opts.all_ifaces->len; 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 = &g_array_index(global_capture_opts.all_ifaces, interface_t, i);
found = FALSE; found = FALSE;
for (entry = hidden_devices; entry != NULL; entry = g_list_next(entry)) { for (entry = hidden_devices; entry != NULL; entry = g_list_next(entry)) {
if (strcmp((char *)entry->data, device.name)==0) { if (strcmp((char *)entry->data, device->name)==0) {
device.hidden = TRUE; device->hidden = TRUE;
if (device.selected) { if (device->selected) {
device.selected = FALSE; device->selected = FALSE;
global_capture_opts.num_selected--; global_capture_opts.num_selected--;
} }
found = TRUE; found = TRUE;
@ -458,10 +458,8 @@ hide_interface(gchar* new_hide)
} }
} }
if (!found) { if (!found) {
device.hidden = FALSE; 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);
} }
g_list_free(hidden_devices); g_list_free(hidden_devices);
g_free(new_hide); g_free(new_hide);
@ -470,22 +468,19 @@ hide_interface(gchar* new_hide)
void void
update_local_interfaces(void) update_local_interfaces(void)
{ {
interface_t device; interface_t *device;
gchar *descr; gchar *descr;
guint i; guint i;
for (i = 0; i < global_capture_opts.all_ifaces->len; 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 = &g_array_index(global_capture_opts.all_ifaces, interface_t, i);
device.type = capture_dev_user_linktype_find(device.name); device->type = capture_dev_user_linktype_find(device->name);
g_free (device.display_name); g_free(device->display_name);
descr = capture_dev_user_descr_find(device.name); descr = capture_dev_user_descr_find(device->name);
device.display_name = get_iface_display_name(descr, &device.if_info); device->display_name = get_iface_display_name(descr, &device->if_info);
g_free (descr); g_free (descr);
device.hidden = prefs_is_capture_device_hidden(device.name); device->hidden = prefs_is_capture_device_hidden(device->name);
fill_from_ifaces(&device); 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);
} }
} }
#endif /* HAVE_LIBPCAP */ #endif /* HAVE_LIBPCAP */

View File

@ -89,19 +89,19 @@ void CaptureFilterSyntaxWorker::start() {
} }
for (guint if_idx = 0; if_idx < global_capture_opts.all_ifaces->len; if_idx++) { for (guint if_idx = 0; if_idx < global_capture_opts.all_ifaces->len; if_idx++) {
interface_t device; interface_t *device;
device = g_array_index(global_capture_opts.all_ifaces, interface_t, if_idx); device = &g_array_index(global_capture_opts.all_ifaces, interface_t, if_idx);
if (!device.locked && device.selected) { if (!device->locked && device->selected) {
#ifdef HAVE_EXTCAP #ifdef HAVE_EXTCAP
if (device.if_info.extcap == NULL || strlen(device.if_info.extcap) == 0) { if (device->if_info.extcap == NULL || strlen(device->if_info.extcap) == 0) {
#endif #endif
if (device.active_dlt >= DLT_USER0 && device.active_dlt <= DLT_USER15) { if (device->active_dlt >= DLT_USER0 && device->active_dlt <= DLT_USER15) {
// Capture filter for DLT_USER is unknown // Capture filter for DLT_USER is unknown
state = SyntaxLineEdit::Deprecated; state = SyntaxLineEdit::Deprecated;
err_str = "Unable to check capture filter"; err_str = "Unable to check capture filter";
} else { } else {
active_dlts.insert(device.active_dlt); active_dlts.insert(device->active_dlt);
} }
#ifdef HAVE_EXTCAP #ifdef HAVE_EXTCAP
} else { } else {
@ -146,11 +146,11 @@ void CaptureFilterSyntaxWorker::start() {
// If it's already invalid, don't bother to check extcap // If it's already invalid, don't bother to check extcap
if (state != SyntaxLineEdit::Invalid) { if (state != SyntaxLineEdit::Invalid) {
foreach (guint extcapif, active_extcap.toList()) { foreach (guint extcapif, active_extcap.toList()) {
interface_t device; interface_t *device;
gchar *error = NULL; gchar *error = NULL;
device = g_array_index(global_capture_opts.all_ifaces, interface_t, extcapif); device = &g_array_index(global_capture_opts.all_ifaces, interface_t, extcapif);
extcap_filter_status status = extcap_verify_capture_filter(device.name, filter.toUtf8().constData(), &error); extcap_filter_status status = extcap_verify_capture_filter(device->name, filter.toUtf8().constData(), &error);
if (status == EXTCAP_FILTER_VALID) { if (status == EXTCAP_FILTER_VALID) {
DEBUG_SYNTAX_CHECK("unknown", "known good"); DEBUG_SYNTAX_CHECK("unknown", "known good");
} else if (status == EXTCAP_FILTER_INVALID) { } else if (status == EXTCAP_FILTER_INVALID) {

View File

@ -247,22 +247,16 @@ void CaptureInterfacesDialog::updateGlobalDeviceSelections()
while (*iter) { while (*iter) {
QString device_name = (*iter)->data(col_interface_, Qt::UserRole).value<QString>(); QString device_name = (*iter)->data(col_interface_, Qt::UserRole).value<QString>();
for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) { for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) {
interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); interface_t *device = &g_array_index(global_capture_opts.all_ifaces, interface_t, i);
if (device_name.compare(QString().fromUtf8(device.name)) == 0) { if (device_name.compare(QString().fromUtf8(device->name)) == 0) {
if (!device.locked) { if (!device->locked) {
if ((*iter)->isSelected()) { if ((*iter)->isSelected()) {
device.selected = TRUE; device->selected = TRUE;
global_capture_opts.num_selected++; global_capture_opts.num_selected++;
} else { } else {
device.selected = FALSE; device->selected = FALSE;
} }
device.locked = TRUE; device->locked = 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);
device.locked = 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);
} }
break; break;
} }
@ -284,10 +278,10 @@ void CaptureInterfacesDialog::updateFromGlobalDeviceSelections()
while (*iter) { while (*iter) {
QString device_name = (*iter)->data(col_interface_, Qt::UserRole).value<QString>(); QString device_name = (*iter)->data(col_interface_, Qt::UserRole).value<QString>();
for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) { for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) {
interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); interface_t *device = &g_array_index(global_capture_opts.all_ifaces, interface_t, i);
if (device_name.compare(QString().fromUtf8(device.name)) == 0) { if (device_name.compare(QString().fromUtf8(device->name)) == 0) {
if ((bool)device.selected != (*iter)->isSelected()) { if ((bool)device->selected != (*iter)->isSelected()) {
(*iter)->setSelected(device.selected); (*iter)->setSelected(device->selected);
} }
break; break;
} }

View File

@ -71,7 +71,7 @@ void CapturePreferencesFrame::showEvent(QShowEvent *)
void CapturePreferencesFrame::updateWidgets() void CapturePreferencesFrame::updateWidgets()
{ {
#ifdef HAVE_LIBPCAP #ifdef HAVE_LIBPCAP
interface_t device; interface_t *device;
QString default_device_string; QString default_device_string;
if (prefs_get_string_value(pref_device_, pref_stashed)) { if (prefs_get_string_value(pref_device_, pref_stashed)) {
@ -87,20 +87,20 @@ void CapturePreferencesFrame::updateWidgets()
wsApp->refreshLocalInterfaces(); wsApp->refreshLocalInterfaces();
} }
for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) { for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) {
device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); device = &g_array_index(global_capture_opts.all_ifaces, interface_t, i);
/* Continue if capture device is hidden */ /* Continue if capture device is hidden */
if (device.hidden) { if (device->hidden) {
continue; continue;
} }
// InterfaceTree matches against device.name when selecting the // InterfaceTree matches against device->name when selecting the
// default interface, so add it here if needed. On Windows this // default interface, so add it here if needed. On Windows this
// means that we show the user a big ugly UUID-laden device path. // means that we show the user a big ugly UUID-laden device path.
// We might be able to work around that by passing device.name as // We might be able to work around that by passing device->name as
// the userData argument to addItem instead. // the userData argument to addItem instead.
QString item_text = device.display_name; QString item_text = device->display_name;
if (!item_text.contains(device.name)) { if (!item_text.contains(device->name)) {
item_text.append(QString(" (%1)").arg(device.name)); item_text.append(QString(" (%1)").arg(device->name));
} }
ui->defaultInterfaceComboBox->addItem(item_text); ui->defaultInterfaceComboBox->addItem(item_text);
} }

View File

@ -84,12 +84,12 @@ void CompiledFilterOutput::compileFilter()
foreach (QString interfaces, intList_) { foreach (QString interfaces, intList_) {
for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) { for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) {
interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); interface_t *device = &g_array_index(global_capture_opts.all_ifaces, interface_t, i);
if (interfaces.compare(device.display_name)) { if (interfaces.compare(device->display_name)) {
continue; continue;
} else { } else {
pcap_t *pd = pcap_open_dead(device.active_dlt, WTAP_MAX_PACKET_SIZE_STANDARD); pcap_t *pd = pcap_open_dead(device->active_dlt, WTAP_MAX_PACKET_SIZE_STANDARD);
if (pd == NULL) if (pd == NULL)
break; break;
g_mutex_lock(pcap_compile_mtx); g_mutex_lock(pcap_compile_mtx);

View File

@ -83,7 +83,7 @@ ExtcapOptionsDialog::ExtcapOptionsDialog(QWidget *parent) :
ExtcapOptionsDialog * ExtcapOptionsDialog::createForDevice(QString &dev_name, QWidget *parent) ExtcapOptionsDialog * ExtcapOptionsDialog::createForDevice(QString &dev_name, QWidget *parent)
{ {
interface_t device; interface_t *device;
ExtcapOptionsDialog * resultDialog = NULL; ExtcapOptionsDialog * resultDialog = NULL;
bool dev_found = false; bool dev_found = false;
guint if_idx; guint if_idx;
@ -93,8 +93,8 @@ ExtcapOptionsDialog * ExtcapOptionsDialog::createForDevice(QString &dev_name, QW
for (if_idx = 0; if_idx < global_capture_opts.all_ifaces->len; if_idx++) for (if_idx = 0; if_idx < global_capture_opts.all_ifaces->len; if_idx++)
{ {
device = g_array_index(global_capture_opts.all_ifaces, interface_t, if_idx); device = &g_array_index(global_capture_opts.all_ifaces, interface_t, if_idx);
if (dev_name.compare(QString(device.name)) == 0 && device.if_info.type == IF_EXTCAP) if (dev_name.compare(QString(device->name)) == 0 && device->if_info.type == IF_EXTCAP)
{ {
dev_found = true; dev_found = true;
break; break;
@ -108,7 +108,7 @@ ExtcapOptionsDialog * ExtcapOptionsDialog::createForDevice(QString &dev_name, QW
resultDialog->device_name = QString(dev_name); resultDialog->device_name = QString(dev_name);
resultDialog->device_idx = if_idx; resultDialog->device_idx = if_idx;
resultDialog->setWindowTitle(wsApp->windowTitleString(tr("Interface Options") + ": " + device.display_name)); resultDialog->setWindowTitle(wsApp->windowTitleString(tr("Interface Options") + ": " + device->display_name));
resultDialog->updateWidgets(); resultDialog->updateWidgets();
@ -316,11 +316,11 @@ void ExtcapOptionsDialog::on_buttonBox_rejected()
void ExtcapOptionsDialog::on_buttonBox_helpRequested() void ExtcapOptionsDialog::on_buttonBox_helpRequested()
{ {
interface_t device; interface_t *device;
QString interface_help = NULL; QString interface_help = NULL;
device = g_array_index(global_capture_opts.all_ifaces, interface_t, device_idx); device = &g_array_index(global_capture_opts.all_ifaces, interface_t, device_idx);
interface_help = QString(extcap_get_help_for_ifname(device.name)); interface_help = QString(extcap_get_help_for_ifname(device->name));
/* The extcap interface didn't provide an help. Let's go with the default */ /* The extcap interface didn't provide an help. Let's go with the default */
if (interface_help.isEmpty()) { if (interface_help.isEmpty()) {
wsApp->helpTopicAction(HELP_EXTCAP_OPTIONS_DIALOG); wsApp->helpTopicAction(HELP_EXTCAP_OPTIONS_DIALOG);
@ -343,7 +343,7 @@ void ExtcapOptionsDialog::on_buttonBox_helpRequested()
{ {
QMessageBox::warning(this, tr("Extcap Help cannot be found"), QMessageBox::warning(this, tr("Extcap Help cannot be found"),
QString(tr("The help for the extcap interface %1 cannot be found. Given file: %2")) QString(tr("The help for the extcap interface %1 cannot be found. Given file: %2"))
.arg(device.name).arg(help_url.path()), .arg(device->name).arg(help_url.path()),
QMessageBox::Ok); QMessageBox::Ok);
} }
@ -352,11 +352,9 @@ void ExtcapOptionsDialog::on_buttonBox_helpRequested()
bool ExtcapOptionsDialog::saveOptionToCaptureInfo() bool ExtcapOptionsDialog::saveOptionToCaptureInfo()
{ {
GHashTable * ret_args; GHashTable * ret_args;
interface_t device; interface_t *device;
device = g_array_index(global_capture_opts.all_ifaces, interface_t, device_idx);
global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, device_idx);
device = &g_array_index(global_capture_opts.all_ifaces, interface_t, device_idx);
ret_args = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); ret_args = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
ExtcapArgumentList::const_iterator iter; ExtcapArgumentList::const_iterator iter;
@ -381,12 +379,9 @@ bool ExtcapOptionsDialog::saveOptionToCaptureInfo()
g_hash_table_insert(ret_args, call_string, value_string ); g_hash_table_insert(ret_args, call_string, value_string );
} }
if (device.external_cap_args_settings != NULL) if (device->external_cap_args_settings != NULL)
g_hash_table_unref(device.external_cap_args_settings); g_hash_table_unref(device->external_cap_args_settings);
device.external_cap_args_settings = ret_args; device->external_cap_args_settings = ret_args;
g_array_insert_val(global_capture_opts.all_ifaces, device_idx, device);
return true; return true;
} }

View File

@ -951,20 +951,20 @@ void InterfaceToolbar::interfaceListChanged()
for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++)
{ {
interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); interface_t *device = &g_array_index(global_capture_opts.all_ifaces, interface_t, i);
if (device.hidden) if (device->hidden)
continue; continue;
if (interface_.keys().contains(device.name)) if (interface_.keys().contains(device->name))
{ {
ui->interfacesComboBox->addItem(device.name); ui->interfacesComboBox->addItem(device->name);
if (selected_ifname.compare(device.name) == 0) if (selected_ifname.compare(device->name) == 0)
{ {
// Keep selected interface // Keep selected interface
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
ui->interfacesComboBox->setCurrentText(device.name); ui->interfacesComboBox->setCurrentText(device->name);
#else #else
int new_index = ui->interfacesComboBox->findText(device.name); int new_index = ui->interfacesComboBox->findText(device->name);
if (new_index >= 0) if (new_index >= 0)
{ {
ui->interfacesComboBox->setCurrentIndex(new_index); ui->interfacesComboBox->setCurrentIndex(new_index);

View File

@ -289,26 +289,24 @@ void MainWelcome::appInitialized()
void MainWelcome::captureFilterTextEdited(const QString capture_filter) void MainWelcome::captureFilterTextEdited(const QString capture_filter)
{ {
if (global_capture_opts.num_selected > 0) { if (global_capture_opts.num_selected > 0) {
interface_t device; interface_t *device;
for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) { for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) {
device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); device = &g_array_index(global_capture_opts.all_ifaces, interface_t, i);
if (!device.selected) { if (!device->selected) {
continue; continue;
} }
// if (device.active_dlt == -1) { // if (device->active_dlt == -1) {
// simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The link type of interface %s was not specified.", device.name); // simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The link type of interface %s was not specified.", device->name);
// continue; /* Programming error: somehow managed to select an "unsupported" entry */ // continue; /* Programming error: somehow managed to select an "unsupported" entry */
// } // }
g_array_remove_index(global_capture_opts.all_ifaces, i); g_free(device->cfilter);
g_free(device.cfilter);
if (capture_filter.isEmpty()) { if (capture_filter.isEmpty()) {
device.cfilter = NULL; device->cfilter = NULL;
} else { } else {
device.cfilter = qstring_strdup(capture_filter); device->cfilter = qstring_strdup(capture_filter);
} }
g_array_insert_val(global_capture_opts.all_ifaces, i, device); // update_filter_string(device->name, filter_text);
// update_filter_string(device.name, filter_text);
} }
} }
} }

View File

@ -458,12 +458,10 @@ void ManageInterfacesDialog::remoteAccepted()
while(*it) { while(*it) {
for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) { for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) {
interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); interface_t *device = &g_array_index(global_capture_opts.all_ifaces, interface_t, i);
if ((*it)->text(col_r_host_dev_).compare(device.name)) if ((*it)->text(col_r_host_dev_).compare(device->name))
continue; continue;
device.hidden = ((*it)->checkState(col_r_show_) == Qt::Checked ? false : true); device->hidden = ((*it)->checkState(col_r_show_) == Qt::Checked ? false : true);
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);
} }
++it; ++it;
} }
@ -481,11 +479,11 @@ void ManageInterfacesDialog::on_remoteList_itemClicked(QTreeWidgetItem *item, in
} }
for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) { for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) {
interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); interface_t *device = &g_array_index(global_capture_opts.all_ifaces, interface_t, i);
if (!device.local) { if (!device->local) {
if (item->text(col_r_host_dev_).compare(device.name)) if (item->text(col_r_host_dev_).compare(device->name))
continue; continue;
device.hidden = (item->checkState(col_r_show_) == Qt::Checked ? false : true); device->hidden = (item->checkState(col_r_show_) == Qt::Checked ? false : true);
} }
} }
} }
@ -498,8 +496,8 @@ void ManageInterfacesDialog::on_delRemote_clicked()
} }
for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) { for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) {
interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); interface_t *device = &g_array_index(global_capture_opts.all_ifaces, interface_t, i);
if (item->text(col_r_host_dev_).compare(device.remote_opts.remote_host_opts.remote_host)) if (item->text(col_r_host_dev_).compare(device->remote_opts.remote_host_opts.remote_host))
continue; continue;
global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i); global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i);
} }
@ -516,22 +514,22 @@ void ManageInterfacesDialog::on_addRemote_clicked()
void ManageInterfacesDialog::showRemoteInterfaces() void ManageInterfacesDialog::showRemoteInterfaces()
{ {
guint i; guint i;
interface_t device; interface_t *device;
QTreeWidgetItem *item = NULL; QTreeWidgetItem *item = NULL;
// We assume that remote interfaces are grouped by host. // We assume that remote interfaces are grouped by host.
for (i = 0; i < global_capture_opts.all_ifaces->len; i++) { for (i = 0; i < global_capture_opts.all_ifaces->len; i++) {
QTreeWidgetItem *child; QTreeWidgetItem *child;
device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); device = &g_array_index(global_capture_opts.all_ifaces, interface_t, i);
if (!device.local) { if (!device->local) {
if (!item || item->text(col_r_host_dev_).compare(device.remote_opts.remote_host_opts.remote_host) != 0) { if (!item || item->text(col_r_host_dev_).compare(device->remote_opts.remote_host_opts.remote_host) != 0) {
item = new QTreeWidgetItem(ui->remoteList); item = new QTreeWidgetItem(ui->remoteList);
item->setText(col_r_host_dev_, device.remote_opts.remote_host_opts.remote_host); item->setText(col_r_host_dev_, device->remote_opts.remote_host_opts.remote_host);
item->setExpanded(true); item->setExpanded(true);
} }
child = new QTreeWidgetItem(item); child = new QTreeWidgetItem(item);
child->setCheckState(col_r_show_, device.hidden ? Qt::Unchecked : Qt::Checked); child->setCheckState(col_r_show_, device->hidden ? Qt::Unchecked : Qt::Checked);
child->setText(col_r_host_dev_, QString(device.name)); child->setText(col_r_host_dev_, QString(device->name));
} }
} }
} }
@ -539,19 +537,19 @@ void ManageInterfacesDialog::showRemoteInterfaces()
void ManageInterfacesDialog::on_remoteSettings_clicked() void ManageInterfacesDialog::on_remoteSettings_clicked()
{ {
guint i = 0; guint i = 0;
interface_t device; interface_t *device;
QTreeWidgetItem* item = ui->remoteList->currentItem(); QTreeWidgetItem* item = ui->remoteList->currentItem();
if (!item) { if (!item) {
return; return;
} }
for (i = 0; i < global_capture_opts.all_ifaces->len; 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 = &g_array_index(global_capture_opts.all_ifaces, interface_t, i);
if (!device.local) { if (!device->local) {
if (item->text(col_r_host_dev_).compare(device.name)) { if (item->text(col_r_host_dev_).compare(device->name)) {
continue; continue;
} else { } else {
RemoteSettingsDialog *dlg = new RemoteSettingsDialog(this, &device); RemoteSettingsDialog *dlg = new RemoteSettingsDialog(this, device);
dlg->show(); dlg->show();
break; break;
} }
@ -562,19 +560,17 @@ void ManageInterfacesDialog::on_remoteSettings_clicked()
void ManageInterfacesDialog::setRemoteSettings(interface_t *iface) void ManageInterfacesDialog::setRemoteSettings(interface_t *iface)
{ {
for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) { for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) {
interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); interface_t *device = &g_array_index(global_capture_opts.all_ifaces, interface_t, i);
if (!device.local) { if (!device->local) {
if (strcmp(iface->name, device.name)) { if (strcmp(iface->name, device->name)) {
continue; continue;
} }
device.remote_opts.remote_host_opts.nocap_rpcap = iface->remote_opts.remote_host_opts.nocap_rpcap; device->remote_opts.remote_host_opts.nocap_rpcap = iface->remote_opts.remote_host_opts.nocap_rpcap;
device.remote_opts.remote_host_opts.datatx_udp = iface->remote_opts.remote_host_opts.datatx_udp; device->remote_opts.remote_host_opts.datatx_udp = iface->remote_opts.remote_host_opts.datatx_udp;
#ifdef HAVE_PCAP_SETSAMPLING #ifdef HAVE_PCAP_SETSAMPLING
device.remote_opts.sampling_method = iface->remote_opts.sampling_method; device->remote_opts.sampling_method = iface->remote_opts.sampling_method;
device.remote_opts.sampling_param = iface->remote_opts.sampling_param; device->remote_opts.sampling_param = iface->remote_opts.sampling_param;
#endif //HAVE_PCAP_SETSAMPLING #endif //HAVE_PCAP_SETSAMPLING
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);
} }
} }
} }

View File

@ -160,9 +160,9 @@ void InterfaceTreeCacheModel::save()
for(unsigned int idx = 0; idx < global_capture_opts.all_ifaces->len; idx++) for(unsigned int idx = 0; idx < global_capture_opts.all_ifaces->len; idx++)
{ {
interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, idx); interface_t *device = &g_array_index(global_capture_opts.all_ifaces, interface_t, idx);
if (! device.name ) if (! device->name )
continue; continue;
/* Try to load a saved value row for this index */ /* Try to load a saved value row for this index */
@ -184,10 +184,10 @@ void InterfaceTreeCacheModel::save()
if ( col == IFTREE_COL_HIDDEN ) if ( col == IFTREE_COL_HIDDEN )
{ {
device.hidden = saveValue.toBool(); device->hidden = saveValue.toBool();
} }
#ifdef HAVE_EXTCAP #ifdef HAVE_EXTCAP
else if ( device.if_info.type == IF_EXTCAP ) else if ( device->if_info.type == IF_EXTCAP )
{ {
/* extcap interfaces do not have the following columns. /* extcap interfaces do not have the following columns.
* ATTENTION: all generic columns must be added, BEFORE this * ATTENTION: all generic columns must be added, BEFORE this
@ -196,12 +196,12 @@ void InterfaceTreeCacheModel::save()
#endif #endif
else if ( col == IFTREE_COL_PROMISCUOUSMODE ) else if ( col == IFTREE_COL_PROMISCUOUSMODE )
{ {
device.pmode = saveValue.toBool(); device->pmode = saveValue.toBool();
} }
#ifdef HAVE_PCAP_CREATE #ifdef HAVE_PCAP_CREATE
else if ( col == IFTREE_COL_MONITOR_MODE ) else if ( col == IFTREE_COL_MONITOR_MODE )
{ {
device.monitor_mode_enabled = saveValue.toBool(); device->monitor_mode_enabled = saveValue.toBool();
} }
#endif #endif
else if ( col == IFTREE_COL_SNAPLEN ) else if ( col == IFTREE_COL_SNAPLEN )
@ -209,40 +209,36 @@ void InterfaceTreeCacheModel::save()
int iVal = saveValue.toInt(); int iVal = saveValue.toInt();
if ( iVal != WTAP_MAX_PACKET_SIZE_STANDARD ) if ( iVal != WTAP_MAX_PACKET_SIZE_STANDARD )
{ {
device.has_snaplen = true; device->has_snaplen = true;
device.snaplen = iVal; device->snaplen = iVal;
} }
else else
{ {
device.has_snaplen = false; device->has_snaplen = false;
device.snaplen = WTAP_MAX_PACKET_SIZE_STANDARD; device->snaplen = WTAP_MAX_PACKET_SIZE_STANDARD;
} }
} }
#ifdef CAN_SET_CAPTURE_BUFFER_SIZE #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
else if ( col == IFTREE_COL_BUFFERLEN ) else if ( col == IFTREE_COL_BUFFERLEN )
{ {
device.buffer = saveValue.toInt(); device->buffer = saveValue.toInt();
} }
#endif #endif
global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, idx);
g_array_insert_val(global_capture_opts.all_ifaces, idx, device);
++it; ++it;
} }
} }
QVariant content = getColumnContent(idx, IFTREE_COL_HIDDEN, Qt::CheckStateRole); QVariant content = getColumnContent(idx, IFTREE_COL_HIDDEN, Qt::CheckStateRole);
if ( content.isValid() && static_cast<Qt::CheckState>(content.toInt()) == Qt::Unchecked ) if ( content.isValid() && static_cast<Qt::CheckState>(content.toInt()) == Qt::Unchecked )
prefStorage[&prefs.capture_devices_hide] << QString(device.name); prefStorage[&prefs.capture_devices_hide] << QString(device->name);
content = getColumnContent(idx, IFTREE_COL_INTERFACE_COMMENT); content = getColumnContent(idx, IFTREE_COL_INTERFACE_COMMENT);
if ( content.isValid() && content.toString().size() > 0 ) if ( content.isValid() && content.toString().size() > 0 )
prefStorage[&prefs.capture_devices_descr] << QString("%1(%2)").arg(device.name).arg(content.toString()); prefStorage[&prefs.capture_devices_descr] << QString("%1(%2)").arg(device->name).arg(content.toString());
bool allowExtendedColumns = true; bool allowExtendedColumns = true;
#ifdef HAVE_EXTCAP #ifdef HAVE_EXTCAP
if ( device.if_info.type == IF_EXTCAP ) if ( device->if_info.type == IF_EXTCAP )
allowExtendedColumns = false; allowExtendedColumns = false;
#endif #endif
if ( allowExtendedColumns ) if ( allowExtendedColumns )
@ -251,13 +247,13 @@ void InterfaceTreeCacheModel::save()
if ( content.isValid() ) if ( content.isValid() )
{ {
bool value = static_cast<Qt::CheckState>(content.toInt()) == Qt::Checked; bool value = static_cast<Qt::CheckState>(content.toInt()) == Qt::Checked;
prefStorage[&prefs.capture_devices_pmode] << QString("%1(%2)").arg(device.name).arg(value ? 1 : 0); prefStorage[&prefs.capture_devices_pmode] << QString("%1(%2)").arg(device->name).arg(value ? 1 : 0);
} }
#ifdef HAVE_PCAP_CREATE #ifdef HAVE_PCAP_CREATE
content = getColumnContent(idx, IFTREE_COL_MONITOR_MODE, Qt::CheckStateRole); content = getColumnContent(idx, IFTREE_COL_MONITOR_MODE, Qt::CheckStateRole);
if ( content.isValid() && static_cast<Qt::CheckState>(content.toInt()) == Qt::Checked ) if ( content.isValid() && static_cast<Qt::CheckState>(content.toInt()) == Qt::Checked )
prefStorage[&prefs.capture_devices_monitor_mode] << QString(device.name); prefStorage[&prefs.capture_devices_monitor_mode] << QString(device->name);
#endif #endif
content = getColumnContent(idx, IFTREE_COL_SNAPLEN); content = getColumnContent(idx, IFTREE_COL_SNAPLEN);
@ -265,9 +261,9 @@ void InterfaceTreeCacheModel::save()
{ {
int value = content.toInt(); int value = content.toInt();
prefStorage[&prefs.capture_devices_snaplen] << prefStorage[&prefs.capture_devices_snaplen] <<
QString("%1:%2(%3)").arg(device.name). QString("%1:%2(%3)").arg(device->name).
arg(device.has_snaplen ? 1 : 0). arg(device->has_snaplen ? 1 : 0).
arg(device.has_snaplen ? value : WTAP_MAX_PACKET_SIZE_STANDARD); arg(device->has_snaplen ? value : WTAP_MAX_PACKET_SIZE_STANDARD);
} }
#ifdef CAN_SET_CAPTURE_BUFFER_SIZE #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
@ -278,7 +274,7 @@ void InterfaceTreeCacheModel::save()
if ( value != -1 ) if ( value != -1 )
{ {
prefStorage[&prefs.capture_devices_buffersize] << prefStorage[&prefs.capture_devices_buffersize] <<
QString("%1(%2)").arg(device.name). QString("%1(%2)").arg(device->name).
arg(value); arg(value);
} }
} }

View File

@ -121,7 +121,7 @@ QVariant InterfaceTreeModel::data(const QModelIndex &index, int role) const
if ( interfacesLoaded ) if ( interfacesLoaded )
{ {
interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, row); interface_t *device = &g_array_index(global_capture_opts.all_ifaces, interface_t, row);
/* Data for display in cell */ /* Data for display in cell */
if ( role == Qt::DisplayRole ) if ( role == Qt::DisplayRole )
@ -129,55 +129,55 @@ QVariant InterfaceTreeModel::data(const QModelIndex &index, int role) const
/* Only the name is being displayed */ /* Only the name is being displayed */
if ( col == IFTREE_COL_NAME ) if ( col == IFTREE_COL_NAME )
{ {
return QString(device.display_name); return QString(device->display_name);
} }
else if ( col == IFTREE_COL_INTERFACE_NAME ) else if ( col == IFTREE_COL_INTERFACE_NAME )
{ {
return QString(device.name); return QString(device->name);
} }
else if ( col == IFTREE_COL_PIPE_PATH ) else if ( col == IFTREE_COL_PIPE_PATH )
{ {
return QString(device.if_info.name); return QString(device->if_info.name);
} }
else if ( col == IFTREE_COL_CAPTURE_FILTER ) else if ( col == IFTREE_COL_CAPTURE_FILTER )
{ {
if ( device.cfilter && strlen(device.cfilter) > 0 ) if ( device->cfilter && strlen(device->cfilter) > 0 )
return html_escape(QString(device.cfilter)); return html_escape(QString(device->cfilter));
} }
#ifdef HAVE_EXTCAP #ifdef HAVE_EXTCAP
else if ( col == IFTREE_COL_EXTCAP_PATH ) else if ( col == IFTREE_COL_EXTCAP_PATH )
{ {
return QString(device.if_info.extcap); return QString(device->if_info.extcap);
} }
#endif #endif
else if ( col == IFTREE_COL_SNAPLEN ) else if ( col == IFTREE_COL_SNAPLEN )
{ {
return device.has_snaplen ? QString::number(device.snaplen) : DefaultNumericValue; return device->has_snaplen ? QString::number(device->snaplen) : DefaultNumericValue;
} }
#ifdef CAN_SET_CAPTURE_BUFFER_SIZE #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
else if ( col == IFTREE_COL_BUFFERLEN ) else if ( col == IFTREE_COL_BUFFERLEN )
{ {
return QString::number(device.buffer); return QString::number(device->buffer);
} }
#endif #endif
else if ( col == IFTREE_COL_TYPE ) else if ( col == IFTREE_COL_TYPE )
{ {
return QVariant::fromValue((int)device.if_info.type); return QVariant::fromValue((int)device->if_info.type);
} }
else if ( col == IFTREE_COL_INTERFACE_COMMENT ) else if ( col == IFTREE_COL_INTERFACE_COMMENT )
{ {
QString comment = gchar_free_to_qstring(capture_dev_user_descr_find(device.name)); QString comment = gchar_free_to_qstring(capture_dev_user_descr_find(device->name));
if ( comment.length() > 0 ) if ( comment.length() > 0 )
return comment; return comment;
else else
return QString(device.if_info.vendor_description); return QString(device->if_info.vendor_description);
} }
else if ( col == IFTREE_COL_DLT ) else if ( col == IFTREE_COL_DLT )
{ {
QString linkname = QObject::tr("DLT %1").arg(device.active_dlt); QString linkname = QObject::tr("DLT %1").arg(device->active_dlt);
for (GList *list = device.links; list != NULL; list = g_list_next(list)) { for (GList *list = device->links; list != NULL; list = g_list_next(list)) {
link_row *linkr = (link_row*)(list->data); link_row *linkr = (link_row*)(list->data);
if (linkr->dlt != -1 && linkr->dlt == device.active_dlt) { if (linkr->dlt != -1 && linkr->dlt == device->active_dlt) {
linkname = linkr->name; linkname = linkr->name;
break; break;
} }
@ -196,16 +196,16 @@ QVariant InterfaceTreeModel::data(const QModelIndex &index, int role) const
if ( col == IFTREE_COL_HIDDEN ) if ( col == IFTREE_COL_HIDDEN )
{ {
/* Hidden is a de-selection, therefore inverted logic here */ /* Hidden is a de-selection, therefore inverted logic here */
return device.hidden ? Qt::Unchecked : Qt::Checked; return device->hidden ? Qt::Unchecked : Qt::Checked;
} }
else if ( col == IFTREE_COL_PROMISCUOUSMODE ) else if ( col == IFTREE_COL_PROMISCUOUSMODE )
{ {
return device.pmode ? Qt::Checked : Qt::Unchecked; return device->pmode ? Qt::Checked : Qt::Unchecked;
} }
#ifdef HAVE_PCAP_CREATE #ifdef HAVE_PCAP_CREATE
else if ( col == IFTREE_COL_MONITOR_MODE ) else if ( col == IFTREE_COL_MONITOR_MODE )
{ {
return device.monitor_mode_enabled ? Qt::Checked : Qt::Unchecked; return device->monitor_mode_enabled ? Qt::Checked : Qt::Unchecked;
} }
#endif #endif
} }
@ -214,12 +214,12 @@ QVariant InterfaceTreeModel::data(const QModelIndex &index, int role) const
{ {
if ( col == IFTREE_COL_STATS ) if ( col == IFTREE_COL_STATS )
{ {
if ( points.contains(device.name) ) if ( points.contains(device->name) )
return qVariantFromValue(points[device.name]); return qVariantFromValue(points[device->name]);
} }
else if ( col == IFTREE_COL_HIDDEN ) else if ( col == IFTREE_COL_HIDDEN )
{ {
return QVariant::fromValue((bool)device.hidden); return QVariant::fromValue((bool)device->hidden);
} }
} }
#ifdef HAVE_EXTCAP #ifdef HAVE_EXTCAP
@ -228,7 +228,7 @@ QVariant InterfaceTreeModel::data(const QModelIndex &index, int role) const
{ {
if ( col == IFTREE_COL_EXTCAP ) if ( col == IFTREE_COL_EXTCAP )
{ {
if ( device.if_info.type == IF_EXTCAP ) if ( device->if_info.type == IF_EXTCAP )
return QIcon(StockIcon("x-capture-options")); return QIcon(StockIcon("x-capture-options"));
} }
} }
@ -322,8 +322,8 @@ QVariant InterfaceTreeModel::getColumnContent(int idx, int col, int role)
#ifdef HAVE_PCAP_REMOTE #ifdef HAVE_PCAP_REMOTE
bool InterfaceTreeModel::isRemote(int idx) bool InterfaceTreeModel::isRemote(int idx)
{ {
interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, idx); interface_t *device = &g_array_index(global_capture_opts.all_ifaces, interface_t, idx);
if ( device.remote_opts.src_type == CAPTURE_IFREMOTE ) if ( device->remote_opts.src_type == CAPTURE_IFREMOTE )
return true; return true;
return false; return false;
} }
@ -352,20 +352,20 @@ QVariant InterfaceTreeModel::toolTipForInterface(int idx) const
if ( ! global_capture_opts.all_ifaces || global_capture_opts.all_ifaces->len <= (guint) idx) if ( ! global_capture_opts.all_ifaces || global_capture_opts.all_ifaces->len <= (guint) idx)
return QVariant(); return QVariant();
interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, idx); interface_t *device = &g_array_index(global_capture_opts.all_ifaces, interface_t, idx);
QString tt_str = "<p>"; QString tt_str = "<p>";
if ( device.no_addresses > 0 ) if ( device->no_addresses > 0 )
{ {
tt_str += QString("%1: %2") tt_str += QString("%1: %2")
.arg(device.no_addresses > 1 ? tr("Addresses") : tr("Address")) .arg(device->no_addresses > 1 ? tr("Addresses") : tr("Address"))
.arg(html_escape(device.addresses)) .arg(html_escape(device->addresses))
.replace('\n', ", "); .replace('\n', ", ");
} }
#ifdef HAVE_EXTCAP #ifdef HAVE_EXTCAP
else if ( device.if_info.type == IF_EXTCAP ) else if ( device->if_info.type == IF_EXTCAP )
{ {
tt_str = QString(tr("Extcap interface: %1")).arg(get_basename(device.if_info.extcap)); tt_str = QString(tr("Extcap interface: %1")).arg(get_basename(device->if_info.extcap));
} }
#endif #endif
else else
@ -374,7 +374,7 @@ QVariant InterfaceTreeModel::toolTipForInterface(int idx) const
} }
tt_str += "<br/>"; tt_str += "<br/>";
QString cfilter = device.cfilter; QString cfilter = device->cfilter;
if ( cfilter.isEmpty() ) if ( cfilter.isEmpty() )
{ {
tt_str += tr("No capture filter"); tt_str += tr("No capture filter");
@ -413,9 +413,9 @@ void InterfaceTreeModel::updateStatistic(unsigned int idx)
if ( ! global_capture_opts.all_ifaces || global_capture_opts.all_ifaces->len <= (guint) idx ) if ( ! global_capture_opts.all_ifaces || global_capture_opts.all_ifaces->len <= (guint) idx )
return; return;
interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, idx); interface_t *device = &g_array_index(global_capture_opts.all_ifaces, interface_t, idx);
if ( device.if_info.type == IF_PIPE ) if ( device->if_info.type == IF_PIPE )
return; return;
if ( !stat_cache_ ) if ( !stat_cache_ )
@ -430,20 +430,17 @@ void InterfaceTreeModel::updateStatistic(unsigned int idx)
struct pcap_stat stats; struct pcap_stat stats;
diff = 0; diff = 0;
if ( capture_stats(stat_cache_, device.name, &stats) ) if ( capture_stats(stat_cache_, device->name, &stats) )
{ {
if ( (int)(stats.ps_recv - device.last_packets) >= 0 ) if ( (int)(stats.ps_recv - device->last_packets) >= 0 )
{ {
diff = stats.ps_recv - device.last_packets; diff = stats.ps_recv - device->last_packets;
device.packet_diff = diff; device->packet_diff = diff;
} }
device.last_packets = stats.ps_recv; device->last_packets = stats.ps_recv;
global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, idx);
g_array_insert_val(global_capture_opts.all_ifaces, idx, device);
} }
points[device.name].append(diff); points[device->name].append(diff);
emit dataChanged(index(idx, IFTREE_COL_STATS), index(idx, IFTREE_COL_STATS)); emit dataChanged(index(idx, IFTREE_COL_STATS), index(idx, IFTREE_COL_STATS));
#else #else
Q_UNUSED(idx) Q_UNUSED(idx)
@ -456,9 +453,9 @@ void InterfaceTreeModel::getPoints(int idx, PointList *pts)
if ( ! global_capture_opts.all_ifaces || global_capture_opts.all_ifaces->len <= (guint) idx ) if ( ! global_capture_opts.all_ifaces || global_capture_opts.all_ifaces->len <= (guint) idx )
return; return;
interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, idx); interface_t *device = &g_array_index(global_capture_opts.all_ifaces, interface_t, idx);
if ( points.contains(device.name) ) if ( points.contains(device->name) )
pts->append(points[device.name]); pts->append(points[device->name]);
#else #else
Q_UNUSED(idx) Q_UNUSED(idx)
Q_UNUSED(pts) Q_UNUSED(pts)
@ -471,9 +468,9 @@ QItemSelection InterfaceTreeModel::selectedDevices()
#ifdef HAVE_LIBPCAP #ifdef HAVE_LIBPCAP
for( int idx = 0; idx < rowCount(); idx++ ) for( int idx = 0; idx < rowCount(); idx++ )
{ {
interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, idx); interface_t *device = &g_array_index(global_capture_opts.all_ifaces, interface_t, idx);
if ( device.selected ) if ( device->selected )
{ {
QModelIndex selectIndex = index(idx, 0); QModelIndex selectIndex = index(idx, 0);
mySelection.merge( mySelection.merge(
@ -514,27 +511,21 @@ bool InterfaceTreeModel::updateSelectedDevices(QItemSelection sourceSelection)
for ( unsigned int idx = 0; idx < global_capture_opts.all_ifaces->len; idx++ ) for ( unsigned int idx = 0; idx < global_capture_opts.all_ifaces->len; idx++ )
{ {
interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, idx); interface_t *device = &g_array_index(global_capture_opts.all_ifaces, interface_t, idx);
if ( !device.locked ) if ( !device->locked )
{ {
if ( selectedIndices.contains(idx) ) if ( selectedIndices.contains(idx) )
{ {
if (! device.selected ) if (! device->selected )
selectionHasChanged = true; selectionHasChanged = true;
device.selected = TRUE; device->selected = TRUE;
global_capture_opts.num_selected++; global_capture_opts.num_selected++;
} else { } else {
if ( device.selected ) if ( device->selected )
selectionHasChanged = true; selectionHasChanged = true;
device.selected = FALSE; device->selected = FALSE;
} }
device.locked = TRUE; device->locked = FALSE;
global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, idx);
g_array_insert_val(global_capture_opts.all_ifaces, idx, device);
device.locked = FALSE;
global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, idx);
g_array_insert_val(global_capture_opts.all_ifaces, idx, device);
} }
} }
#else #else

View File

@ -256,13 +256,13 @@ QPair<const QString, bool> CaptureFilterEdit::getSelectedFilter()
int selected_devices = 0; int selected_devices = 0;
for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) { for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) {
interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); interface_t *device = &g_array_index(global_capture_opts.all_ifaces, interface_t, i);
if (device.selected) { if (device->selected) {
selected_devices++; selected_devices++;
if (selected_devices == 1) { if (selected_devices == 1) {
user_filter = device.cfilter; user_filter = device->cfilter;
} else { } else {
if (user_filter.compare(device.cfilter)) { if (user_filter.compare(device->cfilter)) {
filter_conflict = true; filter_conflict = true;
} }
} }

View File

@ -1026,12 +1026,12 @@ iface_mon_event_cb(const char *iface, int up)
{ {
int present = 0; int present = 0;
guint ifs, j; guint ifs, j;
interface_t device; interface_t *device;
interface_options interface_opts; interface_options interface_opts;
for (ifs = 0; ifs < global_capture_opts.all_ifaces->len; ifs++) { for (ifs = 0; ifs < global_capture_opts.all_ifaces->len; ifs++) {
device = g_array_index(global_capture_opts.all_ifaces, interface_t, ifs); device = &g_array_index(global_capture_opts.all_ifaces, interface_t, ifs);
if (strcmp(device.name, iface) == 0) { if (strcmp(device->name, iface) == 0) {
present = 1; present = 1;
if (!up) { if (!up) {
/* /*
@ -1041,7 +1041,7 @@ iface_mon_event_cb(const char *iface, int up)
*/ */
for (j = 0; j < global_capture_opts.ifaces->len; j++) { for (j = 0; j < global_capture_opts.ifaces->len; j++) {
interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, j); interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, j);
if (strcmp(interface_opts.name, device.name) == 0) { if (strcmp(interface_opts.name, device->name) == 0) {
g_array_remove_index(global_capture_opts.ifaces, j); g_array_remove_index(global_capture_opts.ifaces, j);
} }
} }

View File

@ -737,15 +737,15 @@ int main(int argc, char *qt_argv[])
/* Get the list of link-layer types for the capture devices. */ /* Get the list of link-layer types for the capture devices. */
if_capabilities_t *caps; if_capabilities_t *caps;
guint i; guint i;
interface_t device; interface_t *device;
for (i = 0; i < global_capture_opts.all_ifaces->len; i++) { for (i = 0; i < global_capture_opts.all_ifaces->len; i++) {
int if_caps_queries = caps_queries; int if_caps_queries = caps_queries;
device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); device = &g_array_index(global_capture_opts.all_ifaces, interface_t, i);
if (device.selected) { if (device->selected) {
#if defined(HAVE_PCAP_CREATE) #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 #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 #endif
if (caps == NULL) { if (caps == NULL) {
cmdarg_err("%s", err_str); cmdarg_err("%s", err_str);
@ -754,7 +754,7 @@ int main(int argc, char *qt_argv[])
goto clean_exit; goto clean_exit;
} }
if (caps->data_link_types == NULL) { 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; ret_val = INVALID_LINK_TYPE;
goto clean_exit; goto clean_exit;
} }
@ -762,10 +762,10 @@ int main(int argc, char *qt_argv[])
create_console(); create_console();
#endif /* _WIN32 */ #endif /* _WIN32 */
#if defined(HAVE_PCAP_CREATE) #if defined(HAVE_PCAP_CREATE)
if (device.monitor_mode_supported) if (device->monitor_mode_supported)
if_caps_queries |= CAPS_MONITOR_MODE; if_caps_queries |= CAPS_MONITOR_MODE;
#endif #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 #ifdef _WIN32
destroy_console(); destroy_console();
#endif /* _WIN32 */ #endif /* _WIN32 */
@ -794,14 +794,12 @@ int main(int argc, char *qt_argv[])
if ((global_capture_opts.num_selected == 0) && if ((global_capture_opts.num_selected == 0) &&
(prefs.capture_device != NULL)) { (prefs.capture_device != NULL)) {
guint i; guint i;
interface_t device; interface_t *device;
for (i = 0; i < global_capture_opts.all_ifaces->len; 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 = &g_array_index(global_capture_opts.all_ifaces, interface_t, i);
if (!device.hidden && strcmp(device.display_name, prefs.capture_device) == 0) { if (!device->hidden && strcmp(device->display_name, prefs.capture_device) == 0) {
device.selected = TRUE; device->selected = TRUE;
global_capture_opts.num_selected++; 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; break;
} }
} }