1 /* remote_capture_dialog.cpp
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 // XXX This shouldn't exist. These controls should be in ManageInterfacesDialog instead.
25 #ifdef HAVE_PCAP_REMOTE
27 #include "qt_ui_utils.h"
28 #include "ui/capture_globals.h"
29 #include "remote_capture_dialog.h"
30 #include <ui_remote_capture_dialog.h>
31 #include "capture_opts.h"
32 #include "caputils/capture-pcap-util.h"
33 #include "ui/capture_ui_utils.h"
34 #include "epan/prefs.h"
35 #include "epan/to_str.h"
36 #include "ui/ui_util.h"
37 #include "ui/recent.h"
39 #include <QMessageBox>
41 static guint num_selected = 0;
43 RemoteCaptureDialog::RemoteCaptureDialog(QWidget *parent) :
45 ui(new Ui::RemoteCaptureDialog)
50 connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(apply_remote()));
51 connect(this, SIGNAL(remoteAdded(GList *, remote_options*)), parent, SIGNAL(remoteAdded(GList *, remote_options*)));
52 connect(ui->hostCombo, SIGNAL(currentIndexChanged(QString)), this, SLOT(hostChanged(QString)));
55 RemoteCaptureDialog::~RemoteCaptureDialog()
60 void RemoteCaptureDialog::hostChanged(QString host)
62 if (!host.compare(tr("Clear list"))) {
63 free_remote_host_list();
64 ui->hostCombo->clear();
66 struct remote_host *rh = recent_get_remote_host(host.toUtf8().constData());
68 ui->portText->setText(QString(rh->remote_port));
69 if (rh->auth_type == CAPTURE_AUTH_NULL) {
70 ui->nullAuth->setChecked(true);
72 ui->pwAuth->setChecked(true);
79 static void fillBox(gpointer key, gpointer, gpointer)
81 QComboBox *cb = (QComboBox *)user_data;
82 cb->addItem(QString((gchar*)key));
85 void RemoteCaptureDialog::fillComboBox()
87 GHashTable *ht = get_remote_host_list();
88 ui->hostCombo->addItem(QString(""));
89 if (g_hash_table_size(ht) > 0) {
90 g_hash_table_foreach(ht, fillBox, ui->hostCombo);
91 ui->hostCombo->insertSeparator(g_hash_table_size(ht)+1);
92 ui->hostCombo->addItem(QString(tr("Clear list")));
96 void RemoteCaptureDialog::apply_remote()
100 remote_options global_remote_opts;
102 QString host = ui->hostCombo->currentText();
103 global_remote_opts.src_type = CAPTURE_IFREMOTE;
104 global_remote_opts.remote_host_opts.remote_host = qstring_strdup(host);
105 QString port = ui->portText->text();
106 global_remote_opts.remote_host_opts.remote_port = qstring_strdup(port);
107 if (ui->pwAuth->isChecked()) {
108 global_remote_opts.remote_host_opts.auth_type = CAPTURE_AUTH_PWD;
110 global_remote_opts.remote_host_opts.auth_type = CAPTURE_AUTH_NULL;
112 QString user = ui->userText->text();
113 global_remote_opts.remote_host_opts.auth_username = qstring_strdup(user);
114 QString pw = ui->pwText->text();
115 global_remote_opts.remote_host_opts.auth_password = qstring_strdup(pw);
116 GList *rlist = get_remote_interface_list(global_remote_opts.remote_host_opts.remote_host,
117 global_remote_opts.remote_host_opts.remote_port,
118 global_remote_opts.remote_host_opts.auth_type,
119 global_remote_opts.remote_host_opts.auth_username,
120 global_remote_opts.remote_host_opts.auth_password,
123 (err == CANT_GET_INTERFACE_LIST || err == DONT_HAVE_PCAP)) {
124 QMessageBox::warning(this, tr("Error"),
125 (err == CANT_GET_INTERFACE_LIST?tr("No remote interfaces found."):tr("PCAP not found")));
128 if (ui->hostCombo->count() == 0) {
129 ui->hostCombo->addItem("");
130 ui->hostCombo->addItem(host);
131 ui->hostCombo->insertSeparator(2);
132 ui->hostCombo->addItem(QString(tr("Clear list")));
134 ui->hostCombo->insertItem(0, host);
136 struct remote_host *rh = recent_get_remote_host(host.toUtf8().constData());
138 rh = (struct remote_host *)g_malloc (sizeof (*rh));
139 rh->r_host = qstring_strdup(host);
140 rh->remote_port = qstring_strdup(port);
141 rh->auth_type = global_remote_opts.remote_host_opts.auth_type;
142 rh->auth_password = g_strdup("");
143 rh->auth_username = g_strdup("");
144 recent_add_remote_host(global_remote_opts.remote_host_opts.remote_host, rh);
146 emit remoteAdded(rlist, &global_remote_opts);
149 void RemoteCaptureDialog::on_pwAuth_toggled(bool checked)
152 ui->userLabel->setEnabled(true);
153 ui->userText->setEnabled(true);
154 ui->pwLabel->setEnabled(true);
155 ui->pwText->setEnabled(true);
159 void RemoteCaptureDialog::on_nullAuth_toggled(bool checked)
162 ui->userLabel->setEnabled(false);
163 ui->userText->setEnabled(false);
164 ui->pwLabel->setEnabled(false);
165 ui->pwText->setEnabled(false);
168 #endif /* HAVE_PCAP_REMOTE */
176 * indent-tabs-mode: nil
179 * ex: set shiftwidth=4 tabstop=8 expandtab:
180 * :indentSize=4:tabSize=8:noTabs=true: