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
|
#include <string.h>
#include <getopt.h>
#include "submodule/log.c-patched/src/log.h"
#include <stdint.h>
#include <stdlib.h>
#define dbgchr(x) log_info("%c", x)
enum tcpf_mode {
TCPF_SERVER,
TCPF_CLIENT
};
struct runtime_opts {
enum tcpf_mode mode;
uint16_t srcport;
uint16_t destport;
};
static int parseopt(int argc, char **argv, struct runtime_opts *r_opts)
{
int optcounter = 0;
int c = 0;
static struct option opt_table[] = {
{"mode", required_argument, 0, 'm'},
{"srcport", required_argument, 0, 's'},
{"destport", required_argument, 0, 'd'},
// {"mode", required_argument, 0, 'm'},4
{0, 0, 0, 0}
};
while(1) {
c = getopt_long(argc, argv, "m:s:d:", opt_table, &optcounter);
// dbgchr(c);
if (c == -1)
break;
switch (c) {
case 'm':
if (strcmp(optarg, "server") == 0) {
r_opts->mode = TCPF_SERVER;
}
if (strcmp(optarg, "client") == 0) {
r_opts->mode = TCPF_CLIENT;
}
break;
case 's':
r_opts->srcport = atoi(optarg);
break;
case 'd':
r_opts->destport = atoi(optarg);
break;
}
}
}
int main(int argc, char **argv)
{
struct runtime_opts runtime_opts;
parseopt(argc, argv, &runtime_opts);
return 0;
}
|