summaryrefslogtreecommitdiffstats
path: root/ui/qt/remote_capture_dialog.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-09-19 04:14:33 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-09-19 04:14:33 +0000
commit9f153fbfec0fb9c9ce38e749a7c6f4a5e115d4e9 (patch)
tree2784370cda9bbf2da9114d70f05399c0b229d28c /ui/qt/remote_capture_dialog.cpp
parentAdding debian version 4.2.6-1. (diff)
downloadwireshark-9f153fbfec0fb9c9ce38e749a7c6f4a5e115d4e9.tar.xz
wireshark-9f153fbfec0fb9c9ce38e749a7c6f4a5e115d4e9.zip
Merging upstream version 4.4.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ui/qt/remote_capture_dialog.cpp')
-rw-r--r--ui/qt/remote_capture_dialog.cpp64
1 files changed, 38 insertions, 26 deletions
diff --git a/ui/qt/remote_capture_dialog.cpp b/ui/qt/remote_capture_dialog.cpp
index dff16527..f9a183b2 100644
--- a/ui/qt/remote_capture_dialog.cpp
+++ b/ui/qt/remote_capture_dialog.cpp
@@ -11,8 +11,8 @@
#include "config.h"
#ifdef HAVE_PCAP_REMOTE
-#include <glib.h>
#include <ui/qt/utils/qt_ui_utils.h>
+#include <ui/qt/utils/variant_pointer.h>
#include "ui/capture_globals.h"
#include "remote_capture_dialog.h"
#include <ui_remote_capture_dialog.h>
@@ -49,7 +49,11 @@ void RemoteCaptureDialog::hostChanged(const QString host)
recent_free_remote_host_list();
ui->hostCombo->clear();
} else {
- struct remote_host *rh = recent_get_remote_host(host.toUtf8().constData());
+ const struct remote_host *rh = nullptr;
+ int index = ui->hostCombo->findText(host);
+ if (index != -1) {
+ rh = VariantPointer<const struct remote_host>::asPtr(ui->hostCombo->itemData(index));
+ }
if (rh) {
ui->portText->setText(QString(rh->remote_port));
if (rh->auth_type == CAPTURE_AUTH_NULL) {
@@ -62,10 +66,11 @@ void RemoteCaptureDialog::hostChanged(const QString host)
}
-static void fillBox(gpointer key, gpointer, gpointer user_data)
+static void fillBox(void *value, void *user_data)
{
QComboBox *cb = (QComboBox *)user_data;
- cb->addItem(QString((gchar*)key));
+ struct remote_host* rh = (struct remote_host*)value;
+ cb->addItem(QString((char*)rh->r_host), VariantPointer<const struct remote_host>::asQVariant(rh));
}
void RemoteCaptureDialog::fillComboBox()
@@ -84,10 +89,13 @@ void RemoteCaptureDialog::fillComboBox()
void RemoteCaptureDialog::apply_remote()
{
int err;
- gchar *err_str;
+ char *err_str;
remote_options global_remote_opts;
QString host = ui->hostCombo->currentText();
+ if (host.isEmpty()) {
+ return;
+ }
global_remote_opts.src_type = CAPTURE_IFREMOTE;
global_remote_opts.remote_host_opts.remote_host = qstring_strdup(host);
QString port = ui->portText->text();
@@ -101,9 +109,9 @@ void RemoteCaptureDialog::apply_remote()
global_remote_opts.remote_host_opts.auth_username = qstring_strdup(user);
QString pw = ui->pwText->text();
global_remote_opts.remote_host_opts.auth_password = qstring_strdup(pw);
- global_remote_opts.remote_host_opts.datatx_udp = FALSE;
- global_remote_opts.remote_host_opts.nocap_rpcap = TRUE;
- global_remote_opts.remote_host_opts.nocap_local = FALSE;
+ global_remote_opts.remote_host_opts.datatx_udp = false;
+ global_remote_opts.remote_host_opts.nocap_rpcap = true;
+ global_remote_opts.remote_host_opts.nocap_local = false;
#ifdef HAVE_PCAP_SETSAMPLING
global_remote_opts.sampling_method = CAPTURE_SAMP_NONE;
global_remote_opts.sampling_param = 0;
@@ -126,24 +134,28 @@ void RemoteCaptureDialog::apply_remote()
QMessageBox::critical(this, tr("Error"), "Unknown error");
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 = qstring_strdup(host);
- rh->remote_port = qstring_strdup(port);
- 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);
- }
+
+ // Add the remote host even if it already exists, to update the port and
+ // auth type and move it to the front.
+ struct remote_host* rh;
+ rh = (struct remote_host *)g_malloc (sizeof (*rh));
+ rh->r_host = qstring_strdup(host);
+ rh->remote_port = qstring_strdup(port);
+ 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);
+
+ // We don't need to add the new entry to hostCombo since we only call
+ // this when accepting the dialog.
+
+ // Tell the parent ManageInterfacesDialog we added this.
+ // XXX: If the remote hostname already exists in ManageInterfacesDialog,
+ // this doesn't remove it. Most of the time it won't, but there is the
+ // corner case of a host existing with empty (hence default, 2002) port,
+ // and then adding it a second time explicitly starting port 2002.
+ // Someone could bind rpcapd to multiple ports on the same host for
+ // some reason too, I suppose.
emit remoteAdded(rlist, &global_remote_opts);
}