forked from ts-way/aranea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
argparser.h
101 lines (78 loc) · 2.04 KB
/
argparser.h
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#ifndef __ARGPARSER_H__
#define __ARGPARSER_H__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#define VERSION "1.0"
/*
* Cmdline options
*/
struct prog_options {
char *file; // hosts file
char *device; // interface
char *filter; // custom pcap filter
int verbose; // verbosity level
} options;
/*
* Program usage template
*/
const char usage_template[] =
"Aranea " VERSION " [fast dns spoofing tool]\n"
"written by: Emanuele Acri <[email protected]>\n\n"
"Usage:\n"
" aranea -f hosts_file <options>\n"
"Options:\n"
" -f file: hosts file (see hosts.txt)\n"
" -i device: network device to use\n"
" -F filter: custom pcap filter\n"
" -v verbose: verbosity level\n"
" -h help screen\n";
/*
* Program usage
*/
void usage(FILE *out, const char *error)
{
fputs(usage_template, out);
if(error)
fputs(error, out);
exit(1);
}
/*
* Parser for command line options
* See getopt(3)...
*/
int parseopt(int argc, char **argv)
{
char ch;
// cleaning
memset(&options, 0, sizeof(options));
const char *shortopt = "f:i:F:vh"; // short options
while ((ch = getopt (argc, argv, shortopt)) != -1) {
switch (ch) {
case 'f': // hosts file
options.file = optarg;
break;
case 'i': // interface
options.device = optarg;
break;
case 'F': // custom filter
options.filter = optarg;
break;
case 'v': // verbosity level
options.verbose++;
break;
case 'h': //help
usage(stdout, NULL);
case '?':
default:
usage(stderr, NULL);
}
}
// check required options
if ( !options.file ) {
usage(stderr, "\nError: no hosts file selected, see -f option...\n");
}
return 1;
}
#endif /* __ARGPARSER_H__ */