-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner_args.h
76 lines (70 loc) · 1.54 KB
/
runner_args.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
#ifndef RUNNER_ARGS_H
#define RUNNER_ARGS_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <net/if.h>
#include <assert.h>
struct parameters {
char *binary_path;
size_t repeat;
char *progname;
char *ifname;
int ifindex;
int local;
};
extern struct parameters args;
void usage(void) {
printf("loader:\n"
" --repeat -r [default 10^7]\n"
" --iface -i interface to use in cross test\n"
" --local -l the target server is on the local machine.\n"
" this mode emulate receiving traffic from"
" network.\n"
" --help -h\n"
);
}
void parse_args(int argc, char *argv[]) {
int ret;
struct option long_opts[] = {
{"help", no_argument, NULL, 'h'},
{"repeat", required_argument, NULL, 'r'},
{"iface", required_argument, NULL, 'i'},
{"local", no_argument, NULL, 'l'},
/* End of option list ------------------- */
{NULL, 0, NULL, 0},
};
/* Default values */
args.repeat = 1000000;
args.binary_path = "./build/bpf.o";
args.progname = "prog";
args.local = 0;
while (1) {
ret = getopt_long(argc, argv, "hi:r:", long_opts, NULL);
if (ret == -1)
break;
switch(ret) {
case 'r':
args.repeat = atoi(optarg);
break;
case 'i':
args.ifname = strdup(optarg);
args.ifindex = if_nametoindex(optarg);
assert(args.ifindex > 0);
break;
case 'l':
args.local = 1;
break;
case 'h':
usage();
exit(0);
break;
default:
usage();
exit(1);
break;
}
}
}
#endif