From 363014345b4e824a979cc85446f0f517298753b9 Mon Sep 17 00:00:00 2001 From: gongheng Date: Fri, 1 Aug 2025 09:23:39 +0800 Subject: [PATCH] fix: [Net-Wakeup] The net card can not wakeup. -- Code Logic error, "sizeof(logicalName::toStdString().c_str())" always return 8, not the length of logicalName. -- So, When the length more than 8, the net card will can not find. Log: fix issue Bug: https://pms.uniontech.com/bug-view-326565.html --- .../src/wakecontrol/wakeuputils.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/deepin-devicemanager-server/deepin-devicecontrol/src/wakecontrol/wakeuputils.cpp b/deepin-devicemanager-server/deepin-devicecontrol/src/wakecontrol/wakeuputils.cpp index 186c7ba39..d3a9ad613 100644 --- a/deepin-devicemanager-server/deepin-devicecontrol/src/wakecontrol/wakeuputils.cpp +++ b/deepin-devicemanager-server/deepin-devicecontrol/src/wakecontrol/wakeuputils.cpp @@ -117,7 +117,12 @@ WakeupUtils::EthStatus WakeupUtils::wakeOnLanIsOpen(const QString &logicalName) struct ifreq ifr; struct ethtool_wolinfo wolinfo; memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, logicalName.toStdString().c_str(), sizeof(logicalName.toStdString().c_str())); + memset(&wolinfo, 0, sizeof(wolinfo)); + + QByteArray nameBytes = logicalName.toLocal8Bit(); + strncpy(ifr.ifr_name, nameBytes.constData(), IFNAMSIZ - 1); + ifr.ifr_name[IFNAMSIZ - 1] = '\0'; + wolinfo.cmd = ETHTOOL_GWOL; ifr.ifr_data = reinterpret_cast(&wolinfo); if (0 != ioctl(fd, SIOCETHTOOL, &ifr)) { @@ -147,7 +152,12 @@ bool WakeupUtils::setWakeOnLan(const QString &logicalName, bool open) struct ifreq ifr; struct ethtool_wolinfo wolinfo; memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, logicalName.toStdString().c_str(), sizeof(logicalName.toStdString().c_str())); + memset(&wolinfo, 0, sizeof(wolinfo)); + + QByteArray nameBytes = logicalName.toLocal8Bit(); + strncpy(ifr.ifr_name, nameBytes.constData(), IFNAMSIZ - 1); + ifr.ifr_name[IFNAMSIZ - 1] = '\0'; + wolinfo.cmd = ETHTOOL_SWOL; if (open) wolinfo.wolopts = 0 | WAKE_MAGIC;