-
Notifications
You must be signed in to change notification settings - Fork 0
/
args.c
60 lines (59 loc) · 981 Bytes
/
args.c
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
#include "args.h"
#include "help.h"
#include <getopt.h>
#include <stdlib.h>
#include <unistd.h>
int
parse_args(int argc, char **argv, struct u_option *o)
{
int opt;
/* Set mode and options */
if (argc < 2) {
print_help();
exit(EXIT_FAILURE);
}
switch (argv[1][0]) {
case 'r':
o->action = RECEIVE;
break;
case 's':
o->action = SEND;
if (argc < 3 || argv[2][0] == '-') {
print_help();
exit(EXIT_FAILURE);
}
o->net.addr = argv[2];
++argv;
--argc;
break;
default:
print_help();
exit(EXIT_FAILURE);
}
++argv;
--argc;
o->output = STDOUT;
while ((opt = getopt(argc, argv, "?::e::p:f:a:")) >= 0) {
switch (opt) {
case '?':
print_help();
exit(0);
break;
case 'a':
o->net.addr = optarg;
break;
case 'e':
o->enc.algo = AES256;
break;
case 'p':
o->net.port = strtoul(optarg, NULL, 0);
break;
case 'f':
o->filename = optarg;
o->input = READ_FILE;
o->output = SAVE_FILE;
break;
}
}
return 0;
}