summaryrefslogtreecommitdiff
path: root/ui/qt/compiled_filter_output.cpp
diff options
context:
space:
mode:
authorIrene Ruengeler <ruengeler@wireshark.org>2014-06-04 11:03:59 +0200
committerAnders Broman <a.broman58@gmail.com>2014-06-12 05:54:59 +0000
commitdf8c4bf2644d39d66613868256d918346d56aef8 (patch)
treeb0a04ebc37a508598b5e49652ebe83219fff47c2 /ui/qt/compiled_filter_output.cpp
parent428c5b9448a510da1d8bc903f59364ef830585ac (diff)
downloadwireshark-df8c4bf2644d39d66613868256d918346d56aef8.tar.gz
Capture Interfaces Dialog:
- allow to change the interface options in the table - save the options to preferences when the dialog is left - add a field for setting a capture filter for all selected interfaces - add a "Compile BPF" button and a window to show the compiled filter output - try to address Alexis' and Evan's comments Change-Id: Ic1272e29183ec80e2d2f4b3e494c79dabe2c3b6f Reviewed-on: https://code.wireshark.org/review/1946 Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com> Tested-by: Alexis La Goutte <alexis.lagoutte@gmail.com> Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'ui/qt/compiled_filter_output.cpp')
-rw-r--r--ui/qt/compiled_filter_output.cpp115
1 files changed, 115 insertions, 0 deletions
diff --git a/ui/qt/compiled_filter_output.cpp b/ui/qt/compiled_filter_output.cpp
new file mode 100644
index 0000000000..63265cd450
--- /dev/null
+++ b/ui/qt/compiled_filter_output.cpp
@@ -0,0 +1,115 @@
+/* compiled_filter_output.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 "ui_compiled_filter_output.h"
+#include "compiled_filter_output.h"
+
+#include "capture_opts.h"
+#include "wtap.h"
+#include <pcap.h>
+#include "ui/capture_globals.h"
+
+CompiledFilterOutput::CompiledFilterOutput(QWidget *parent, QStringList *intList, QString &compile_filter) :
+ QDialog(parent),
+ intList_(intList),
+ compile_filter_(compile_filter),
+ ui(new Ui::CompiledFilterOutput)
+{
+ ui->setupUi(this);
+
+ interface_list_ = ui->interfaceList;
+#if GLIB_CHECK_VERSION(2,31,0)
+ pcap_compile_mtx = g_new(GMutex,1);
+ g_mutex_init(pcap_compile_mtx);
+#else
+ pcap_compile_mtx = g_mutex_new();
+#endif
+ compileFilter();
+ connect(interface_list_, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(compile_clicked(QListWidgetItem*, QListWidgetItem*)));
+}
+
+CompiledFilterOutput::~CompiledFilterOutput()
+{
+ delete ui;
+}
+
+
+void CompiledFilterOutput::compileFilter()
+{
+ struct bpf_program fcode;
+
+ foreach (QString interfaces, *intList_) {
+ 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 (interfaces.compare(device.display_name)) {
+ continue;
+ } else {
+ pcap_t *pd = pcap_open_dead(device.active_dlt, WTAP_MAX_PACKET_SIZE);
+ g_mutex_lock(pcap_compile_mtx);
+ if (pcap_compile(pd, &fcode, compile_filter_.toUtf8().constData(), 1, 0) < 0) {
+ compile_results.insert(interfaces, QString("%1").arg(g_strdup(pcap_geterr(pd))));
+ g_mutex_unlock(pcap_compile_mtx);
+ ui->interfaceList->addItem(new QListWidgetItem(QIcon(":expert/expert_error.png"),interfaces));
+ } else {
+ GString *bpf_code_dump = g_string_new("");
+ struct bpf_insn *insn = fcode.bf_insns;
+ int ii, n = fcode.bf_len;
+ gchar *bpf_code_str;
+ for (ii = 0; ii < n; ++insn, ++ii) {
+ g_string_append(bpf_code_dump, bpf_image(insn, ii));
+ g_string_append(bpf_code_dump, "\n");
+ }
+ bpf_code_str = g_string_free(bpf_code_dump, FALSE);
+ g_mutex_unlock(pcap_compile_mtx);
+ compile_results.insert(interfaces, QString("%1").arg(g_strdup(bpf_code_str)));
+ ui->interfaceList->addItem(new QListWidgetItem(QIcon(":expert/expert_ok.png"),interfaces));
+ }
+ break;
+ }
+ }
+ }
+}
+
+
+void CompiledFilterOutput::compile_clicked(QListWidgetItem *current, QListWidgetItem *previous)
+{
+ Q_UNUSED(previous);
+
+ QString interface = current->text();
+ QHash<QString, QString>::const_iterator iter = compile_results.find(interface);
+ ui->filterList->clear();
+ ui->filterList->setText(iter.value());
+}
+
+//
+// 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:
+//