-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharg_parser.cpp
More file actions
55 lines (50 loc) · 1.44 KB
/
arg_parser.cpp
File metadata and controls
55 lines (50 loc) · 1.44 KB
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
/**
* @file arg_parser.cpp
* @brief Implementation file for the argument parser class.
* @author Adam Pastierik
* login: xpasti00
*/
#include "arg_parser.hpp"
ArgParser::ArgParser(int argc, char *argv[])
{
parse_args(argc, argv);
}
void ArgParser::parse_args(int argc, char *argv[])
{
int opt;
// process command line options using getopt
while ((opt = getopt(argc, argv, "i:p:vd:t:")) != -1)
{
switch (opt)
{
case 'i':
interface = optarg; // set the network interface
break;
case 'p':
pcapfile = optarg; // set the PCAP file path
break;
case 'v':
verbose = true; // enable verbose mode
break;
case 'd':
domainsfile = optarg; // set the domains file path
break;
case 't':
translationsfile = optarg; // set the translations file path
break;
default:
exit(1); // exit with error if an invalid option is provided
}
}
// ensure that either interface or pcapfile is provided, but not both
if (interface.empty() && pcapfile.empty())
{
std::cerr << "Error: Either an interface (-i) or a pcap file (-p) must be provided.\n";
exit(1);
}
else if (!interface.empty() && !pcapfile.empty())
{
std::cerr << "Error: Cannot provide both an interface (-i) and a pcap file (-p).\n";
exit(1);
}
}