-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.c
83 lines (70 loc) · 1.7 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
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
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
#include "bumerang_messages.h"
#include "send.h"
#include "get.h"
#include "connect.h"
#define VERSION "0.1"
int checkArgc(int argc);
void usage(void);
int main(int argc, char *argv[]) {
int socket;
char c;
char *filePath = NULL;
int key;
int check_send = 0;
int check_get = 0;
char *ipaddr;
if (checkArgc(argc))
usage();
while ((c = getopt (argc, argv, "hsg:p:l:")) != -1)
switch (c)
{
case 'h':
usage();
break;
case 's':
check_send = 1;
break;
case 'g':
ipaddr = optarg;
check_get = 1;
break;
case 'p':
key = atoi(optarg);
break;
case 'l':
filePath = optarg;
break;
default:
usage();
}
if (check_send) {
socket = connectForSend();
sendFile(socket, filePath, key);
closeConnect(socket);
}
if (check_get) {
socket = connectForGet(ipaddr);
getFile(socket, filePath, key);
closeConnect(socket);
}
return 0;
}
int checkArgc(int argc)
{
if (argc < 2)
usage();
return 0;
}
void usage(void)
{
printf("\nBumerang v%s (Usage)\n"
"Send a file : bumerang -s -p <password> -l <filepath>\n"
"Get a file : bumerang -g <ipaddr> -p <password> -l <folderpath>\n"
"Get a file-2 : bumerang -g <ipaddr> -p <password>\n"
"Help : bumerang -h\n\n", VERSION);
exit(EXIT_FAILURE);
}