Macos fix: routes delete
This commit is contained in:
parent
9dbe15a0e3
commit
435ee58d40
2 changed files with 39 additions and 12 deletions
|
@ -48,7 +48,6 @@ int RouterMac::routeAddList(const QString &gw, const QStringList &ips)
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
for (const QString &ip: ips) {
|
for (const QString &ip: ips) {
|
||||||
if (routeAdd(ip, gw)) cnt++;
|
if (routeAdd(ip, gw)) cnt++;
|
||||||
//QThread::msleep(10);
|
|
||||||
}
|
}
|
||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
@ -62,27 +61,54 @@ bool RouterMac::clearSavedRoutes()
|
||||||
// for (const QString &ip: m_addedRoutes) {
|
// for (const QString &ip: m_addedRoutes) {
|
||||||
// if (routeDelete(ip)) cnt++;
|
// if (routeDelete(ip)) cnt++;
|
||||||
// }
|
// }
|
||||||
// return (cnt == m_addedRoutes.count());
|
// return (cnt == m_addedRoutes.count());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RouterMac::routeDeleteList(const QString &gw, const QStringList &ips)
|
bool RouterMac::routeDelete(const QString &ipWithSubnet, const QString &gw)
|
||||||
{
|
{
|
||||||
|
QString ip = Utils::ipAddressFromIpWithSubnet(ipWithSubnet);
|
||||||
|
QString mask = Utils::netMaskFromIpWithSubnet(ipWithSubnet);
|
||||||
|
|
||||||
|
|
||||||
if (ip == "0.0.0.0") {
|
if (ip == "0.0.0.0") {
|
||||||
qDebug().noquote() << "Warning, trying to remove default route, skipping: " << ip << gw;
|
qDebug().noquote() << "Warning, trying to remove default route, skipping: " << ip << gw;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// route delete ip gw
|
QString cmd;
|
||||||
QProcess p;
|
if (mask == "255.255.255.255") {
|
||||||
p.setProcessChannelMode(QProcess::MergedChannels);
|
cmd = QString("route delete -host %1 %2").arg(ip).arg(gw);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cmd = QString("route delete -net %1 %2 %3").arg(ip).arg(gw).arg(mask);
|
||||||
|
}
|
||||||
|
|
||||||
p.start("route", QStringList() << "delete" << ip);
|
QStringList parts = cmd.split(" ");
|
||||||
p.waitForFinished();
|
|
||||||
// skipping gw
|
|
||||||
qDebug().noquote() << "routeDelete, skipping gw`: " << ip;
|
|
||||||
qDebug().noquote() << "OUTPUT routeDelete: " << p.readAll();
|
|
||||||
|
|
||||||
return p.exitCode() == 0;
|
int argc = parts.size();
|
||||||
|
char **argv = new char*[argc];
|
||||||
|
|
||||||
|
for (int i = 0; i < argc; i++) {
|
||||||
|
argv[i] = new char[parts.at(i).toStdString().length() + 1];
|
||||||
|
strcpy(argv[i], parts.at(i).toStdString().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
mainRouteIface(argc, argv);
|
||||||
|
|
||||||
|
for (int i = 0; i < argc; i++) {
|
||||||
|
delete [] argv[i];
|
||||||
|
}
|
||||||
|
delete[] argv;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RouterMac::routeDeleteList(const QString &gw, const QStringList &ips)
|
||||||
|
{
|
||||||
|
int cnt = 0;
|
||||||
|
for (const QString &ip: ips) {
|
||||||
|
if (routeDelete(ip, gw)) cnt++;
|
||||||
|
}
|
||||||
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouterMac::flushDns()
|
void RouterMac::flushDns()
|
||||||
|
|
|
@ -21,6 +21,7 @@ public:
|
||||||
bool routeAdd(const QString &ip, const QString &gw);
|
bool routeAdd(const QString &ip, const QString &gw);
|
||||||
int routeAddList(const QString &gw, const QStringList &ips);
|
int routeAddList(const QString &gw, const QStringList &ips);
|
||||||
bool clearSavedRoutes();
|
bool clearSavedRoutes();
|
||||||
|
bool routeDelete(const QString &ip, const QString &gw);
|
||||||
bool routeDeleteList(const QString &gw, const QStringList &ips);
|
bool routeDeleteList(const QString &gw, const QStringList &ips);
|
||||||
void flushDns();
|
void flushDns();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue