-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkftp.c
65 lines (59 loc) · 1.12 KB
/
kftp.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
#include <stdio.h>
#include <getopt.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include "kftp.h"
#include "serve.h"
void parse_args(int argc, char **argv) {
opts = 0;
int opt;
while ((opt = getopt(argc, argv, "fvhi:")) != -1) {
switch (opt) {
case 'f':
opts|=FORK;
break;
case 'v':
opts|=VERBOSE;
break;
case 'i':
strncpy(interface, optarg, 9);
break;
case 'h':
printf("Simple FTP server.\n\n"
"Usage:\tkftp [-f] [-v] [-i int]\n\n"
"Argument usage:\n"
"\t-i\t\tInterface\n"
"\t-f\t\tDaemonize\n"
"\t-v\t\tVerbose output\n");
exit(0);
break;
default:
break;
}
}
}
int main(int argc, char **argv) {
parse_args(argc, argv);
log_output = stdout;
err_output = stderr;
if (opts&FORK){
if (daemonize()){
error(1,0,"Fork failed");
}
}
if (serve()) {
error(1,0, "Server exited unexpectedly, error code: %d", serve_ERRNO);
} else {
printf("Quitted. Bye!\n");
}
return 0;
}
int daemonize() {
return 0;
}
char * currenttime() {
time_t now = time (0);
strftime (timebuf, 100, "%Y-%m-%d %H:%M:%S", localtime (&now));
return timebuf;
}