forked from ryd/chaosvpn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_addrmask.c
67 lines (52 loc) · 1.37 KB
/
test_addrmask.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
#include <string.h>
#include <sys/socket.h>
#ifndef WIN32
#include <arpa/inet.h>
#endif
#include <netinet/in.h>
#include <netdb.h>
#include "chaosvpn.h"
#include "addrmask.h"
struct addr_info ip;
struct string str;
bool ret;
int
main (int argc,char *argv[])
{
log_init(&argc, &argv, LOG_PID, LOG_DAEMON);
log_info("test_addrmask started.\n");
/* IPV4 */
ret = addrmask_parse(&ip, "127.0.0.1/8");
if (!ret) {
log_err("addrmask_parse(&ip, \"127.0.0.1/8\") failed.\n");
exit(1);
}
log_info("ip addr_family = %d, (v4=%d, v6=%d)\n", ip.addr_family, AF_INET, AF_INET6);
string_init(&str, 128, 128);
ret = addrmask_to_string(&str, &ip);
if (!ret) {
log_err("addrmask_to_string(&str, &ip) failed.\n");
exit(1);
}
string_ensurez(&str);
log_info("addrmask_to_string(): %s\n", string_get(&str));
string_free(&str);
/* IPV6 */
ret = addrmask_parse(&ip, "fe80::227:13ff:feb5:160e/64");
if (!ret) {
log_err("addrmask_parse(&ip, \"fe80::227:13ff:feb5:160e/64\") failed.\n");
exit(1);
}
log_info("ip addr_family = %d, (v4=%d, v6=%d)\n", ip.addr_family, AF_INET, AF_INET6);
string_init(&str, 128, 128);
ret = addrmask_to_string(&str, &ip);
if (!ret) {
log_err("addrmask_to_string(&str, &ip) failed.\n");
exit(1);
}
string_ensurez(&str);
log_info("addrmask_to_string(): %s\n", string_get(&str));
string_free(&str);
log_info("test_addrmask finished.\n");
exit(0);
}