Skip to content

Commit 95f588d

Browse files
committed
fix(network): filter virtual network interfaces correctly on Windows
Fix data migration failure when multiple network adapters exist, including virtual adapters like VMware Network Adapter VMnet1. On Windows, virtual adapter names in QNetworkInterface::name() are GUIDs, not "vmnet*", so the previous filter failed to exclude them, causing the app to select the wrong IP address (e.g., 192.168.199.1 instead of the real WLAN IP 192.168.43.204). Changes: - Add isVirtualInterface() helper to check both name() and humanReadableName() - Linux: filter virbr*, vmnet*, docker*, veth*, br- prefixes - Windows: filter VMware, VirtualBox, Hyper-V, Virtual Ethernet, vEthernet, Bluetooth This ensures the sender advertises the correct IP address and the web server binds to a reachable network interface, preventing 0B file transfers.
1 parent 930da60 commit 95f588d

2 files changed

Lines changed: 45 additions & 9 deletions

File tree

src/common/commonutils.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,27 @@ using namespace deepin_cross;
2424
#define WEB_MIN_PORT 13628
2525
#define WEB_MAX_PORT 23628
2626

27+
static bool isVirtualInterface(const QNetworkInterface &netInterface)
28+
{
29+
QString name = netInterface.name().toLower();
30+
if (name.startsWith("virbr") || name.startsWith("vmnet")
31+
|| name.startsWith("docker") || name.startsWith("veth")
32+
|| name.startsWith("br-")) {
33+
qInfo() << "Filtering virtual interface (by name):" << netInterface.name();
34+
return true;
35+
}
36+
37+
QString humanName = netInterface.humanReadableName().toLower();
38+
if (humanName.contains("vmware") || humanName.contains("virtualbox")
39+
|| humanName.contains("hyper-v") || humanName.contains("virtual ethernet")
40+
|| humanName.contains("vethernet") || humanName.contains("bluetooth")) {
41+
qInfo() << "Filtering virtual interface (by humanReadableName):" << netInterface.humanReadableName();
42+
return true;
43+
}
44+
45+
return false;
46+
}
47+
2748
std::string CommonUitls::getFirstIp()
2849
{
2950
qInfo() << "Getting first available IP address";
@@ -38,10 +59,7 @@ std::string CommonUitls::getFirstIp()
3859
continue;
3960
}
4061

41-
if (netInterface.name().startsWith("virbr") || netInterface.name().startsWith("vmnet")
42-
|| netInterface.name().startsWith("docker")) {
43-
// 跳过桥接,虚拟机和docker的网络接口
44-
qInfo() << "netInterface name:" << netInterface.name();
62+
if (isVirtualInterface(netInterface)) {
4563
continue;
4664
}
4765

@@ -52,7 +70,7 @@ std::string CommonUitls::getFirstIp()
5270
if (entry.ip().protocol() == QAbstractSocket::IPv4Protocol && entry.ip() != QHostAddress::LocalHost) {
5371
//IP地址
5472
ip = QString(entry.ip().toString());
55-
qInfo() << "Found available IP: " << ip;
73+
qInfo() << "Found available IP: " << ip << "on interface:" << netInterface.name();
5674
return ip.toStdString();
5775
}
5876
}

src/compat/common/commonutils.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@ static constexpr char kApp1[] { "dde-cooperation" };
2323
static constexpr char kApp2[] { "deepin-data-transfer" };
2424
static constexpr char kDaemon[] { "cooperation-daemon" };
2525

26+
static bool isVirtualInterface(const QNetworkInterface &netInterface)
27+
{
28+
QString name = netInterface.name().toLower();
29+
if (name.startsWith("virbr") || name.startsWith("vmnet")
30+
|| name.startsWith("docker") || name.startsWith("veth")
31+
|| name.startsWith("br-")) {
32+
qInfo() << "Filtering virtual interface (by name):" << netInterface.name();
33+
return true;
34+
}
35+
36+
QString humanName = netInterface.humanReadableName().toLower();
37+
if (humanName.contains("vmware") || humanName.contains("virtualbox")
38+
|| humanName.contains("hyper-v") || humanName.contains("virtual ethernet")
39+
|| humanName.contains("vethernet") || humanName.contains("bluetooth")) {
40+
qInfo() << "Filtering virtual interface (by humanReadableName):" << netInterface.humanReadableName();
41+
return true;
42+
}
43+
44+
return false;
45+
}
46+
2647
std::string CommonUitls::getFirstIp()
2748
{
2849
QString ip;
@@ -35,10 +56,7 @@ std::string CommonUitls::getFirstIp()
3556
continue;
3657
}
3758

38-
if (netInterface.name().startsWith("virbr") || netInterface.name().startsWith("vmnet")
39-
|| netInterface.name().startsWith("docker")) {
40-
// 跳过桥接,虚拟机和docker的网络接口
41-
qInfo() << "netInterface name:" << netInterface.name();
59+
if (isVirtualInterface(netInterface)) {
4260
continue;
4361
}
4462

0 commit comments

Comments
 (0)