-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
57 lines (52 loc) · 1.12 KB
/
main.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
#include "client.h"
#include "enc.h"
#include "error.h"
#include "server.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
bool parse_args(int argc, char **argv, int *server_port, char *remote,
char *password);
int main(int argc, char **argv) {
if (argc < 5)
USAGE
int server_port;
char remote[64] = {0}, password[64] = {0};
bool client = parse_args(argc, argv, &server_port, remote, password);
aes_init(password);
if (client)
main__client(remote);
else
main__server(server_port);
}
bool parse_args(int argc, char **argv, int *server_port, char *remote,
char *password) {
bool ret;
int opt;
while ((opt = getopt(argc, argv, "c:s:p:")) != -1) {
switch (opt) {
case 'c':
ret = true;
if (!optarg)
USAGE
strcpy(remote, optarg);
break;
case 's':
ret = false;
if (!optarg)
USAGE
*server_port = atoi(optarg);
break;
case 'p':
if (!optarg)
USAGE
strcpy(password, optarg);
break;
default:
USAGE
}
}
return ret;
}