Fix: There is no method to check ipv6 conflict.

修复无Ipv6地址检测的Bug
Link:http://172.17.66.192/biz/bug-view-39031.html
This commit is contained in:
zhangjiaping 2021-04-22 14:32:38 +08:00
parent 7cbc2f7884
commit 0ae784318c
6 changed files with 84 additions and 11 deletions

View File

@ -494,18 +494,72 @@ bool ConfForm::check_ip_conflict(QString ifname)
ret[strlen(ret)-1]=0;
if ( ret != NULL ) {
if (!strcmp(ret,"0")) {
//printf("正常连接");
return false;
} else {
//printf("ip地址冲突");
QString strInfo = tr("IP address conflict, Please change IP");
QString buffer = "notify-send -i network-offline " + strInfo;
// if (!strcmp(ret,"0")) {
// //printf("正常连接");
// return false;
// } else {
if (strcmp(ret,"0")) {
//printf("ipv4地址冲突");
QString strInfo = tr("IPV4 address conflict, Please change IP");
// QString buffer = "notify-send -i network-offline " + strInfo;
showNotify(strInfo);
return true;
}
}
}
if (ui->leAddr_ipv6->text().isEmpty() || ui->leAddr_ipv6->text() == "") {
//未配置ipv6地址跳过ipv6地址冲突检测
return false;
}
isIpv6Conflict = false;
QProcess * process = new QProcess;
if (this->isActWifi) {
//指定无线网卡检测
process->start(QString("ping6 %1%%2").arg(ui->leAddr_ipv6->text()).arg(wcard));
} else {
//指定有线网卡检测
process->start(QString("ping6 %1%%2").arg(ui->leAddr_ipv6->text()).arg(lcard));
}
connect(process, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), this, [ = ]() {
process->deleteLater();
});
connect(process, &QProcess::readyReadStandardOutput, this, [ = ]() {
QString str = process->readAllStandardOutput();
if (!str.contains("PING")) {
if (str.contains("unreachable")) {
isIpv6Conflict = false;
} else {
//如果能ping通需要看是不是当前本机连接的ipv6地址如果是本机连接的也不算冲突
if (this->isActWifi) {
if (ui->leAddr_ipv6->text() == actWifiIpv6Addr) {
//新地址与当前本机连接的wifi的ipv6地址一直不算冲突
isIpv6Conflict = false;
} else {
isIpv6Conflict = true;
}
} else {
if (ui->leAddr_ipv6->text() == actLanIpv6Addr) {
//新地址与当前本机连接的有线的ipv6地址一直不算冲突
isIpv6Conflict = false;
} else {
isIpv6Conflict = true;
}
}
}
process->close();
}
});
connect(process, &QProcess::readyReadStandardError, this, [ = ]() {
isIpv6Conflict = false;
process->close();
});
process->waitForFinished();
if (isIpv6Conflict) {
//printf("ipv6地址冲突");
QString strInfo = tr("IPV6 address conflict, Please change IP");
showNotify(strInfo);
return true;
}
//printf("正常连接");
return false;
}

View File

@ -27,6 +27,7 @@
#include <QPainterPath>
#include <QDialog>
#include <QListView>
#include "kylin-dbus-interface.h"
namespace Ui {
class ConfForm;
@ -41,6 +42,9 @@ public:
~ConfForm();
void setProp(QString connName, QString uuidName, QString v4method, QString v4addr, QString v6method, QString v6addr, QString mask, QString gateway, QString dns, bool isActConf, bool isWiFi);
QString actLanIpv6Addr;
QString actWifiIpv6Addr;
QString lcard, wcard;
public slots:
void cbTypeChanged(int index);
@ -95,6 +99,7 @@ private:
QString lastConnName, lastIpv4, netUuid, newUuid;
bool isActWifi; //是否是wifi网络
bool canCheckIpConflict = true; //当前是否可以执行IP冲突的检测
bool isIpv6Conflict = false; //ipv6地址是否冲突
QString labelQss, cbxQss, leQss, lineQss, btnOnQss, btnOffQss;

View File

@ -87,7 +87,7 @@ void KSimpleNM::execGetWifiList(const QString& wname)
shellOutputWifi = "";
QString cmd;
if (wname.isEmpty() || wname == "") {
cmd = "nmcli -f in-use,signal,security,freq,bssid,ssid,dbus-path device wifi";
cmd = "nmcli -f in-use,signal,security,freq,bssid,ssid,dbus-path,category device wifi";
} else {
cmd = "nmcli -f in-use,signal,security,freq,bssid,ssid,dbus-path,category device wifi list ifname " + wname;
}

View File

@ -467,6 +467,8 @@ void MainWindow::initNetwork()
lwname = iface->wname;
lcardname = iface->lname;
llname = iface->lname;
confForm->lcard = lcardname;
confForm->wcard = wcardname;
mwBandWidth = bt->execChkLanWidth(lcardname);
@ -537,6 +539,11 @@ void MainWindow::initNetwork()
}
}
ksnm->execGetConnList();
QString actWifiUuid = objKyDBus->getActiveWifiUuid();
objKyDBus->getConnectNetIp(actWifiUuid);
objKyDBus->getWifiIp(actWifiUuid);
confForm->actWifiIpv6Addr = objKyDBus->dbusActiveWifiIpv6;
}
// 初始化定时器
@ -1398,6 +1405,7 @@ void MainWindow::on_wifi_changed()
QString actWifiUuid = objKyDBus->getActiveWifiUuid();
objKyDBus->getConnectNetIp(actWifiUuid);
objKyDBus->getWifiIp(actWifiUuid);
confForm->actWifiIpv6Addr = objKyDBus->dbusActiveWifiIpv6;
if (oldWifiIpv4Method == "") {
oldWifiIpv4Method = objKyDBus-> dbusWifiIpv4Method;
}
@ -1556,6 +1564,7 @@ void MainWindow::getLanListDone(QStringList slist)
ifLanConnected = true;
objKyDBus->getConnectNetIp(nuuid);
confForm->actLanIpv6Addr = objKyDBus->dbusActiveLanIpv6;
if (mwBandWidth == "Unknown!") { getLanBandWidth(); }
//QString strLanName = TranslateLanName(nname); //进行中英文系统环境下有线网络名称的汉化

Binary file not shown.

View File

@ -112,9 +112,14 @@
<translation type="unfinished">IP地址冲突</translation>
</message>
<message>
<location filename="../src/confform.cpp" line="359"/>
<source>IP address conflict, Please change IP</source>
<translation type="unfinished">IP地址冲突IP</translation>
<location filename="../src/confform.cpp" line="503"/>
<source>IPV4 address conflict, Please change IP</source>
<translation>IPV4地址冲突IP</translation>
</message>
<message>
<location filename="../src/confform.cpp" line="559"/>
<source>IPV6 address conflict, Please change IP</source>
<translation>IPV6地址冲突IP</translation>
</message>
<message>
<location filename="../src/confform.cpp" line="386"/>