-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutehandler.cpp
62 lines (48 loc) · 1.55 KB
/
routehandler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "routehandler.h"
RouteHandler::RouteHandler()
{
isWindows = QSysInfo::windowsVersion() != 0;
_isFirstRoute = true;
}
void RouteHandler::deleteGateways() {
if (isWindows) {
windowsDeleteGateways();
} else {
linuxDeleteGateways();
}
}
void RouteHandler::addRoute(QHostAddress gateway, uint metric) {
if (isWindows) {
windowsAddRoute(gateway, metric);
} else {
linuxAddRoute(gateway, metric);
}
}
int RouteHandler::linuxAddRoute(QHostAddress gateway, uint metric) {
// route add default gw 192.168.1.2
QProcess route;
route.start("route", QStringList() << "add" << "default" << "gw" << gateway.toString() << "metric" << QString::number(metric));
// route.start("echo", QStringList() << "Hello" << "There");
route.waitForFinished();
QByteArray output = route.readAll();
// Linux Errors
// 7: File Exists
}
void RouteHandler::windowsAddRoute(QHostAddress gateway, uint metric) {
QProcess route;
route.start("route", QStringList() << "-p" << "add" << "0.0.0.0" << "mask" << "0.0.0.0" << gateway.toString() << "metric" << QString::number(metric));
route.waitForFinished();
}
void RouteHandler::linuxDeleteGateways() {
QProcess process;
process.start("route", QStringList() << "del" << "default");
process.waitForFinished();
}
void RouteHandler::windowsDeleteGateways() {
QProcess process;
process.start("route", QStringList() << "delete" << "0.0.0.0");
process.waitForFinished();
}
bool RouteHandler::isFirstRoute() {
return _isFirstRoute;
}