1*00b67f09SDavid van Moolenbroek /* $NetBSD: inter_test.c,v 1.6 2014/12/10 04:37:53 christos Exp $ */
2*00b67f09SDavid van Moolenbroek
3*00b67f09SDavid van Moolenbroek /*
4*00b67f09SDavid van Moolenbroek * Copyright (C) 2004, 2005, 2007, 2008 Internet Systems Consortium, Inc. ("ISC")
5*00b67f09SDavid van Moolenbroek * Copyright (C) 2000, 2001, 2003 Internet Software Consortium.
6*00b67f09SDavid van Moolenbroek *
7*00b67f09SDavid van Moolenbroek * Permission to use, copy, modify, and/or distribute this software for any
8*00b67f09SDavid van Moolenbroek * purpose with or without fee is hereby granted, provided that the above
9*00b67f09SDavid van Moolenbroek * copyright notice and this permission notice appear in all copies.
10*00b67f09SDavid van Moolenbroek *
11*00b67f09SDavid van Moolenbroek * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12*00b67f09SDavid van Moolenbroek * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13*00b67f09SDavid van Moolenbroek * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14*00b67f09SDavid van Moolenbroek * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15*00b67f09SDavid van Moolenbroek * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16*00b67f09SDavid van Moolenbroek * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17*00b67f09SDavid van Moolenbroek * PERFORMANCE OF THIS SOFTWARE.
18*00b67f09SDavid van Moolenbroek */
19*00b67f09SDavid van Moolenbroek
20*00b67f09SDavid van Moolenbroek /* Id: inter_test.c,v 1.16 2008/03/20 23:47:00 tbox Exp */
21*00b67f09SDavid van Moolenbroek
22*00b67f09SDavid van Moolenbroek /*! \file */
23*00b67f09SDavid van Moolenbroek #include <config.h>
24*00b67f09SDavid van Moolenbroek
25*00b67f09SDavid van Moolenbroek #include <stdlib.h>
26*00b67f09SDavid van Moolenbroek
27*00b67f09SDavid van Moolenbroek #include <isc/interfaceiter.h>
28*00b67f09SDavid van Moolenbroek #include <isc/mem.h>
29*00b67f09SDavid van Moolenbroek #include <isc/util.h>
30*00b67f09SDavid van Moolenbroek
31*00b67f09SDavid van Moolenbroek int
main(int argc,char ** argv)32*00b67f09SDavid van Moolenbroek main(int argc, char **argv) {
33*00b67f09SDavid van Moolenbroek isc_mem_t *mctx = NULL;
34*00b67f09SDavid van Moolenbroek isc_interfaceiter_t *iter = NULL;
35*00b67f09SDavid van Moolenbroek isc_interface_t ifdata;
36*00b67f09SDavid van Moolenbroek isc_result_t result;
37*00b67f09SDavid van Moolenbroek const char * res;
38*00b67f09SDavid van Moolenbroek char buf[128];
39*00b67f09SDavid van Moolenbroek
40*00b67f09SDavid van Moolenbroek UNUSED(argc);
41*00b67f09SDavid van Moolenbroek UNUSED(argv);
42*00b67f09SDavid van Moolenbroek
43*00b67f09SDavid van Moolenbroek RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
44*00b67f09SDavid van Moolenbroek result = isc_interfaceiter_create(mctx, &iter);
45*00b67f09SDavid van Moolenbroek if (result != ISC_R_SUCCESS)
46*00b67f09SDavid van Moolenbroek goto cleanup;
47*00b67f09SDavid van Moolenbroek result = isc_interfaceiter_first(iter);
48*00b67f09SDavid van Moolenbroek while (result == ISC_R_SUCCESS) {
49*00b67f09SDavid van Moolenbroek result = isc_interfaceiter_current(iter, &ifdata);
50*00b67f09SDavid van Moolenbroek if (result != ISC_R_SUCCESS) {
51*00b67f09SDavid van Moolenbroek fprintf(stdout, "isc_interfaceiter_current: %s",
52*00b67f09SDavid van Moolenbroek isc_result_totext(result));
53*00b67f09SDavid van Moolenbroek continue;
54*00b67f09SDavid van Moolenbroek }
55*00b67f09SDavid van Moolenbroek fprintf(stdout, "%s %d %x\n", ifdata.name, ifdata.af,
56*00b67f09SDavid van Moolenbroek ifdata.flags);
57*00b67f09SDavid van Moolenbroek INSIST(ifdata.af == AF_INET || ifdata.af == AF_INET6);
58*00b67f09SDavid van Moolenbroek res = inet_ntop(ifdata.af, &ifdata.address.type, buf,
59*00b67f09SDavid van Moolenbroek sizeof(buf));
60*00b67f09SDavid van Moolenbroek if (ifdata.address.zone != 0)
61*00b67f09SDavid van Moolenbroek fprintf(stdout, "address = %s (zone %u)\n",
62*00b67f09SDavid van Moolenbroek res == NULL ? "BAD" : res,
63*00b67f09SDavid van Moolenbroek ifdata.address.zone);
64*00b67f09SDavid van Moolenbroek else
65*00b67f09SDavid van Moolenbroek fprintf(stdout, "address = %s\n",
66*00b67f09SDavid van Moolenbroek res == NULL ? "BAD" : res);
67*00b67f09SDavid van Moolenbroek INSIST(ifdata.address.family == ifdata.af);
68*00b67f09SDavid van Moolenbroek res = inet_ntop(ifdata.af, &ifdata.netmask.type, buf,
69*00b67f09SDavid van Moolenbroek sizeof(buf));
70*00b67f09SDavid van Moolenbroek fprintf(stdout, "netmask = %s\n", res == NULL ? "BAD" : res);
71*00b67f09SDavid van Moolenbroek INSIST(ifdata.netmask.family == ifdata.af);
72*00b67f09SDavid van Moolenbroek if ((ifdata.flags & INTERFACE_F_POINTTOPOINT) != 0) {
73*00b67f09SDavid van Moolenbroek res = inet_ntop(ifdata.af, &ifdata.dstaddress.type,
74*00b67f09SDavid van Moolenbroek buf, sizeof(buf));
75*00b67f09SDavid van Moolenbroek fprintf(stdout, "dstaddress = %s\n",
76*00b67f09SDavid van Moolenbroek res == NULL ? "BAD" : res);
77*00b67f09SDavid van Moolenbroek
78*00b67f09SDavid van Moolenbroek INSIST(ifdata.dstaddress.family == ifdata.af);
79*00b67f09SDavid van Moolenbroek }
80*00b67f09SDavid van Moolenbroek result = isc_interfaceiter_next(iter);
81*00b67f09SDavid van Moolenbroek if (result != ISC_R_SUCCESS && result != ISC_R_NOMORE) {
82*00b67f09SDavid van Moolenbroek fprintf(stdout, "isc_interfaceiter_next: %s",
83*00b67f09SDavid van Moolenbroek isc_result_totext(result));
84*00b67f09SDavid van Moolenbroek continue;
85*00b67f09SDavid van Moolenbroek }
86*00b67f09SDavid van Moolenbroek }
87*00b67f09SDavid van Moolenbroek isc_interfaceiter_destroy(&iter);
88*00b67f09SDavid van Moolenbroek
89*00b67f09SDavid van Moolenbroek fprintf(stdout, "\nPass 2\n\n");
90*00b67f09SDavid van Moolenbroek
91*00b67f09SDavid van Moolenbroek result = isc_interfaceiter_create(mctx, &iter);
92*00b67f09SDavid van Moolenbroek if (result != ISC_R_SUCCESS)
93*00b67f09SDavid van Moolenbroek goto cleanup;
94*00b67f09SDavid van Moolenbroek result = isc_interfaceiter_first(iter);
95*00b67f09SDavid van Moolenbroek while (result == ISC_R_SUCCESS) {
96*00b67f09SDavid van Moolenbroek result = isc_interfaceiter_current(iter, &ifdata);
97*00b67f09SDavid van Moolenbroek if (result != ISC_R_SUCCESS) {
98*00b67f09SDavid van Moolenbroek fprintf(stdout, "isc_interfaceiter_current: %s",
99*00b67f09SDavid van Moolenbroek isc_result_totext(result));
100*00b67f09SDavid van Moolenbroek continue;
101*00b67f09SDavid van Moolenbroek }
102*00b67f09SDavid van Moolenbroek fprintf(stdout, "%s %d %x\n", ifdata.name, ifdata.af,
103*00b67f09SDavid van Moolenbroek ifdata.flags);
104*00b67f09SDavid van Moolenbroek INSIST(ifdata.af == AF_INET || ifdata.af == AF_INET6);
105*00b67f09SDavid van Moolenbroek res = inet_ntop(ifdata.af, &ifdata.address.type, buf,
106*00b67f09SDavid van Moolenbroek sizeof(buf));
107*00b67f09SDavid van Moolenbroek if (ifdata.address.zone != 0)
108*00b67f09SDavid van Moolenbroek fprintf(stdout, "address = %s (zone %u)\n",
109*00b67f09SDavid van Moolenbroek res == NULL ? "BAD" : res,
110*00b67f09SDavid van Moolenbroek ifdata.address.zone);
111*00b67f09SDavid van Moolenbroek else
112*00b67f09SDavid van Moolenbroek fprintf(stdout, "address = %s\n",
113*00b67f09SDavid van Moolenbroek res == NULL ? "BAD" : res);
114*00b67f09SDavid van Moolenbroek INSIST(ifdata.address.family == ifdata.af);
115*00b67f09SDavid van Moolenbroek res = inet_ntop(ifdata.af, &ifdata.netmask.type, buf,
116*00b67f09SDavid van Moolenbroek sizeof(buf));
117*00b67f09SDavid van Moolenbroek fprintf(stdout, "netmask = %s\n", res == NULL ? "BAD" : res);
118*00b67f09SDavid van Moolenbroek INSIST(ifdata.netmask.family == ifdata.af);
119*00b67f09SDavid van Moolenbroek if ((ifdata.flags & INTERFACE_F_POINTTOPOINT) != 0) {
120*00b67f09SDavid van Moolenbroek res = inet_ntop(ifdata.af, &ifdata.dstaddress.type,
121*00b67f09SDavid van Moolenbroek buf, sizeof(buf));
122*00b67f09SDavid van Moolenbroek fprintf(stdout, "dstaddress = %s\n",
123*00b67f09SDavid van Moolenbroek res == NULL ? "BAD" : res);
124*00b67f09SDavid van Moolenbroek
125*00b67f09SDavid van Moolenbroek INSIST(ifdata.dstaddress.family == ifdata.af);
126*00b67f09SDavid van Moolenbroek }
127*00b67f09SDavid van Moolenbroek result = isc_interfaceiter_next(iter);
128*00b67f09SDavid van Moolenbroek if (result != ISC_R_SUCCESS && result != ISC_R_NOMORE) {
129*00b67f09SDavid van Moolenbroek fprintf(stdout, "isc_interfaceiter_next: %s",
130*00b67f09SDavid van Moolenbroek isc_result_totext(result));
131*00b67f09SDavid van Moolenbroek continue;
132*00b67f09SDavid van Moolenbroek }
133*00b67f09SDavid van Moolenbroek }
134*00b67f09SDavid van Moolenbroek isc_interfaceiter_destroy(&iter);
135*00b67f09SDavid van Moolenbroek cleanup:
136*00b67f09SDavid van Moolenbroek isc_mem_destroy(&mctx);
137*00b67f09SDavid van Moolenbroek
138*00b67f09SDavid van Moolenbroek return (0);
139*00b67f09SDavid van Moolenbroek }
140