fix: NetworkMonitor virtual sorting
fixes: #9459 make NetworkMonitor::isVirtualInterface a static member of NetworkMonitor write tests for NetworkMonitor
This commit is contained in:
parent
9dc76c1caf
commit
f9857e102a
5 changed files with 74 additions and 25 deletions
|
|
@ -9,31 +9,20 @@
|
||||||
#include <QAbstractSocket>
|
#include <QAbstractSocket>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QNetworkInterface>
|
#include <QNetworkInterface>
|
||||||
|
#include <QRegularExpression>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
namespace deskflow::gui {
|
namespace deskflow::gui {
|
||||||
|
|
||||||
bool NetworkMonitor::isVirtualInterface(const QString &interfaceName) const
|
bool NetworkMonitor::isVirtualInterface(const QString &interfaceName)
|
||||||
{
|
{
|
||||||
// Common virtual network interface patterns
|
// Common virtual network interface patterns
|
||||||
static const QStringList virtualPatterns = {
|
static const auto virtualRegEx = QRegularExpression(
|
||||||
QStringLiteral("vboxnet"), // VirtualBox host-only networks
|
QStringLiteral("^vboxnet|vmnet|docker|virbr|veth|br\\-|tun|utun|awdl|p2p|llw|anpi|tap"),
|
||||||
QStringLiteral("vmnet"), // VMware virtual networks
|
QRegularExpression::CaseInsensitiveOption
|
||||||
QStringLiteral("docker"), // Docker bridge networks
|
);
|
||||||
QStringLiteral("virbr"), // libvirt bridge networks
|
return virtualRegEx.match(interfaceName).hasMatch();
|
||||||
QStringLiteral("veth"), // Virtual ethernet
|
|
||||||
QStringLiteral("br-"), // Bridge interfaces (some are virtual)
|
|
||||||
QStringLiteral("tun"), // Tunnel interfaces
|
|
||||||
QStringLiteral("tap"), // TAP interfaces
|
|
||||||
QStringLiteral("utun"), // User tunnel (macOS)
|
|
||||||
QStringLiteral("awdl"), // Apple Wireless Direct Link
|
|
||||||
QStringLiteral("p2p"), // Peer-to-peer
|
|
||||||
QStringLiteral("llw"), // Link-local wireless
|
|
||||||
QStringLiteral("anpi"), // Apple network interface
|
|
||||||
};
|
|
||||||
|
|
||||||
return virtualPatterns.contains(interfaceName, Qt::CaseInsensitive);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkMonitor::NetworkMonitor(QObject *parent) : QObject(parent), m_checkTimer(new QTimer(this))
|
NetworkMonitor::NetworkMonitor(QObject *parent) : QObject(parent), m_checkTimer(new QTimer(this))
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,13 @@ public:
|
||||||
*/
|
*/
|
||||||
QStringList getAvailableIPv4Addresses() const;
|
QStringList getAvailableIPv4Addresses() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check if a network interface is virtual
|
||||||
|
* @param interfaceName Network interface name
|
||||||
|
* @return true if it's a virtual interface
|
||||||
|
*/
|
||||||
|
static bool isVirtualInterface(const QString &interfaceName);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
/**
|
/**
|
||||||
* @brief Emitted when IP addresses change
|
* @brief Emitted when IP addresses change
|
||||||
|
|
@ -62,13 +69,6 @@ Q_SIGNALS:
|
||||||
private:
|
private:
|
||||||
void setIpAddresses(const QStringList &newAddresses);
|
void setIpAddresses(const QStringList &newAddresses);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Check if a network interface is virtual
|
|
||||||
* @param interfaceName Network interface name
|
|
||||||
* @return true if it's a virtual interface
|
|
||||||
*/
|
|
||||||
bool isVirtualInterface(const QString &interfaceName) const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Update current network status
|
* @brief Update current network status
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -14,3 +14,12 @@ create_test(
|
||||||
SOURCE ServerConnectionTests.cpp
|
SOURCE ServerConnectionTests.cpp
|
||||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/gui"
|
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/gui"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
create_test(
|
||||||
|
NAME NetworkMonitorTests
|
||||||
|
DEPENDS gui
|
||||||
|
SOURCE NetworkMonitorTests.cpp
|
||||||
|
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/gui"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
|
||||||
36
src/unittests/gui/core/NetworkMonitorTests.cpp
Normal file
36
src/unittests/gui/core/NetworkMonitorTests.cpp
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* Deskflow -- mouse and keyboard sharing utility
|
||||||
|
* SPDX-FileCopyrightText: (C) 2026 Chris Rizzitello <sithlord48@gmail.com>
|
||||||
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "NetworkMonitorTests.h"
|
||||||
|
|
||||||
|
#include "gui/core/NetworkMonitor.h"
|
||||||
|
|
||||||
|
#include <QSignalSpy>
|
||||||
|
|
||||||
|
using namespace deskflow::gui;
|
||||||
|
void NetworkMonitorTests::testVirtualInterface()
|
||||||
|
{
|
||||||
|
QVERIFY(NetworkMonitor::isVirtualInterface(QStringLiteral("vboxnet0")));
|
||||||
|
QVERIFY(NetworkMonitor::isVirtualInterface(QStringLiteral("vboXnet0")));
|
||||||
|
QVERIFY(NetworkMonitor::isVirtualInterface(QStringLiteral("vmnet0")));
|
||||||
|
QVERIFY(NetworkMonitor::isVirtualInterface(QStringLiteral("docker-bridge")));
|
||||||
|
QVERIFY(NetworkMonitor::isVirtualInterface(QStringLiteral("virbr0")));
|
||||||
|
QVERIFY(NetworkMonitor::isVirtualInterface(QStringLiteral("veth0")));
|
||||||
|
QVERIFY(NetworkMonitor::isVirtualInterface(QStringLiteral("br-0")));
|
||||||
|
QVERIFY(NetworkMonitor::isVirtualInterface(QStringLiteral("tun0")));
|
||||||
|
QVERIFY(NetworkMonitor::isVirtualInterface(QStringLiteral("utun0")));
|
||||||
|
QVERIFY(NetworkMonitor::isVirtualInterface(QStringLiteral("awdl0")));
|
||||||
|
QVERIFY(NetworkMonitor::isVirtualInterface(QStringLiteral("p2p0")));
|
||||||
|
QVERIFY(NetworkMonitor::isVirtualInterface(QStringLiteral("llw0")));
|
||||||
|
QVERIFY(NetworkMonitor::isVirtualInterface(QStringLiteral("anpi5")));
|
||||||
|
QVERIFY(NetworkMonitor::isVirtualInterface(QStringLiteral("tap1")));
|
||||||
|
|
||||||
|
QVERIFY(!NetworkMonitor::isVirtualInterface(QStringLiteral("eth0")));
|
||||||
|
QVERIFY(!NetworkMonitor::isVirtualInterface(QStringLiteral("enp0s0f")));
|
||||||
|
QVERIFY(!NetworkMonitor::isVirtualInterface(QStringLiteral("wifi")));
|
||||||
|
QVERIFY(!NetworkMonitor::isVirtualInterface(QStringLiteral("wlan0")));
|
||||||
|
}
|
||||||
|
QTEST_MAIN(NetworkMonitorTests)
|
||||||
15
src/unittests/gui/core/NetworkMonitorTests.h
Normal file
15
src/unittests/gui/core/NetworkMonitorTests.h
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
/*
|
||||||
|
* Deskflow -- mouse and keyboard sharing utility
|
||||||
|
* SPDX-FileCopyrightText: (C) 2026 Chris Rizzitello <sithlord48@gmail.com>
|
||||||
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <QTest>
|
||||||
|
|
||||||
|
class NetworkMonitorTests : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
private Q_SLOTS:
|
||||||
|
// Test are run in order top to bottom
|
||||||
|
void testVirtualInterface();
|
||||||
|
};
|
||||||
Loading…
Reference in a new issue