2 * Copyright (C) 1999-2001 Internet Software Consortium.
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
9 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
10 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
11 * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
13 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
14 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
15 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: interfaceiter.c,v 1.27 2002/07/02 05:51:43 marka Exp $ */
22 #include <sys/types.h>
23 #include <sys/ioctl.h>
24 #ifdef HAVE_SYS_SOCKIO_H
25 #include <sys/sockio.h> /* Required for ifiter_ioctl.c. */
33 #include <isc/interfaceiter.h>
34 #include <isc/magic.h>
38 #include <isc/result.h>
39 #include <isc/strerror.h>
40 #include <isc/string.h>
41 #include <isc/types.h>
44 /* Must follow <isc/net.h>. */
50 /* Common utility functions */
53 * Extract the network address part from a "struct sockaddr".
55 * The address family is given explicity
56 * instead of using src->sa_family, because the latter does not work
57 * for copying a network mask obtained by SIOCGIFNETMASK (it does
58 * not have a valid address family).
62 get_addr(unsigned int family, isc_netaddr_t *dst, struct sockaddr *src) {
67 &((struct sockaddr_in *) src)->sin_addr,
68 sizeof(struct in_addr));
71 memcpy(&dst->type.in6,
72 &((struct sockaddr_in6 *) src)->sin6_addr,
73 sizeof(struct in6_addr));
82 * Include system-dependent code.
85 #if HAVE_IFLIST_SYSCTL
86 #include "ifiter_sysctl.c"
88 #include "ifiter_ioctl.c"
92 * The remaining code is common to the sysctl and ioctl case.
96 isc_interfaceiter_current(isc_interfaceiter_t *iter,
97 isc_interface_t *ifdata)
99 REQUIRE(iter->result == ISC_R_SUCCESS);
100 memcpy(ifdata, &iter->current, sizeof(*ifdata));
101 return (ISC_R_SUCCESS);
105 isc_interfaceiter_first(isc_interfaceiter_t *iter) {
108 REQUIRE(VALID_IFITER(iter));
111 #ifdef HAVE_TRUCLUSTER
112 iter->clua_context = 0;
115 result = internal_current(iter);
116 if (result != ISC_R_IGNORE)
118 result = internal_next(iter);
119 if (result != ISC_R_SUCCESS)
122 iter->result = result;
127 isc_interfaceiter_next(isc_interfaceiter_t *iter) {
130 REQUIRE(VALID_IFITER(iter));
131 REQUIRE(iter->result == ISC_R_SUCCESS);
134 result = internal_next(iter);
135 if (result != ISC_R_SUCCESS)
137 result = internal_current(iter);
138 if (result != ISC_R_IGNORE)
141 iter->result = result;
146 isc_interfaceiter_destroy(isc_interfaceiter_t **iterp)
148 isc_interfaceiter_t *iter;
149 REQUIRE(iterp != NULL);
151 REQUIRE(VALID_IFITER(iter));
153 internal_destroy(iter);
154 isc_mem_put(iter->mctx, iter->buf, iter->bufsize);
157 isc_mem_put(iter->mctx, iter, sizeof(*iter));