forked from codyps/peerduct
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
92 lines (72 loc) · 1.54 KB
/
main.c
File metadata and controls
92 lines (72 loc) · 1.54 KB
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
84
85
86
87
88
89
90
91
92
#include <stdio.h>
#include <sys/types.h> /* socket, getaddrinfo */
#include <sys/socket.h> /* socket, getaddrinfo */
#include <netdb.h> /* getaddrinfo */
#include <netinet/in.h> /* udp */
#include <stdarg.h> /* va_* */
#include <unistd.h> /* getopt */
static const char optstr[] = ":p:f:l:";
static int warn(char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
int x = vfprintf(stderr, fmt, ap);
va_end(ap);
return x;
}
static void usage(char *pname)
{
warn(
"usage: %s [options]\n"
" -h show help\n"
" -f <cfgfile> cfg file path\n"
" -l <local> where to listen\n"
" -p <peer> an initial peer to connect to.\n"
"\n"
" ipv4 - ip:port, ip, host, host:port\n"
" ipv6 - [ip]:port, ip, host, host:port\n"
, pname);
}
struct peer_addr {
char *host;
uint16_t port;
};
int peer_str_to_addr(char *in_str, struct peer_addr *pa)
{
/* TODO: parse in_str, determine */
return -1;
}
struct peer_args {
};
static void *peer_thread(void *pa_v)
{
struct peer_args *pa = pa_v;
return NULL;
}
int main(int argc, char **argv)
{
int c;
while ((c = getopt(argc, argv, optstr)) != -1) {
switch(c) {
case 'p':
warn("need to add peer-str to list: %s\n", optarg);
break;
case 'l':
warn("add this to listen list: %s\n", optarg);
break;
case 'f':
warn("config file path: %s\n", optarg);
break;
case ':':
warn("option '-%c' requires an argument\n", optopt);
break;
case '?':
warn("option '-%c' is unrecognized\n", optopt);
break;
default:
warn("opt: %c\n", c);
return -1;
}
}
return 0;
}