1: #include <stdio.h>
2: #include <string.h>
3: #include <elwix.h>
4: #include <netinet/in.h>
5:
6:
7: int
8: main(int argc, char **argv)
9: {
10: sockaddr_t addr = { 0 };
11: ait_val_t v, *val = NULL;
12: struct in_addr a;
13: netaddr_t n, *n0;
14: inaddr_t t;
15: ether_addr_t ea;
16: char str[BUFSIZ];
17:
18: a.s_addr = E_CIDRMASK(8);
19: printf("/8 = %08X %08x\n", a.s_addr, htonl(a.s_addr));
20: a.s_addr = E_CIDRMASK(24);
21: printf("/24 = %08X %08x\n", a.s_addr, htonl(a.s_addr));
22: a.s_addr = E_CIDRMASK(26);
23: printf("/26 = %08X %08x\n", a.s_addr, htonl(a.s_addr));
24: a.s_addr = E_CIDRMASK(30);
25: printf("/30 = %08X %08x\n", a.s_addr, htonl(a.s_addr));
26:
27: memset(&n, 0, sizeof n);
28: n.addr.sin.sin_family = AF_INET;
29: n.addr.sin.sin_addr.s_addr = inet_addr("10.10.10.1");
30: n.mask.in.s_addr = E_CIDRMASK(24);
31:
32: t.in.s_addr = inet_addr("10.10.10.42");
33: printf("10.10.10.42 is in network 10.10.10.0/24? %d\n", e_innet(&n, &t));
34: t.in.s_addr = inet_addr("10.10.0.42");
35: printf("10.10.0.42 is in network 10.10.10.0/24? %d\n", e_innet(&n, &t));
36: t.in.s_addr = inet_addr("172.16.0.42");
37: printf("172.16.0.42 is in network 10.10.10.0/24? %d\n", e_innet(&n, &t));
38:
39: n0 = e_getnet("1.1.1.1/12");
40: if (n0) {
41: printf("addr=%s/%x\n", inet_ntoa(n0->addr.sin.sin_addr), ntohl(n0->mask.in.s_addr));
42: e_free(n0);
43: }
44: n0 = e_getnet("2.2.2.2");
45: if (n0) {
46: printf("addr=%s/%x\n", inet_ntoa(n0->addr.sin.sin_addr), ntohl(n0->mask.in.s_addr));
47: e_free(n0);
48: }
49: n0 = e_getnet("elwix.org/29");
50: if (n0) {
51: printf("addr=%s/%x\n", inet_ntoa(n0->addr.sin.sin_addr), ntohl(n0->mask.in.s_addr));
52: e_free(n0);
53: }
54:
55: if (argc < 2)
56: return 0;
57:
58: AIT_SET_DATA(val, "shits hit the fan! --- shits with Merudia ...\n", 47);
59: printf("GET DATA = %p %s t=%d l=%d\n", val, AIT_GET_DATA(val), AIT_TYPE(val), AIT_LEN(val));
60: AIT_SET_DATA(val, argv[1], strlen(argv[1]) + 1);
61: printf("+GET DATA = %p %s t=%d l=%d\n", val, AIT_GET_DATA(val), AIT_TYPE(val), AIT_LEN(val));
62: ait_freeVar(&val);
63:
64: AIT_SET_DATA(val, argv[1], strlen(argv[1]) + 1);
65: printf("GET DATA = %p %s t=%d l=%d\n", val, AIT_GET_DATA(val), AIT_TYPE(val), AIT_LEN(val));
66: ait_freeVar(&val);
67:
68: if (!e_gethostbyname(argv[1], 1234, &addr)) {
69: printf("Error:: #%d - %s\n", elwix_GetErrno(), elwix_GetError());
70: return 1;
71: }
72:
73: if (!e_n2addr(&addr, &v)) {
74: printf("Error:: #%d - %s\n", elwix_GetErrno(), elwix_GetError());
75: return 2;
76: }
77:
78: printf("Address is %s port is %u\n", AIT_GET_STR(&v), e_n2port(&addr));
79: AIT_FREE_VAL(&v);
80:
81: if (argc < 3)
82: return 0;
83:
84: val = ait_allocVar();
85: AIT_SET_STR(val, argv[2]);
86: if (!e_ether_addr(AIT_GET_STR(val), &ea))
87: printf("MAC address of iface=%s is %s\n", AIT_GET_STR(val), e_ether_ntoa(&ea, str, sizeof str));
88: ait_freeVar(&val);
89:
90: return 0;
91: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>