1 /* $NetBSD: inter_test.c,v 1.6 2014/12/10 04:37:53 christos Exp $ */
4 * Copyright (C) 2004, 2005, 2007, 2008 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 2000, 2001, 2003 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: inter_test.c,v 1.16 2008/03/20 23:47:00 tbox Exp */
27 #include <isc/interfaceiter.h>
32 main(int argc
, char **argv
) {
33 isc_mem_t
*mctx
= NULL
;
34 isc_interfaceiter_t
*iter
= NULL
;
35 isc_interface_t ifdata
;
43 RUNTIME_CHECK(isc_mem_create(0, 0, &mctx
) == ISC_R_SUCCESS
);
44 result
= isc_interfaceiter_create(mctx
, &iter
);
45 if (result
!= ISC_R_SUCCESS
)
47 result
= isc_interfaceiter_first(iter
);
48 while (result
== ISC_R_SUCCESS
) {
49 result
= isc_interfaceiter_current(iter
, &ifdata
);
50 if (result
!= ISC_R_SUCCESS
) {
51 fprintf(stdout
, "isc_interfaceiter_current: %s",
52 isc_result_totext(result
));
55 fprintf(stdout
, "%s %d %x\n", ifdata
.name
, ifdata
.af
,
57 INSIST(ifdata
.af
== AF_INET
|| ifdata
.af
== AF_INET6
);
58 res
= inet_ntop(ifdata
.af
, &ifdata
.address
.type
, buf
,
60 if (ifdata
.address
.zone
!= 0)
61 fprintf(stdout
, "address = %s (zone %u)\n",
62 res
== NULL
? "BAD" : res
,
65 fprintf(stdout
, "address = %s\n",
66 res
== NULL
? "BAD" : res
);
67 INSIST(ifdata
.address
.family
== ifdata
.af
);
68 res
= inet_ntop(ifdata
.af
, &ifdata
.netmask
.type
, buf
,
70 fprintf(stdout
, "netmask = %s\n", res
== NULL
? "BAD" : res
);
71 INSIST(ifdata
.netmask
.family
== ifdata
.af
);
72 if ((ifdata
.flags
& INTERFACE_F_POINTTOPOINT
) != 0) {
73 res
= inet_ntop(ifdata
.af
, &ifdata
.dstaddress
.type
,
75 fprintf(stdout
, "dstaddress = %s\n",
76 res
== NULL
? "BAD" : res
);
78 INSIST(ifdata
.dstaddress
.family
== ifdata
.af
);
80 result
= isc_interfaceiter_next(iter
);
81 if (result
!= ISC_R_SUCCESS
&& result
!= ISC_R_NOMORE
) {
82 fprintf(stdout
, "isc_interfaceiter_next: %s",
83 isc_result_totext(result
));
87 isc_interfaceiter_destroy(&iter
);
89 fprintf(stdout
, "\nPass 2\n\n");
91 result
= isc_interfaceiter_create(mctx
, &iter
);
92 if (result
!= ISC_R_SUCCESS
)
94 result
= isc_interfaceiter_first(iter
);
95 while (result
== ISC_R_SUCCESS
) {
96 result
= isc_interfaceiter_current(iter
, &ifdata
);
97 if (result
!= ISC_R_SUCCESS
) {
98 fprintf(stdout
, "isc_interfaceiter_current: %s",
99 isc_result_totext(result
));
102 fprintf(stdout
, "%s %d %x\n", ifdata
.name
, ifdata
.af
,
104 INSIST(ifdata
.af
== AF_INET
|| ifdata
.af
== AF_INET6
);
105 res
= inet_ntop(ifdata
.af
, &ifdata
.address
.type
, buf
,
107 if (ifdata
.address
.zone
!= 0)
108 fprintf(stdout
, "address = %s (zone %u)\n",
109 res
== NULL
? "BAD" : res
,
110 ifdata
.address
.zone
);
112 fprintf(stdout
, "address = %s\n",
113 res
== NULL
? "BAD" : res
);
114 INSIST(ifdata
.address
.family
== ifdata
.af
);
115 res
= inet_ntop(ifdata
.af
, &ifdata
.netmask
.type
, buf
,
117 fprintf(stdout
, "netmask = %s\n", res
== NULL
? "BAD" : res
);
118 INSIST(ifdata
.netmask
.family
== ifdata
.af
);
119 if ((ifdata
.flags
& INTERFACE_F_POINTTOPOINT
) != 0) {
120 res
= inet_ntop(ifdata
.af
, &ifdata
.dstaddress
.type
,
122 fprintf(stdout
, "dstaddress = %s\n",
123 res
== NULL
? "BAD" : res
);
125 INSIST(ifdata
.dstaddress
.family
== ifdata
.af
);
127 result
= isc_interfaceiter_next(iter
);
128 if (result
!= ISC_R_SUCCESS
&& result
!= ISC_R_NOMORE
) {
129 fprintf(stdout
, "isc_interfaceiter_next: %s",
130 isc_result_totext(result
));
134 isc_interfaceiter_destroy(&iter
);
136 isc_mem_destroy(&mctx
);