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