-
Notifications
You must be signed in to change notification settings - Fork 0
/
tool.c
59 lines (46 loc) · 1.36 KB
/
tool.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
//
// Created by mofan on 5/17/16.
//
#include "tool.h"
#include "l5.h"
#include "wxworker/ip.h"
void print_item(uint32_t ip, uint16_t port, uint16_t weight, void* arg) {
char sip[16]={0};
int2ip(ip, sip);
printf("%s %d %d\n", sip, port, weight);;
}
void showusage() {
printf("usage:\n");
printf(" -g sid peek rows of sid\n");
printf(" -d sid ip port remove a row\n");
printf(" -a sid ip port weight add a row\n");
}
int run_tool(int argc, char** argv) {
char args[512]={0};
int i;
for (i=1;i<argc;i++) {
if (i>1) {
strcat(args, " ");
}
strcat(args, argv[i]);
}
l5_shm_init();
uint32_t ip;
uint16_t sid, port, weight;
char sip[16]={0};
if (4 == sscanf(args, "-a %hu %s %hu %hu", &sid, sip, &port, &weight)) {// -a sid ip port weight
ip2int(sip, &ip);
l5_sid_add_ipport(sid, ip, port, weight);
l5_sid_each_block(sid, print_item, NULL);
} else if(3 == sscanf(args, "-d %hu %s %hu", &sid, sip, &port)) {
ip2int(sip, &ip);
l5_sid_del_ipport(sid, ip, port);
l5_sid_each_block(sid, print_item, NULL);
} else if(1 == sscanf(args, "-g %hu", &sid)) {
l5_sid_each_block(sid, print_item, NULL);
} else {
showusage();
}
l5_shm_detach();
return EXIT_SUCCESS;
}