2014-06-24 09:36:51 +00:00
|
|
|
/* manage_interfaces_dialog.cpp
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include "manage_interfaces_dialog.h"
|
2015-06-25 16:17:03 +00:00
|
|
|
#include <ui_manage_interfaces_dialog.h>
|
2014-06-24 09:36:51 +00:00
|
|
|
#include "epan/prefs.h"
|
2014-08-04 11:57:17 +00:00
|
|
|
#include "epan/to_str.h"
|
2014-06-24 09:36:51 +00:00
|
|
|
#include "ui/last_open_dir.h"
|
|
|
|
#include "capture_opts.h"
|
|
|
|
#include "ui/capture_globals.h"
|
|
|
|
#include "ui/qt/capture_interfaces_dialog.h"
|
2014-08-04 11:57:17 +00:00
|
|
|
#ifdef HAVE_PCAP_REMOTE
|
|
|
|
#include "ui/qt/remote_capture_dialog.h"
|
|
|
|
#include "ui/qt/remote_settings_dialog.h"
|
|
|
|
#endif
|
2014-06-24 09:36:51 +00:00
|
|
|
#include "ui/iface_lists.h"
|
|
|
|
#include "ui/preference_utils.h"
|
2014-08-04 11:57:17 +00:00
|
|
|
#include "ui/ui_util.h"
|
2015-10-04 17:10:29 +00:00
|
|
|
#include <wsutil/utf8_entities.h>
|
2014-06-24 09:36:51 +00:00
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
#include "qt_ui_utils.h"
|
|
|
|
|
|
|
|
#include "wireshark_application.h"
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
2014-06-24 09:36:51 +00:00
|
|
|
#ifdef HAVE_LIBPCAP
|
2014-08-14 20:20:09 +00:00
|
|
|
#include <QCheckBox>
|
2014-06-24 09:36:51 +00:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QHBoxLayout>
|
2015-02-08 20:24:19 +00:00
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QStandardItemModel>
|
2014-08-14 20:20:09 +00:00
|
|
|
#include <QTreeWidgetItemIterator>
|
|
|
|
|
|
|
|
// To do:
|
|
|
|
// - Check the validity of pipes and remote interfaces and provide feedback
|
|
|
|
// via hintLabel.
|
|
|
|
// - We might want to move PathChooserDelegate to its own module and use it in
|
|
|
|
// other parts of the application such as the general preferences and UATs.
|
|
|
|
// Qt Creator has a much more elaborate version from which we might want
|
|
|
|
// to draw inspiration.
|
2014-06-24 09:36:51 +00:00
|
|
|
|
2014-08-06 21:50:48 +00:00
|
|
|
enum {
|
|
|
|
col_p_pipe_
|
|
|
|
};
|
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
col_l_show_,
|
|
|
|
col_l_friendly_name_,
|
|
|
|
col_l_local_name_,
|
2014-10-04 15:21:53 +00:00
|
|
|
col_l_comment_
|
2014-08-14 20:20:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
col_r_show_,
|
2014-10-04 15:21:53 +00:00
|
|
|
col_r_host_dev_
|
2014-08-14 20:20:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
tab_local_,
|
|
|
|
tab_pipe_,
|
|
|
|
tab_remote_
|
|
|
|
};
|
|
|
|
|
2014-06-24 09:36:51 +00:00
|
|
|
ManageInterfacesDialog::ManageInterfacesDialog(QWidget *parent) :
|
2016-02-28 18:23:20 +00:00
|
|
|
GeometryStateDialog(parent),
|
2014-06-24 09:36:51 +00:00
|
|
|
ui(new Ui::ManageInterfacesDialog)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2016-02-28 18:23:20 +00:00
|
|
|
loadGeometry();
|
2014-06-24 09:36:51 +00:00
|
|
|
|
|
|
|
#ifdef Q_OS_MAC
|
2014-08-14 20:20:09 +00:00
|
|
|
ui->addPipe->setAttribute(Qt::WA_MacSmallSize, true);
|
|
|
|
ui->addPipe->setAttribute(Qt::WA_MacSmallSize, true);
|
|
|
|
ui->addRemote->setAttribute(Qt::WA_MacSmallSize, true);
|
|
|
|
ui->delRemote->setAttribute(Qt::WA_MacSmallSize, true);
|
2014-06-24 09:36:51 +00:00
|
|
|
#endif
|
2014-08-14 20:20:09 +00:00
|
|
|
|
|
|
|
int one_em = fontMetrics().height();
|
|
|
|
|
|
|
|
ui->localList->setColumnWidth(col_l_show_, one_em * 3);
|
|
|
|
#ifndef Q_OS_WIN
|
|
|
|
ui->localList->setColumnHidden(col_l_friendly_name_, true);
|
2014-08-04 11:57:17 +00:00
|
|
|
#endif
|
2016-02-19 18:47:16 +00:00
|
|
|
ui->localList->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
2014-08-14 20:20:09 +00:00
|
|
|
|
|
|
|
ui->pipeList->setItemDelegateForColumn(col_p_pipe_, &new_pipe_item_delegate_);
|
|
|
|
new_pipe_item_delegate_.setTree(ui->pipeList);
|
|
|
|
|
|
|
|
showPipes();
|
2014-06-24 09:36:51 +00:00
|
|
|
showLocalInterfaces();
|
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
#if defined(HAVE_PCAP_REMOTE)
|
|
|
|
// The default indentation (20) means our checkboxes are shifted too far on Windows.
|
|
|
|
// Assume that our disclosure and checkbox controls are square, or at least fit within an em.
|
|
|
|
ui->remoteList->setIndentation(one_em);
|
|
|
|
ui->remoteList->setColumnWidth(col_r_show_, one_em * 4);
|
2014-08-04 11:57:17 +00:00
|
|
|
ui->remoteSettings->setEnabled(false);
|
|
|
|
showRemoteInterfaces();
|
2014-08-14 20:20:09 +00:00
|
|
|
#else
|
|
|
|
ui->remoteTab->setEnabled(false);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
connect(ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateWidgets()));
|
|
|
|
connect(this, SIGNAL(ifsChanged()), parent, SIGNAL(ifsChanged()));
|
2016-02-19 18:47:16 +00:00
|
|
|
connect(ui->localList, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(localListItemDoubleClicked(QTreeWidgetItem *, int)));
|
2014-08-14 20:20:09 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_PCAP_REMOTE
|
|
|
|
connect(this, SIGNAL(remoteAdded(GList*, remote_options*)), this, SLOT(addRemoteInterfaces(GList*, remote_options*)));
|
|
|
|
connect(this, SIGNAL(remoteSettingsChanged(interface_t *)), this, SLOT(setRemoteSettings(interface_t *)));
|
2014-08-04 11:57:17 +00:00
|
|
|
connect(ui->remoteList, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(remoteSelectionChanged(QTreeWidgetItem*, int)));
|
2014-06-24 09:36:51 +00:00
|
|
|
#endif
|
2014-08-14 20:20:09 +00:00
|
|
|
|
|
|
|
ui->tabWidget->setCurrentIndex(tab_local_);
|
|
|
|
updateWidgets();
|
2014-06-24 09:36:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ManageInterfacesDialog::~ManageInterfacesDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
void ManageInterfacesDialog::updateWidgets()
|
|
|
|
{
|
|
|
|
QString hint;
|
|
|
|
|
|
|
|
if (ui->pipeList->selectedItems().length() > 0) {
|
|
|
|
ui->delPipe->setEnabled(true);
|
|
|
|
} else {
|
|
|
|
ui->delPipe->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_PCAP_REMOTE
|
|
|
|
bool enable_del_remote = false;
|
|
|
|
bool enable_remote_settings = false;
|
|
|
|
QTreeWidgetItem *item = ui->remoteList->currentItem();
|
|
|
|
|
|
|
|
if (item) {
|
|
|
|
if (item->childCount() < 1) { // Leaf
|
|
|
|
enable_remote_settings = true;
|
|
|
|
} else {
|
|
|
|
enable_del_remote = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ui->delRemote->setEnabled(enable_del_remote);
|
|
|
|
ui->remoteSettings->setEnabled(enable_remote_settings);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
switch (ui->tabWidget->currentIndex()) {
|
|
|
|
case tab_pipe_:
|
|
|
|
hint = tr("This version of Wireshark does not save pipe settings.");
|
|
|
|
break;
|
|
|
|
case tab_remote_:
|
|
|
|
#ifdef HAVE_PCAP_REMOTE
|
|
|
|
hint = tr("This version of Wireshark does not save remote settings.");
|
|
|
|
#else
|
|
|
|
hint = tr("This version of Wireshark does not support remote interfaces.");
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
hint.prepend("<small><i>");
|
|
|
|
hint.append("</i></small>");
|
|
|
|
ui->hintLabel->setText(hint);
|
|
|
|
}
|
2014-06-24 09:36:51 +00:00
|
|
|
|
|
|
|
void ManageInterfacesDialog::showPipes()
|
|
|
|
{
|
2014-08-14 20:20:09 +00:00
|
|
|
ui->pipeList->clear();
|
2014-06-24 09:36:51 +00:00
|
|
|
|
|
|
|
if (global_capture_opts.all_ifaces->len > 0) {
|
|
|
|
interface_t device;
|
|
|
|
|
|
|
|
for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) {
|
|
|
|
device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
|
|
|
|
|
|
|
|
/* Continue if capture device is hidden */
|
|
|
|
if (device.hidden || device.type != IF_PIPE) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-08-14 20:20:09 +00:00
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem(ui->pipeList);
|
|
|
|
item->setFlags(item->flags() | Qt::ItemIsEditable);
|
|
|
|
item->setText(col_p_pipe_, device.display_name);
|
2014-06-24 09:36:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
void ManageInterfacesDialog::on_buttonBox_accepted()
|
2014-06-24 09:36:51 +00:00
|
|
|
{
|
2014-08-14 20:20:09 +00:00
|
|
|
pipeAccepted();
|
|
|
|
localAccepted();
|
|
|
|
#ifdef HAVE_PCAP_REMOTE
|
|
|
|
remoteAccepted();
|
|
|
|
#endif
|
|
|
|
prefs_main_write();
|
|
|
|
emit ifsChanged();
|
2014-06-24 09:36:51 +00:00
|
|
|
}
|
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
const QString new_pipe_default_ = QObject::tr("New Pipe");
|
|
|
|
void ManageInterfacesDialog::on_addPipe_clicked()
|
|
|
|
{
|
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem(ui->pipeList);
|
|
|
|
item->setText(col_p_pipe_, new_pipe_default_);
|
|
|
|
item->setFlags(item->flags() | Qt::ItemIsEditable);
|
|
|
|
ui->pipeList->setCurrentItem(item);
|
|
|
|
ui->pipeList->editItem(item, col_p_pipe_);
|
|
|
|
}
|
2014-06-24 09:36:51 +00:00
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
void ManageInterfacesDialog::pipeAccepted()
|
2014-06-24 09:36:51 +00:00
|
|
|
{
|
|
|
|
interface_t device;
|
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
// First clear the current pipes
|
|
|
|
for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) {
|
|
|
|
device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
|
|
|
|
/* Continue if capture device is hidden or not a pipe */
|
|
|
|
if (device.hidden || device.type != IF_PIPE) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i);
|
2015-11-26 08:27:51 +00:00
|
|
|
capture_opts_free_interface_t(&device);
|
2014-08-14 20:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Next rebuild a fresh list
|
|
|
|
QTreeWidgetItemIterator it(ui->pipeList);
|
|
|
|
while (*it) {
|
|
|
|
QString pipe_name = (*it)->text(col_p_pipe_);
|
|
|
|
if (pipe_name.isEmpty() || pipe_name == new_pipe_default_) {
|
|
|
|
++it;
|
|
|
|
continue;
|
2014-06-24 09:36:51 +00:00
|
|
|
}
|
2014-08-14 20:20:09 +00:00
|
|
|
|
2014-06-24 09:36:51 +00:00
|
|
|
for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) {
|
2014-08-14 20:20:09 +00:00
|
|
|
// Instead of just deleting the device we might want to add a hint label
|
|
|
|
// and let the user know what's going to happen.
|
|
|
|
device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
|
|
|
|
if (pipe_name.compare(device.name) == 0) { // Duplicate
|
|
|
|
++it;
|
|
|
|
continue;
|
|
|
|
}
|
2014-06-24 09:36:51 +00:00
|
|
|
}
|
2014-08-14 20:20:09 +00:00
|
|
|
|
2015-11-26 08:27:51 +00:00
|
|
|
memset(&device, 0, sizeof(device));
|
2014-08-14 20:20:09 +00:00
|
|
|
device.name = qstring_strdup(pipe_name);
|
|
|
|
device.display_name = g_strdup(device.name);
|
2014-06-24 09:36:51 +00:00
|
|
|
device.hidden = FALSE;
|
|
|
|
device.selected = TRUE;
|
|
|
|
device.type = IF_PIPE;
|
|
|
|
device.pmode = global_capture_opts.default_options.promisc_mode;
|
|
|
|
device.has_snaplen = global_capture_opts.default_options.has_snaplen;
|
|
|
|
device.snaplen = global_capture_opts.default_options.snaplen;
|
|
|
|
device.cfilter = g_strdup(global_capture_opts.default_options.cfilter);
|
2014-08-14 20:20:09 +00:00
|
|
|
device.addresses = NULL;
|
2014-06-24 09:36:51 +00:00
|
|
|
device.no_addresses = 0;
|
|
|
|
device.last_packets = 0;
|
|
|
|
device.links = NULL;
|
2015-03-25 03:22:00 +00:00
|
|
|
#ifdef CAN_SET_CAPTURE_BUFFER_SIZE
|
2014-06-24 09:36:51 +00:00
|
|
|
device.buffer = DEFAULT_CAPTURE_BUFFER_SIZE;
|
2014-08-14 20:20:09 +00:00
|
|
|
#endif
|
2014-06-24 09:36:51 +00:00
|
|
|
device.active_dlt = -1;
|
|
|
|
device.locked = FALSE;
|
2014-08-14 20:20:09 +00:00
|
|
|
device.if_info.name = g_strdup(device.name);
|
2014-06-24 09:36:51 +00:00
|
|
|
device.if_info.friendly_name = NULL;
|
|
|
|
device.if_info.vendor_description = NULL;
|
|
|
|
device.if_info.addrs = NULL;
|
|
|
|
device.if_info.loopback = FALSE;
|
|
|
|
device.if_info.type = IF_PIPE;
|
2015-08-21 10:43:55 +00:00
|
|
|
#ifdef HAVE_EXTCAP
|
|
|
|
device.if_info.extcap = NULL;
|
|
|
|
device.external_cap_args_settings = NULL;
|
|
|
|
#endif
|
2014-08-14 20:20:09 +00:00
|
|
|
#if defined(HAVE_PCAP_CREATE)
|
2014-06-24 09:36:51 +00:00
|
|
|
device.monitor_mode_enabled = FALSE;
|
|
|
|
device.monitor_mode_supported = FALSE;
|
2014-08-14 20:20:09 +00:00
|
|
|
#endif
|
2014-06-24 09:36:51 +00:00
|
|
|
global_capture_opts.num_selected++;
|
|
|
|
g_array_append_val(global_capture_opts.all_ifaces, device);
|
2014-08-14 20:20:09 +00:00
|
|
|
++it;
|
2014-06-24 09:36:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
void ManageInterfacesDialog::on_delPipe_clicked()
|
|
|
|
{
|
|
|
|
// We're just managing a list of strings at this point.
|
|
|
|
delete ui->pipeList->currentItem();
|
|
|
|
}
|
2014-06-24 09:36:51 +00:00
|
|
|
|
2015-07-07 21:47:20 +00:00
|
|
|
void ManageInterfacesDialog::on_pipeList_currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)
|
2014-06-24 09:36:51 +00:00
|
|
|
{
|
2014-08-14 20:20:09 +00:00
|
|
|
updateWidgets();
|
2014-06-24 09:36:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ManageInterfacesDialog::showLocalInterfaces()
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
interface_t device;
|
|
|
|
gchar *pr_descr = g_strdup("");
|
|
|
|
char *comment = NULL;
|
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
ui->localList->clear();
|
2014-06-24 09:36:51 +00:00
|
|
|
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.local && device.type != IF_PIPE && device.type != IF_STDIN) {
|
2014-08-14 20:20:09 +00:00
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem(ui->localList);
|
|
|
|
item->setFlags(item->flags() | Qt::ItemIsEditable);
|
|
|
|
if (prefs.capture_device && strstr(prefs.capture_device, device.name)) {
|
|
|
|
// Force the default device to be checked.
|
|
|
|
item->setFlags(item->flags() ^ Qt::ItemIsUserCheckable);
|
|
|
|
item->setCheckState(col_l_show_, Qt::Checked);
|
|
|
|
} else {
|
|
|
|
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
|
|
|
item->setCheckState(col_l_show_, device.hidden ? Qt::Unchecked : Qt::Checked);
|
|
|
|
}
|
2014-06-24 09:36:51 +00:00
|
|
|
#ifdef _WIN32
|
2014-08-14 20:20:09 +00:00
|
|
|
item->setText(col_l_friendly_name_, device.friendly_name);
|
2014-06-24 09:36:51 +00:00
|
|
|
#endif
|
2014-08-14 20:20:09 +00:00
|
|
|
item->setText(col_l_local_name_, device.name);
|
2014-06-24 09:36:51 +00:00
|
|
|
|
|
|
|
comment = capture_dev_user_descr_find(device.name);
|
2014-08-14 20:20:09 +00:00
|
|
|
if (comment) {
|
|
|
|
item->setText(col_l_comment_, comment);
|
2015-03-19 00:27:57 +00:00
|
|
|
g_free(comment);
|
2016-02-23 16:01:16 +00:00
|
|
|
} else if (device.if_info.vendor_description) {
|
|
|
|
item->setText(col_l_comment_, device.if_info.vendor_description);
|
2014-08-14 20:20:09 +00:00
|
|
|
}
|
2014-06-24 09:36:51 +00:00
|
|
|
} else {
|
2016-02-23 16:01:16 +00:00
|
|
|
continue;
|
2014-06-24 09:36:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
g_free(pr_descr);
|
|
|
|
}
|
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
void ManageInterfacesDialog::saveLocalHideChanges(QTreeWidgetItem *item)
|
2014-06-24 09:36:51 +00:00
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
interface_t device;
|
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
if (!item) {
|
2014-06-24 09:36:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
QString name = item->text(col_l_local_name_);
|
2014-06-24 09:36:51 +00:00
|
|
|
/* See if this is the currently selected capturing 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 (name.compare(device.name)) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-08-14 20:20:09 +00:00
|
|
|
device.hidden = (item->checkState(col_l_show_) == Qt::Checked ? false : true);
|
2014-06-24 09:36:51 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
void ManageInterfacesDialog::saveLocalCommentChanges(QTreeWidgetItem* item)
|
2014-06-24 09:36:51 +00:00
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
interface_t device;
|
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
if (!item) {
|
2014-06-24 09:36:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
QString name = item->text(col_l_local_name_);
|
|
|
|
QString comment = item->text(col_l_comment_);
|
2014-06-24 09:36:51 +00:00
|
|
|
/* See if this is the currently selected capturing 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 (name.compare(device.name)) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-08-14 20:20:09 +00:00
|
|
|
|
|
|
|
g_free(device.display_name);
|
2015-12-02 06:32:48 +00:00
|
|
|
device.display_name = get_iface_display_name(comment.toUtf8().constData(), &device.if_info);
|
2014-06-24 09:36:51 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
#if 0 // Not needed?
|
|
|
|
void ManageInterfacesDialog::checkBoxChanged(QTreeWidgetItem* item)
|
2014-06-24 09:36:51 +00:00
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
interface_t device;
|
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
if (!item) {
|
2014-06-24 09:36:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
QString name = item->text(col_l_local_name_);
|
2014-06-24 09:36:51 +00:00
|
|
|
/* See if this is the currently selected capturing 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 (name.compare(device.name)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (prefs.capture_device && strstr(prefs.capture_device, device.name) && item->checkState() == Qt::Checked) {
|
|
|
|
/* Don't allow current interface to be hidden */
|
|
|
|
QMessageBox::warning(this, tr("Error"),
|
|
|
|
tr("Default interface cannot be hidden."));
|
|
|
|
item->setCheckState(Qt::Unchecked);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-14 20:20:09 +00:00
|
|
|
#endif // checkBoxChanged not needed?
|
2014-06-24 09:36:51 +00:00
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
void ManageInterfacesDialog::localAccepted()
|
2014-06-24 09:36:51 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (global_capture_opts.all_ifaces->len > 0) {
|
2014-08-14 20:20:09 +00:00
|
|
|
QStringList hide_list;
|
|
|
|
QStringList comment_list;
|
|
|
|
QTreeWidgetItemIterator it(ui->localList);
|
|
|
|
while (*it) {
|
|
|
|
if ((*it)->checkState(col_l_show_) != Qt::Checked) {
|
|
|
|
hide_list << (*it)->text(col_l_local_name_);
|
2014-06-24 09:36:51 +00:00
|
|
|
}
|
2014-08-14 20:20:09 +00:00
|
|
|
|
|
|
|
if (!(*it)->text(col_l_local_name_).isEmpty()) {
|
|
|
|
comment_list << QString("%1(%2)").arg((*it)->text(col_l_local_name_)).arg((*it)->text(col_l_comment_));
|
|
|
|
}
|
|
|
|
|
|
|
|
saveLocalHideChanges(*it);
|
|
|
|
saveLocalCommentChanges(*it);
|
|
|
|
++it;
|
2014-06-24 09:36:51 +00:00
|
|
|
}
|
|
|
|
/* write new "hidden" string to preferences */
|
|
|
|
g_free(prefs.capture_devices_hide);
|
2014-08-14 20:20:09 +00:00
|
|
|
gchar *new_hide = qstring_strdup(hide_list.join(","));
|
2014-06-24 09:36:51 +00:00
|
|
|
prefs.capture_devices_hide = new_hide;
|
|
|
|
hide_interface(g_strdup(new_hide));
|
|
|
|
|
|
|
|
/* write new description string to preferences */
|
|
|
|
if (prefs.capture_devices_descr)
|
|
|
|
g_free(prefs.capture_devices_descr);
|
2016-02-19 18:47:16 +00:00
|
|
|
prefs.capture_devices_descr = qstring_strdup(comment_list.join(","));
|
2014-06-24 09:36:51 +00:00
|
|
|
}
|
2014-08-14 20:20:09 +00:00
|
|
|
}
|
2014-06-24 09:36:51 +00:00
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
void ManageInterfacesDialog::on_buttonBox_helpRequested()
|
|
|
|
{
|
|
|
|
wsApp->helpTopicAction(HELP_CAPTURE_MANAGE_INTERFACES_DIALOG);
|
2014-06-24 09:36:51 +00:00
|
|
|
}
|
|
|
|
|
2016-02-19 18:47:16 +00:00
|
|
|
void ManageInterfacesDialog::localListItemDoubleClicked(QTreeWidgetItem * item, int column)
|
|
|
|
{
|
|
|
|
if (column == col_l_comment_) {
|
|
|
|
ui->localList->editItem(item, column);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-04 11:57:17 +00:00
|
|
|
#ifdef HAVE_PCAP_REMOTE
|
2015-07-07 21:47:20 +00:00
|
|
|
void ManageInterfacesDialog::remoteSelectionChanged(QTreeWidgetItem*, int)
|
2014-08-04 11:57:17 +00:00
|
|
|
{
|
2014-08-14 20:20:09 +00:00
|
|
|
updateWidgets();
|
2014-08-04 11:57:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ManageInterfacesDialog::addRemoteInterfaces(GList* rlist, remote_options *roptions)
|
|
|
|
{
|
|
|
|
GList *if_entry, *lt_entry;
|
|
|
|
if_info_t *if_info;
|
|
|
|
char *if_string = NULL;
|
2015-07-17 15:01:27 +00:00
|
|
|
gchar *descr, *str = NULL, *link_type_name = NULL, *auth_str;
|
2014-08-04 11:57:17 +00:00
|
|
|
if_capabilities_t *caps;
|
|
|
|
gint linktype_count;
|
|
|
|
bool monitor_mode, found = false;
|
|
|
|
GSList *curr_addr;
|
|
|
|
int ips = 0;
|
|
|
|
guint i;
|
|
|
|
if_addr_t *addr;
|
|
|
|
data_link_info_t *data_link_info;
|
|
|
|
GString *ip_str;
|
|
|
|
link_row *linkr = NULL;
|
|
|
|
interface_t device;
|
|
|
|
|
|
|
|
guint num_interfaces = global_capture_opts.all_ifaces->len;
|
|
|
|
for (if_entry = g_list_first(rlist); if_entry != NULL; if_entry = g_list_next(if_entry)) {
|
2015-07-17 15:01:27 +00:00
|
|
|
auth_str = NULL;
|
2014-08-04 11:57:17 +00:00
|
|
|
if_info = (if_info_t *)if_entry->data;
|
|
|
|
for (i = 0; i < num_interfaces; i++) {
|
|
|
|
device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
|
|
|
|
if (device.hidden)
|
|
|
|
continue;
|
|
|
|
if (strcmp(device.name, if_info->name) == 0) {
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (found) {
|
|
|
|
found = FALSE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ip_str = g_string_new("");
|
|
|
|
ips = 0;
|
2015-11-26 08:27:51 +00:00
|
|
|
memset(&device, 0, sizeof(device));
|
2014-08-04 11:57:17 +00:00
|
|
|
device.name = g_strdup(if_info->name);
|
|
|
|
/* Is this interface hidden and, if so, should we include it
|
|
|
|
anyway? */
|
|
|
|
descr = capture_dev_user_descr_find(if_info->name);
|
|
|
|
if (descr != NULL) {
|
|
|
|
/* Yes, we have a user-supplied description; use it. */
|
|
|
|
if_string = g_strdup_printf("%s: %s", descr, if_info->name);
|
|
|
|
g_free(descr);
|
|
|
|
} else {
|
|
|
|
/* No, we don't have a user-supplied description; did we get
|
|
|
|
one from the OS or libpcap? */
|
|
|
|
if (if_info->vendor_description != NULL) {
|
|
|
|
/* Yes - use it. */
|
|
|
|
if_string = g_strdup_printf("%s: %s", if_info->vendor_description, if_info->name);
|
|
|
|
} else {
|
|
|
|
/* No. */
|
|
|
|
if_string = g_strdup(if_info->name);
|
|
|
|
}
|
|
|
|
} /* else descr != NULL */
|
|
|
|
if (if_info->loopback) {
|
|
|
|
device.display_name = g_strdup_printf("%s (loopback)", if_string);
|
|
|
|
} else {
|
|
|
|
device.display_name = g_strdup(if_string);
|
|
|
|
}
|
2015-03-25 03:22:00 +00:00
|
|
|
#ifdef CAN_SET_CAPTURE_BUFFER_SIZE
|
2014-08-04 11:57:17 +00:00
|
|
|
if ((device.buffer = capture_dev_user_buffersize_find(if_string)) == -1) {
|
|
|
|
device.buffer = global_capture_opts.default_options.buffer_size;
|
|
|
|
}
|
|
|
|
#endif
|
2015-04-04 21:43:22 +00:00
|
|
|
if (!capture_dev_user_pmode_find(if_string, &device.pmode)) {
|
2014-08-04 11:57:17 +00:00
|
|
|
device.pmode = global_capture_opts.default_options.promisc_mode;
|
|
|
|
}
|
2015-03-19 01:16:30 +00:00
|
|
|
if (!capture_dev_user_snaplen_find(if_string, &device.has_snaplen,
|
|
|
|
&device.snaplen)) {
|
|
|
|
device.has_snaplen = global_capture_opts.default_options.has_snaplen;
|
2014-08-04 11:57:17 +00:00
|
|
|
device.snaplen = global_capture_opts.default_options.snaplen;
|
|
|
|
}
|
|
|
|
device.cfilter = g_strdup(global_capture_opts.default_options.cfilter);
|
|
|
|
monitor_mode = prefs_capture_device_monitor_mode(if_string);
|
2015-07-17 15:01:27 +00:00
|
|
|
#ifdef HAVE_PCAP_REMOTE
|
|
|
|
if (roptions->remote_host_opts.auth_type == CAPTURE_AUTH_PWD) {
|
|
|
|
auth_str = g_strdup_printf("%s:%s", roptions->remote_host_opts.auth_username,
|
|
|
|
roptions->remote_host_opts.auth_password);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
caps = capture_get_if_capabilities(if_string, monitor_mode, auth_str, NULL, main_window_update);
|
|
|
|
g_free(auth_str);
|
2014-08-04 11:57:17 +00:00
|
|
|
for (; (curr_addr = g_slist_nth(if_info->addrs, ips)) != NULL; ips++) {
|
2014-12-21 13:02:26 +00:00
|
|
|
address addr_str;
|
2015-01-05 16:12:08 +00:00
|
|
|
char* temp_addr_str = NULL;
|
2014-08-04 11:57:17 +00:00
|
|
|
if (ips != 0) {
|
|
|
|
g_string_append(ip_str, "\n");
|
|
|
|
}
|
|
|
|
addr = (if_addr_t *)curr_addr->data;
|
|
|
|
switch (addr->ifat_type) {
|
|
|
|
case IF_AT_IPv4:
|
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 = (char*)address_to_str(NULL, &addr_str);
|
|
|
|
g_string_append(ip_str, temp_addr_str);
|
2014-08-04 11:57:17 +00:00
|
|
|
break;
|
|
|
|
case IF_AT_IPv6:
|
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 = (char*)address_to_str(NULL, &addr_str);
|
|
|
|
g_string_append(ip_str, temp_addr_str);
|
2014-08-04 11:57:17 +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);
|
2014-08-04 11:57:17 +00:00
|
|
|
} /* for curr_addr */
|
|
|
|
linktype_count = 0;
|
|
|
|
device.links = NULL;
|
|
|
|
if (caps != NULL) {
|
|
|
|
#ifdef HAVE_PCAP_CREATE
|
|
|
|
device.monitor_mode_enabled = monitor_mode;
|
|
|
|
device.monitor_mode_supported = caps->can_set_rfmon;
|
|
|
|
#endif
|
|
|
|
for (lt_entry = caps->data_link_types; lt_entry != NULL; lt_entry = g_list_next(lt_entry)) {
|
|
|
|
data_link_info = (data_link_info_t *)lt_entry->data;
|
|
|
|
linkr = (link_row *)g_malloc(sizeof(link_row));
|
|
|
|
/*
|
|
|
|
* For link-layer types libpcap/WinPcap doesn't know about, the
|
|
|
|
* name will be "DLT n", and the description will be null.
|
|
|
|
* We mark those as unsupported, and don't allow them to be
|
|
|
|
* used.
|
|
|
|
*/
|
|
|
|
if (data_link_info->description != NULL) {
|
2016-06-06 02:24:47 +00:00
|
|
|
str = g_strdup(data_link_info->description);
|
2014-08-04 11:57:17 +00:00
|
|
|
linkr->dlt = data_link_info->dlt;
|
|
|
|
} else {
|
|
|
|
str = g_strdup_printf("%s (not supported)", data_link_info->name);
|
|
|
|
linkr->dlt = -1;
|
|
|
|
}
|
|
|
|
if (linktype_count == 0) {
|
|
|
|
link_type_name = g_strdup(str);
|
|
|
|
device.active_dlt = data_link_info->dlt;
|
|
|
|
}
|
|
|
|
linkr->name = g_strdup(str);
|
|
|
|
g_free(str);
|
|
|
|
device.links = g_list_append(device.links, linkr);
|
|
|
|
linktype_count++;
|
|
|
|
} /* for link_types */
|
|
|
|
} else {
|
|
|
|
#if defined(HAVE_PCAP_CREATE)
|
|
|
|
device.monitor_mode_enabled = FALSE;
|
|
|
|
device.monitor_mode_supported = FALSE;
|
|
|
|
#endif
|
|
|
|
device.active_dlt = -1;
|
|
|
|
link_type_name = g_strdup("default");
|
|
|
|
}
|
|
|
|
device.addresses = g_strdup(ip_str->str);
|
|
|
|
device.no_addresses = ips;
|
|
|
|
device.remote_opts.src_type= roptions->src_type;
|
|
|
|
if (device.remote_opts.src_type == CAPTURE_IFREMOTE) {
|
|
|
|
device.local = FALSE;
|
|
|
|
}
|
|
|
|
device.remote_opts.remote_host_opts.remote_host = g_strdup(roptions->remote_host_opts.remote_host);
|
|
|
|
device.remote_opts.remote_host_opts.remote_port = g_strdup(roptions->remote_host_opts.remote_port);
|
|
|
|
device.remote_opts.remote_host_opts.auth_type = roptions->remote_host_opts.auth_type;
|
|
|
|
device.remote_opts.remote_host_opts.auth_username = g_strdup(roptions->remote_host_opts.auth_username);
|
|
|
|
device.remote_opts.remote_host_opts.auth_password = g_strdup(roptions->remote_host_opts.auth_password);
|
|
|
|
device.remote_opts.remote_host_opts.datatx_udp = roptions->remote_host_opts.datatx_udp;
|
|
|
|
device.remote_opts.remote_host_opts.nocap_rpcap = roptions->remote_host_opts.nocap_rpcap;
|
|
|
|
device.remote_opts.remote_host_opts.nocap_local = roptions->remote_host_opts.nocap_local;
|
|
|
|
#ifdef HAVE_PCAP_SETSAMPLING
|
|
|
|
device.remote_opts.sampling_method = roptions->sampling_method;
|
|
|
|
device.remote_opts.sampling_param = roptions->sampling_param;
|
|
|
|
#endif
|
|
|
|
device.selected = TRUE;
|
|
|
|
global_capture_opts.num_selected++;
|
|
|
|
g_array_append_val(global_capture_opts.all_ifaces, device);
|
|
|
|
g_string_free(ip_str, TRUE);
|
|
|
|
} /*for*/
|
|
|
|
showRemoteInterfaces();
|
|
|
|
}
|
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
// We don't actually store these. When we do we should make sure they're stored
|
|
|
|
// securely using CryptProtectData, the OS X Keychain, GNOME Keyring, KWallet, etc.
|
|
|
|
void ManageInterfacesDialog::remoteAccepted()
|
2014-08-04 11:57:17 +00:00
|
|
|
{
|
|
|
|
QTreeWidgetItemIterator it(ui->remoteList);
|
|
|
|
|
|
|
|
while(*it) {
|
|
|
|
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);
|
2014-08-14 20:20:09 +00:00
|
|
|
if ((*it)->text(col_r_host_dev_).compare(device.name))
|
2014-08-04 11:57:17 +00:00
|
|
|
continue;
|
2014-08-14 20:20:09 +00:00
|
|
|
device.hidden = ((*it)->checkState(col_r_show_) == Qt::Checked ? false : true);
|
2014-08-04 11:57:17 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-07 21:47:20 +00:00
|
|
|
void ManageInterfacesDialog::on_remoteList_currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)
|
2014-08-04 11:57:17 +00:00
|
|
|
{
|
2014-08-14 20:20:09 +00:00
|
|
|
updateWidgets();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ManageInterfacesDialog::on_remoteList_itemClicked(QTreeWidgetItem *item, int column)
|
|
|
|
{
|
|
|
|
if (!item || column != col_r_show_) {
|
2014-08-04 11:57:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-08-14 20:20:09 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
if (!device.local) {
|
|
|
|
if (item->text(col_r_host_dev_).compare(device.name))
|
2014-08-04 11:57:17 +00:00
|
|
|
continue;
|
2014-08-14 20:20:09 +00:00
|
|
|
device.hidden = (item->checkState(col_r_show_) == Qt::Checked ? false : true);
|
2014-08-04 11:57:17 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-14 20:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ManageInterfacesDialog::on_delRemote_clicked()
|
|
|
|
{
|
|
|
|
QTreeWidgetItem* item = ui->remoteList->currentItem();
|
|
|
|
if (!item) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
if (item->text(col_r_host_dev_).compare(device.remote_opts.remote_host_opts.remote_host))
|
|
|
|
continue;
|
|
|
|
global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i);
|
|
|
|
}
|
|
|
|
delete item;
|
|
|
|
fflush(stdout); // ???
|
2014-08-04 11:57:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ManageInterfacesDialog::on_addRemote_clicked()
|
|
|
|
{
|
|
|
|
RemoteCaptureDialog *dlg = new RemoteCaptureDialog(this);
|
|
|
|
dlg->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ManageInterfacesDialog::showRemoteInterfaces()
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
interface_t device;
|
2014-08-14 20:20:09 +00:00
|
|
|
QTreeWidgetItem *item = NULL;
|
2014-08-04 11:57:17 +00:00
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
// We assume that remote interfaces are grouped by host.
|
2014-08-04 11:57:17 +00:00
|
|
|
for (i = 0; i < global_capture_opts.all_ifaces->len; i++) {
|
2014-08-14 20:20:09 +00:00
|
|
|
QTreeWidgetItem *child;
|
2014-08-04 11:57:17 +00:00
|
|
|
device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
|
|
|
|
if (!device.local) {
|
2014-08-14 20:20:09 +00:00
|
|
|
if (!item || item->text(col_r_host_dev_).compare(device.remote_opts.remote_host_opts.remote_host) != 0) {
|
|
|
|
item = new QTreeWidgetItem(ui->remoteList);
|
|
|
|
item->setText(col_r_host_dev_, device.remote_opts.remote_host_opts.remote_host);
|
|
|
|
item->setExpanded(true);
|
2014-08-04 11:57:17 +00:00
|
|
|
}
|
2014-08-14 20:20:09 +00:00
|
|
|
child = new QTreeWidgetItem(item);
|
|
|
|
child->setCheckState(col_r_show_, device.hidden ? Qt::Unchecked : Qt::Checked);
|
|
|
|
child->setText(col_r_host_dev_, QString(device.name));
|
2014-08-04 11:57:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ManageInterfacesDialog::on_remoteSettings_clicked()
|
|
|
|
{
|
|
|
|
guint i = 0;
|
|
|
|
interface_t device;
|
2014-08-14 20:20:09 +00:00
|
|
|
QTreeWidgetItem* item = ui->remoteList->currentItem();
|
|
|
|
if (!item) {
|
|
|
|
return;
|
|
|
|
}
|
2014-08-04 11:57:17 +00:00
|
|
|
|
|
|
|
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.local) {
|
2014-08-14 20:20:09 +00:00
|
|
|
if (item->text(col_r_host_dev_).compare(device.name)) {
|
2014-08-04 11:57:17 +00:00
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
RemoteSettingsDialog *dlg = new RemoteSettingsDialog(this, &device);
|
|
|
|
dlg->show();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ManageInterfacesDialog::setRemoteSettings(interface_t *iface)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
if (!device.local) {
|
|
|
|
if (strcmp(iface->name, device.name)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
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;
|
2014-08-05 11:57:16 +00:00
|
|
|
#ifdef HAVE_PCAP_SETSAMPLING
|
2014-08-04 11:57:17 +00:00
|
|
|
device.remote_opts.sampling_method = iface->remote_opts.sampling_method;
|
|
|
|
device.remote_opts.sampling_param = iface->remote_opts.sampling_param;
|
2014-08-05 11:57:16 +00:00
|
|
|
#endif //HAVE_PCAP_SETSAMPLING
|
2014-08-04 11:57:17 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-14 20:20:09 +00:00
|
|
|
#endif // HAVE_PCAP_REMOTE
|
2014-06-24 09:36:51 +00:00
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
PathChooserDelegate::PathChooserDelegate(QObject *parent)
|
2016-07-04 20:53:21 +00:00
|
|
|
: QStyledItemDelegate(parent), tree_(NULL), path_item_(NULL), path_editor_(NULL), path_le_(NULL)
|
2014-06-24 09:36:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
PathChooserDelegate::~PathChooserDelegate()
|
2014-06-24 09:36:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-07-07 21:47:20 +00:00
|
|
|
QWidget* PathChooserDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &) const
|
2014-06-24 09:36:51 +00:00
|
|
|
{
|
2014-08-14 20:20:09 +00:00
|
|
|
QTreeWidgetItem *item = tree_->currentItem();
|
|
|
|
if (!item) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
path_item_ = item;
|
|
|
|
|
|
|
|
path_editor_ = new QWidget(parent);
|
|
|
|
QHBoxLayout *hbox = new QHBoxLayout(path_editor_);
|
|
|
|
path_editor_->setLayout(hbox);
|
|
|
|
path_le_ = new QLineEdit(path_editor_);
|
|
|
|
QPushButton *pb = new QPushButton(path_editor_);
|
2014-06-24 09:36:51 +00:00
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
path_le_->setText(item->text(col_p_pipe_));
|
2015-07-31 17:34:43 +00:00
|
|
|
pb->setText(QString(tr("Browse" UTF8_HORIZONTAL_ELLIPSIS)));
|
2014-08-14 20:20:09 +00:00
|
|
|
|
|
|
|
hbox->setContentsMargins(0, 0, 0, 0);
|
|
|
|
hbox->addWidget(path_le_);
|
2014-06-24 09:36:51 +00:00
|
|
|
hbox->addWidget(pb);
|
2014-08-14 20:20:09 +00:00
|
|
|
hbox->setSizeConstraint(QLayout::SetMinimumSize);
|
|
|
|
|
|
|
|
// Grow the item to match the editor. According to the QAbstractItemDelegate
|
|
|
|
// documenation we're supposed to reimplement sizeHint but this seems to work.
|
|
|
|
QSize size = option.rect.size();
|
|
|
|
size.setHeight(qMax(option.rect.height(), hbox->sizeHint().height()));
|
|
|
|
item->setData(col_p_pipe_, Qt::SizeHintRole, size);
|
|
|
|
|
|
|
|
path_le_->selectAll();
|
|
|
|
path_editor_->setFocusProxy(path_le_);
|
|
|
|
path_editor_->setFocusPolicy(path_le_->focusPolicy());
|
2014-06-24 09:36:51 +00:00
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
connect(path_le_, SIGNAL(destroyed()), this, SLOT(stopEditor()));
|
2014-06-24 09:36:51 +00:00
|
|
|
connect(pb, SIGNAL(pressed()), this, SLOT(browse_button_clicked()));
|
2014-08-14 20:20:09 +00:00
|
|
|
return path_editor_;
|
2014-06-24 09:36:51 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 21:47:20 +00:00
|
|
|
void PathChooserDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const
|
2014-06-24 09:36:51 +00:00
|
|
|
{
|
2014-08-14 20:20:09 +00:00
|
|
|
QRect rect = option.rect;
|
|
|
|
|
|
|
|
// Make sure the editor doesn't get squashed.
|
|
|
|
editor->adjustSize();
|
|
|
|
rect.setHeight(qMax(option.rect.height(), editor->height()));
|
|
|
|
editor->setGeometry(rect);
|
2014-06-24 09:36:51 +00:00
|
|
|
}
|
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
void PathChooserDelegate::stopEditor()
|
2014-06-24 09:36:51 +00:00
|
|
|
{
|
2014-08-14 20:20:09 +00:00
|
|
|
path_item_->setData(col_p_pipe_, Qt::SizeHintRole, QVariant());
|
|
|
|
path_item_->setText(col_p_pipe_, path_le_->text());
|
2014-06-24 09:36:51 +00:00
|
|
|
}
|
|
|
|
|
2014-08-14 20:20:09 +00:00
|
|
|
void PathChooserDelegate::browse_button_clicked()
|
2014-06-24 09:36:51 +00:00
|
|
|
{
|
|
|
|
char *open_dir = NULL;
|
|
|
|
|
|
|
|
switch (prefs.gui_fileopen_style) {
|
|
|
|
|
|
|
|
case FO_STYLE_LAST_OPENED:
|
|
|
|
open_dir = get_last_open_dir();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FO_STYLE_SPECIFIED:
|
|
|
|
if (prefs.gui_fileopen_dir[0] != '\0')
|
|
|
|
open_dir = prefs.gui_fileopen_dir;
|
|
|
|
break;
|
|
|
|
}
|
2014-08-14 20:20:09 +00:00
|
|
|
QString file_name = QFileDialog::getOpenFileName(tree_, tr("Open Pipe"), open_dir);
|
|
|
|
if (!file_name.isEmpty()) {
|
|
|
|
path_le_->setText(file_name);
|
|
|
|
}
|
2014-06-24 09:36:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_LIBPCAP */
|
2014-08-11 06:58:13 +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:
|
|
|
|
*/
|