diff options
author | Irene Ruengeler <ruengeler@wireshark.org> | 2014-08-04 13:57:17 +0200 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2014-08-05 07:48:45 +0000 |
commit | f080b43933fe1bbac48122fc32e9cf621bbd63f4 (patch) | |
tree | e0df63fa7950ae2b23ac9c199a7e36b72b2d2218 /ui/qt/remote_capture_dialog.cpp | |
parent | 3b91474af57daf6620be0d5233c7f2c59c17b3c5 (diff) |
Windows: Manage remote interfaces
Add remote interfaces to capture from a remote host.
Change-Id: I34e31d865304f3c6dd972ab9ab1c23829d564665
Reviewed-on: https://code.wireshark.org/review/3405
Petri-Dish: Jeff Morriss <jeff.morriss.ws@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'ui/qt/remote_capture_dialog.cpp')
-rw-r--r-- | ui/qt/remote_capture_dialog.cpp | 180 |
1 files changed, 180 insertions, 0 deletions
diff --git a/ui/qt/remote_capture_dialog.cpp b/ui/qt/remote_capture_dialog.cpp new file mode 100644 index 0000000000..e52e5973f0 --- /dev/null +++ b/ui/qt/remote_capture_dialog.cpp @@ -0,0 +1,180 @@ +/* remote_capture_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 "config.h" +#ifdef HAVE_PCAP_REMOTE +#include <glib.h> +#include "ui/capture_globals.h" +#include "remote_capture_dialog.h" +#include "ui_remote_capture_dialog.h" +#include "capture_opts.h" +#include "caputils/capture-pcap-util.h" +#include "ui/capture_ui_utils.h" +#include "epan/prefs.h" +#include "epan/to_str.h" +#include "ui/ui_util.h" +#include "ui/recent.h" + +#include <QMessageBox> + +static guint num_selected = 0; + +RemoteCaptureDialog::RemoteCaptureDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::RemoteCaptureDialog) +{ + ui->setupUi(this); + + fillComboBox(); + connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(apply_remote())); + connect(this, SIGNAL(remoteAdded(GList *, remote_options*)), parent, SIGNAL(remoteAdded(GList *, remote_options*))); + connect(ui->hostCombo, SIGNAL(currentIndexChanged(QString)), this, SLOT(hostChanged(QString))); +} + +RemoteCaptureDialog::~RemoteCaptureDialog() +{ + delete ui; +} + +void RemoteCaptureDialog::hostChanged(QString host) +{ + if (!host.compare(tr("Clear list"))) { + free_remote_host_list(); + ui->hostCombo->clear(); + } else { + struct remote_host *rh = recent_get_remote_host(host.toUtf8().constData()); + if (rh) { + ui->portText->setText(QString(rh->remote_port)); + if (rh->auth_type == CAPTURE_AUTH_NULL) { + ui->nullAuth->setChecked(true); + } else { + ui->pwAuth->setChecked(true); + } + } + } + +} + +static void fillBox(gpointer key, gpointer value, gpointer user_data) +{ + Q_UNUSED(value); + Q_UNUSED(user_data); + + QComboBox *cb = (QComboBox *)user_data; + cb->addItem(QString((gchar*)key)); +} + +void RemoteCaptureDialog::fillComboBox() +{ + GHashTable *ht = get_remote_host_list(); + ui->hostCombo->addItem(QString("")); + if (g_hash_table_size(ht) > 0) { + g_hash_table_foreach(ht, fillBox, ui->hostCombo); + ui->hostCombo->insertSeparator(g_hash_table_size(ht)+1); + ui->hostCombo->addItem(QString(tr("Clear list"))); + } +} + +void RemoteCaptureDialog::apply_remote() +{ + int err; + gchar *err_str; + remote_options global_remote_opts; + + QString host = ui->hostCombo->currentText(); + global_remote_opts.src_type = CAPTURE_IFREMOTE; + global_remote_opts.remote_host_opts.remote_host = g_strdup((gchar *)host.toUtf8().constData()); + QString port = ui->portText->text(); + global_remote_opts.remote_host_opts.remote_port = g_strdup((gchar *)port.toUtf8().constData()); + if (ui->pwAuth->isChecked()) { + global_remote_opts.remote_host_opts.auth_type = CAPTURE_AUTH_PWD; + } else { + global_remote_opts.remote_host_opts.auth_type = CAPTURE_AUTH_NULL; + } + QString user = ui->userText->text(); + global_remote_opts.remote_host_opts.auth_username = g_strdup((gchar *)user.toUtf8().constData()); + QString pw = ui->pwText->text(); + global_remote_opts.remote_host_opts.auth_password = g_strdup((gchar *)pw.toUtf8().constData()); + GList *rlist = get_remote_interface_list(global_remote_opts.remote_host_opts.remote_host, + global_remote_opts.remote_host_opts.remote_port, + global_remote_opts.remote_host_opts.auth_type, + global_remote_opts.remote_host_opts.auth_username, + global_remote_opts.remote_host_opts.auth_password, + &err, &err_str); + if (rlist == NULL && + (err == CANT_GET_INTERFACE_LIST || err == DONT_HAVE_PCAP)) { + QMessageBox::warning(this, tr("Error"), + (err == CANT_GET_INTERFACE_LIST?tr("No remote interfaces found."):tr("PCAP not found"))); + return; + } + if (ui->hostCombo->count() == 0) { + ui->hostCombo->addItem(""); + ui->hostCombo->addItem(host); + ui->hostCombo->insertSeparator(2); + ui->hostCombo->addItem(QString(tr("Clear list"))); + } else { + ui->hostCombo->insertItem(0, host); + } + struct remote_host *rh = recent_get_remote_host(host.toUtf8().constData()); + if (!rh) { + rh = (struct remote_host *)g_malloc (sizeof (*rh)); + rh->r_host = g_strdup((gchar *)host.toUtf8().constData()); + rh->remote_port = g_strdup((gchar *)port.toUtf8().constData()); + rh->auth_type = global_remote_opts.remote_host_opts.auth_type; + rh->auth_password = g_strdup(""); + rh->auth_username = g_strdup(""); + recent_add_remote_host(global_remote_opts.remote_host_opts.remote_host, rh); + } + emit remoteAdded(rlist, &global_remote_opts); +} + +void RemoteCaptureDialog::on_pwAuth_toggled(bool checked) +{ + if (checked) { + ui->userLabel->setEnabled(true); + ui->userText->setEnabled(true); + ui->pwLabel->setEnabled(true); + ui->pwText->setEnabled(true); + } +} + +void RemoteCaptureDialog::on_nullAuth_toggled(bool checked) +{ + if (checked) { + ui->userLabel->setEnabled(false); + ui->userText->setEnabled(false); + ui->pwLabel->setEnabled(false); + ui->pwText->setEnabled(false); + } +} +#endif /* HAVE_PCAP_REMOTE */ +// +// Editor modelines - http://www.wireshark.org/tools/modelines.html +// +// Local variables: +// c-basic-offset: 4 +// tab-width: 4 +// indent-tabs-mode: nil +// End: +// +// vi: set shiftwidth=4 tabstop=4 expandtab: +// :indentSize=4:tabSize=4:noTabs=true: +// |