Macos fix: routes delete

This commit is contained in:
pokamest 2021-06-01 08:45:26 -07:00
parent 9dbe15a0e3
commit 435ee58d40
2 changed files with 39 additions and 12 deletions

View file

@ -48,7 +48,6 @@ int RouterMac::routeAddList(const QString &gw, const QStringList &ips)
int cnt = 0;
for (const QString &ip: ips) {
if (routeAdd(ip, gw)) cnt++;
//QThread::msleep(10);
}
return cnt;
}
@ -62,27 +61,54 @@ bool RouterMac::clearSavedRoutes()
// for (const QString &ip: m_addedRoutes) {
// 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") {
qDebug().noquote() << "Warning, trying to remove default route, skipping: " << ip << gw;
return true;
}
// route delete ip gw
QProcess p;
p.setProcessChannelMode(QProcess::MergedChannels);
QString cmd;
if (mask == "255.255.255.255") {
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);
p.waitForFinished();
// skipping gw
qDebug().noquote() << "routeDelete, skipping gw`: " << ip;
qDebug().noquote() << "OUTPUT routeDelete: " << p.readAll();
QStringList parts = cmd.split(" ");
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()

View file

@ -21,6 +21,7 @@ public:
bool routeAdd(const QString &ip, const QString &gw);
int routeAddList(const QString &gw, const QStringList &ips);
bool clearSavedRoutes();
bool routeDelete(const QString &ip, const QString &gw);
bool routeDeleteList(const QString &gw, const QStringList &ips);
void flushDns();