2015-07-09 23:00:14 +00:00
|
|
|
/* resolved_addresses_dialog.cpp
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2018-04-30 07:47:58 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2015-07-09 23:00:14 +00:00
|
|
|
|
|
|
|
#include "resolved_addresses_dialog.h"
|
2016-06-12 21:00:21 +00:00
|
|
|
#include <ui_resolved_addresses_dialog.h>
|
2015-07-09 23:00:14 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include "file.h"
|
|
|
|
|
|
|
|
#include "epan/addr_resolv.h"
|
2015-07-20 14:35:06 +00:00
|
|
|
#include <wiretap/wtap.h>
|
2015-07-09 23:00:14 +00:00
|
|
|
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QTextCursor>
|
2019-08-29 15:30:29 +00:00
|
|
|
#include <QSortFilterProxyModel>
|
2015-07-09 23:00:14 +00:00
|
|
|
|
|
|
|
#include "capture_file.h"
|
2022-02-01 03:30:09 +00:00
|
|
|
#include "main_application.h"
|
2015-07-09 23:00:14 +00:00
|
|
|
|
2019-08-29 15:30:29 +00:00
|
|
|
#include <ui/qt/models/astringlist_list_model.h>
|
|
|
|
#include <ui/qt/models/resolved_addresses_models.h>
|
2015-07-09 23:00:14 +00:00
|
|
|
|
|
|
|
const QString no_entries_ = QObject::tr("No entries.");
|
|
|
|
const QString entry_count_ = QObject::tr("%1 entries.");
|
|
|
|
|
2019-10-04 19:05:13 +00:00
|
|
|
ResolvedAddressesDialog::ResolvedAddressesDialog(QWidget *parent, QString captureFile, wtap* wth) :
|
2019-08-29 15:30:29 +00:00
|
|
|
GeometryStateDialog(parent),
|
2015-07-09 23:00:14 +00:00
|
|
|
ui(new Ui::ResolvedAddressesDialog),
|
|
|
|
file_name_(tr("[no file]"))
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2016-01-20 14:13:38 +00:00
|
|
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
2015-07-09 23:00:14 +00:00
|
|
|
|
|
|
|
QStringList title_parts = QStringList() << tr("Resolved Addresses");
|
|
|
|
|
2022-10-22 14:31:35 +00:00
|
|
|
if (!captureFile.isEmpty()) {
|
2019-10-04 19:05:13 +00:00
|
|
|
file_name_ = captureFile;
|
2015-07-09 23:00:14 +00:00
|
|
|
title_parts << file_name_;
|
|
|
|
}
|
2022-02-01 03:30:09 +00:00
|
|
|
setWindowTitle(mainApp->windowTitleString(title_parts));
|
2015-07-09 23:00:14 +00:00
|
|
|
|
2022-02-01 03:30:09 +00:00
|
|
|
ui->plainTextEdit->setFont(mainApp->monospaceFont());
|
2015-07-09 23:00:14 +00:00
|
|
|
ui->plainTextEdit->setReadOnly(true);
|
|
|
|
ui->plainTextEdit->setWordWrapMode(QTextOption::NoWrap);
|
|
|
|
|
2019-10-04 19:05:13 +00:00
|
|
|
if (wth) {
|
|
|
|
// might return null
|
|
|
|
wtap_block_t nrb_hdr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX - support multiple NRBs.
|
|
|
|
*/
|
|
|
|
nrb_hdr = wtap_file_get_nrb(wth);
|
|
|
|
if (nrb_hdr != NULL) {
|
|
|
|
char *str;
|
2016-07-14 23:01:57 +00:00
|
|
|
|
|
|
|
/*
|
2019-10-04 19:05:13 +00:00
|
|
|
* XXX - support multiple comments.
|
|
|
|
*/
|
|
|
|
if (wtap_block_get_nth_string_option_value(nrb_hdr, OPT_COMMENT, 0, &str) == WTAP_OPTTYPE_SUCCESS) {
|
|
|
|
comment_ = str;
|
2016-07-14 23:01:57 +00:00
|
|
|
}
|
2015-07-20 14:35:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-29 15:30:29 +00:00
|
|
|
fillBlocks();
|
2015-07-09 23:00:14 +00:00
|
|
|
|
2019-08-29 15:30:29 +00:00
|
|
|
ethSortModel = new AStringListListSortFilterProxyModel(this);
|
|
|
|
ethTypeModel = new AStringListListSortFilterProxyModel(this);
|
|
|
|
EthernetAddressModel * ethModel = new EthernetAddressModel(this);
|
2022-09-08 05:16:14 +00:00
|
|
|
ethSortModel->setSourceModel(ethModel);
|
2022-05-16 15:04:49 +00:00
|
|
|
ethSortModel->setColumnsToFilter(QList<int>() << 1 << 2);
|
2019-08-29 15:30:29 +00:00
|
|
|
ethSortModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
2022-09-08 05:16:14 +00:00
|
|
|
ethTypeModel->setSourceModel(ethSortModel);
|
2019-08-29 15:30:29 +00:00
|
|
|
ethTypeModel->setColumnToFilter(0);
|
|
|
|
ethTypeModel->setColumnToHide(0);
|
|
|
|
ui->tblAddresses->setModel(ethTypeModel);
|
|
|
|
ui->tblAddresses->resizeColumnsToContents();
|
|
|
|
ui->tblAddresses->horizontalHeader()->setStretchLastSection(true);
|
|
|
|
ui->tblAddresses->sortByColumn(1, Qt::AscendingOrder);
|
|
|
|
ui->cmbDataType->addItems(ethModel->filterValues());
|
|
|
|
|
|
|
|
portSortModel = new AStringListListSortFilterProxyModel(this);
|
|
|
|
portTypeModel = new AStringListListSortFilterProxyModel(this);
|
|
|
|
PortsModel * portModel = new PortsModel(this);
|
2022-09-08 05:16:14 +00:00
|
|
|
portSortModel->setSourceModel(portModel);
|
2019-08-29 15:30:29 +00:00
|
|
|
portSortModel->setColumnAsNumeric(1);
|
2022-05-16 15:04:49 +00:00
|
|
|
portSortModel->setColumnsToFilter(QList<int>() << 0 << 1);
|
2019-08-29 15:30:29 +00:00
|
|
|
portSortModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
2022-05-16 15:04:49 +00:00
|
|
|
portTypeModel->setSourceModel(portSortModel);
|
2022-09-08 05:16:14 +00:00
|
|
|
portTypeModel->setColumnToFilter(2);
|
|
|
|
portTypeModel->setColumnAsNumeric(1);
|
2019-08-29 15:30:29 +00:00
|
|
|
ui->tblPorts->setModel(portTypeModel);
|
|
|
|
ui->tblPorts->resizeColumnsToContents();
|
|
|
|
ui->tblPorts->horizontalHeader()->setStretchLastSection(true);
|
|
|
|
ui->tblPorts->sortByColumn(1, Qt::AscendingOrder);
|
|
|
|
ui->cmbPortFilterType->addItems(portModel->filterValues());
|
|
|
|
}
|
2015-07-09 23:00:14 +00:00
|
|
|
|
2019-08-29 15:30:29 +00:00
|
|
|
ResolvedAddressesDialog::~ResolvedAddressesDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
2015-07-09 23:00:14 +00:00
|
|
|
|
2022-09-08 05:16:14 +00:00
|
|
|
void ResolvedAddressesDialog::on_cmbDataType_currentIndexChanged(int index)
|
2019-08-29 15:30:29 +00:00
|
|
|
{
|
2019-11-17 19:02:20 +00:00
|
|
|
if (! ethSortModel)
|
2019-08-29 15:30:29 +00:00
|
|
|
return;
|
2015-07-09 23:00:14 +00:00
|
|
|
|
2022-09-08 05:16:14 +00:00
|
|
|
QString filter = ui->cmbDataType->itemText(index);
|
|
|
|
if (index == 0)
|
2019-08-29 15:30:29 +00:00
|
|
|
{
|
|
|
|
filter.clear();
|
|
|
|
ethTypeModel->setFilterType(AStringListListSortFilterProxyModel::FilterNone, 0);
|
2015-07-09 23:00:14 +00:00
|
|
|
}
|
2019-08-29 15:30:29 +00:00
|
|
|
else
|
|
|
|
ethTypeModel->setFilterType(AStringListListSortFilterProxyModel::FilterByEquivalent, 0);
|
|
|
|
ethTypeModel->setFilter(filter);
|
|
|
|
}
|
2015-07-09 23:00:14 +00:00
|
|
|
|
2019-08-29 15:30:29 +00:00
|
|
|
void ResolvedAddressesDialog::on_txtSearchFilter_textChanged(QString)
|
|
|
|
{
|
2020-02-04 13:51:51 +00:00
|
|
|
QString filter = ui->txtSearchFilter->text();
|
|
|
|
if (!ethSortModel || (!filter.isEmpty() && filter.length() < 3))
|
2019-08-29 15:30:29 +00:00
|
|
|
return;
|
2015-07-09 23:00:14 +00:00
|
|
|
|
2020-02-04 13:51:51 +00:00
|
|
|
ethSortModel->setFilter(filter);
|
2015-07-09 23:00:14 +00:00
|
|
|
}
|
|
|
|
|
2022-09-08 05:16:14 +00:00
|
|
|
void ResolvedAddressesDialog::on_cmbPortFilterType_currentIndexChanged(int index)
|
2015-07-09 23:00:14 +00:00
|
|
|
{
|
2019-11-17 19:02:20 +00:00
|
|
|
if (! portSortModel)
|
2019-08-29 15:30:29 +00:00
|
|
|
return;
|
|
|
|
|
2022-09-08 05:16:14 +00:00
|
|
|
QString filter = ui->cmbPortFilterType->itemText(index);
|
|
|
|
if (index == 0)
|
2019-08-29 15:30:29 +00:00
|
|
|
{
|
|
|
|
filter.clear();
|
|
|
|
portTypeModel->setFilterType(AStringListListSortFilterProxyModel::FilterNone, 2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
portTypeModel->setFilterType(AStringListListSortFilterProxyModel::FilterByEquivalent, 2);
|
|
|
|
portTypeModel->setFilter(filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResolvedAddressesDialog::on_txtPortFilter_textChanged(QString val)
|
|
|
|
{
|
2019-11-17 19:02:20 +00:00
|
|
|
if (! portSortModel)
|
2019-08-29 15:30:29 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
portSortModel->setFilter(val);
|
2015-07-09 23:00:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResolvedAddressesDialog::changeEvent(QEvent *event)
|
|
|
|
{
|
|
|
|
if (0 != event)
|
|
|
|
{
|
|
|
|
switch (event->type())
|
|
|
|
{
|
|
|
|
case QEvent::LanguageChange:
|
|
|
|
ui->retranslateUi(this);
|
|
|
|
fillBlocks();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QDialog::changeEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResolvedAddressesDialog::fillBlocks()
|
|
|
|
{
|
|
|
|
setUpdatesEnabled(false);
|
|
|
|
ui->plainTextEdit->clear();
|
|
|
|
|
|
|
|
QString lines;
|
|
|
|
ui->plainTextEdit->appendPlainText(tr("# Resolved addresses found in %1").arg(file_name_));
|
|
|
|
|
2015-07-20 14:35:06 +00:00
|
|
|
if (ui->actionComment->isChecked()) {
|
|
|
|
lines = "\n";
|
|
|
|
lines.append(tr("# Comments\n#\n# "));
|
|
|
|
if (!comment_.isEmpty()) {
|
|
|
|
lines.append("\n\n");
|
|
|
|
lines.append(comment_);
|
|
|
|
lines.append("\n");
|
|
|
|
} else {
|
|
|
|
lines.append(no_entries_);
|
|
|
|
}
|
|
|
|
ui->plainTextEdit->appendPlainText(lines);
|
|
|
|
}
|
|
|
|
|
2015-07-09 23:00:14 +00:00
|
|
|
ui->plainTextEdit->moveCursor(QTextCursor::Start);
|
|
|
|
setUpdatesEnabled(true);
|
|
|
|
}
|