diff options
author | Steffen Ritter | 2016-11-15 17:11:15 +0100 |
---|---|---|
committer | Steffen Ritter | 2016-11-15 17:16:39 +0100 |
commit | 44d5db857e98b41c2994d05f0b8ec5aca0d82f34 (patch) | |
tree | 43abd5234f9f371f00c69c481dfd9265be79b7ae /src/client | |
parent | Increase compiler warnings, fix a lot of those instances (diff) | |
download | pvs2-44d5db857e98b41c2994d05f0b8ec5aca0d82f34.tar.gz pvs2-44d5db857e98b41c2994d05f0b8ec5aca0d82f34.tar.xz pvs2-44d5db857e98b41c2994d05f0b8ec5aca0d82f34.zip |
[client] Nicer output of ip addresses under system information
* show interface name, ipv4, ipv6, mac
* filter loopback interface
* filter interfaces which are connected to a bridge
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/informationdialog/informationdialog.cpp | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/src/client/informationdialog/informationdialog.cpp b/src/client/informationdialog/informationdialog.cpp index 275259b..fb3e87c 100644 --- a/src/client/informationdialog/informationdialog.cpp +++ b/src/client/informationdialog/informationdialog.cpp @@ -1,6 +1,8 @@ #include "informationdialog.h" #include <QNetworkInterface> #include <QHostInfo> +#include <QDir> +#include <QDirIterator> InformationDialog::InformationDialog() : QDialog() { @@ -28,17 +30,47 @@ void InformationDialog::initTable() { /* NETWORK*/ /* hostnames */ - _tableLayout->addRow(new QLabel(tr("hostname")), new QLabel(QHostInfo::localHostName())); + _tableLayout->addRow(new QLabel("<b>" + tr("hostname") + "</b>"), new QLabel(QHostInfo::localHostName())); /* ips */ - for (QHostAddress a : QNetworkInterface::allAddresses()) { - if (a == QHostAddress::Null || a == QHostAddress::Broadcast || a == QHostAddress::LocalHost || a == QHostAddress::AnyIPv6) + QStringList interfaceFilter; + QString bridgeDevicePath("/sys/devices/virtual/net/"); + QDirIterator it(bridgeDevicePath, QStringList() << "brif", QDir::Dirs, QDirIterator::Subdirectories); + while (it.hasNext()) { + it.next(); + QDir dir = it.filePath(); + dir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot); + interfaceFilter += dir.entryList(); + } + + for (QNetworkInterface interface : QNetworkInterface::allInterfaces()) { + + if (interfaceFilter.contains(interface.name()) || interface.flags().testFlag(QNetworkInterface::IsLoopBack)) { + qDebug() << "interface filtered: " << interface.name(); continue; + } + + _tableLayout->addRow("<u><b>" + interface.name() + "</b></u>", new QLabel("")); + + for (QNetworkAddressEntry entry : interface.addressEntries()) { + QLabel* label; + QLabel* value; + QHostAddress hostAddr = entry.ip(); + + if (hostAddr == QHostAddress::Null || hostAddr == QHostAddress::Broadcast || hostAddr == QHostAddress::LocalHost + || hostAddr == QHostAddress::AnyIPv6) + continue; - QString ip = a.toString(); + if (hostAddr.protocol() == QAbstractSocket::IPv6Protocol) { + label = new QLabel("IPv6"); + value = new QLabel(hostAddr.toString().split("%").first()); + } else { + label = new QLabel("IPv4"); + value = new QLabel(hostAddr.toString()); + } - QLabel* label = new QLabel(tr("IP") ); - QLabel* value = new QLabel(ip); - _tableLayout->addRow(label, value); + _tableLayout->addRow(label, value); + } + _tableLayout->addRow("MAC", new QLabel(interface.hardwareAddress())); } /* TODO: Add other information */ |