-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
executable file
·58 lines (47 loc) · 1.56 KB
/
main.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
#include "DevicesHandler.h"
#include <cstring>
#include <iostream>
int main(int argc, char *argv[])
{
DevicesHandler devicesHandler;
switch (argc) {
case 2:
if (strcmp(argv[1], "--list") == 0) {
devicesHandler.enumerateNics();
return 0;
}
break;
case 3:
const uint32_t index = strtoul(argv[1], nullptr, 10);
if (index == 0 || errno == ERANGE) {
std::cout << "Invalid index: " << argv[1] << std::endl << std::endl;
break;
}
if (strcmp(argv[2], "--disable") == 0) {
if (devicesHandler.toggleNic(index, DevicesHandler::Disable)) {
std::cout << "Network interface #" << index << " successfully disabled!" << std::endl;
return 0;
}
return 1;
} else if (strcmp(argv[2], "--enable") == 0) {
if (devicesHandler.toggleNic(index, DevicesHandler::Enable)) {
std::cout << "Network interface #" << index << " successfully enabled!" << std::endl;
return 0;
}
return 1;
} else if (strcmp(argv[2], "--toggle") == 0) {
if (devicesHandler.toggleNic(index, DevicesHandler::Toggle)) {
std::cout << "Network interface #" << index << " successfully toggled!" << std::endl;
return 0;
}
return 1;
} else {
std::cout << "Invalid argument: " << argv[2] << std::endl << std::endl;
}
}
std::cout << "----- Usage -----" << std::endl << std::endl;
std::cout << "List interfaces: \"toggle-nic --list\"" << std::endl;
std::cout << "Disable interface #11: \"toggle-nic 11 --disable\"" << std::endl;
std::cout << "Enable interface #11: \"toggle-nic 11 --enable\"" << std::endl;
return 0;
}