-
Notifications
You must be signed in to change notification settings - Fork 1
/
iuctl.cpp
83 lines (78 loc) · 1.7 KB
/
iuctl.cpp
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 "iuctl.h"
#include <arpa/inet.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#define HELP "help"
#define ADDR "addr"
#define NET "net"
#define STATUS "status"
#define SHUTDOWN "shutdown"
const char* help = "\
iuctl [command] [params...]\n\
" HELP "\n\
print this message\n\
" ADDR " nid addr\n\
tell server about the address of a node\n\
" NET "\n\
print network addresses\n\
" STATUS "\n\
print status\n\
" SHUTDOWN "\n\
shutdown iu server\n\
";
const char* addr_help = "\
iuctl addr nid addr\n\
nid\n\
node id\n\
addr\n\
IPv6 address of node\n\
";
void print_help(void) {
fputs(help, stderr);
}
void print_addr_help(void) {
fputs(addr_help, stderr);
}
void print_status() {
status_iuctl();
}
int main(int argc, char* argv[]) {
if (argc < 2) {
print_help();
exit(EINVAL);
}
#define IS(index,str) (strcmp(argv[index], str) == 0)
if (IS(1, HELP)) {
print_help();
exit(EXIT_SUCCESS);
}
if(join_iuctl() != 0) {
fprintf(stderr, "Error, is server running?\n");
return -1;
}
if (IS(1, STATUS)){
print_status();
} else if (IS(1, ADDR)) {
if (argc < 4) {
print_addr_help();
}
addr_t addr;
if (inet_pton(AF_INET6, argv[3], &addr.siaddr6) == 0) {
perror(argv[3]);
}
addr_iuctl(atol(argv[2]), &addr);
} else if (IS(1, NET)) {
net_iuctl();
} else if (IS(1, SHUTDOWN)) {
shutdown_iuctl();
} else {
print_help();
}
#undef IS
return 0;
}