ifiter_getifaddrs.c revision 0a7e6db2db81e8ca518ab9d5620d69fe1b1837f5
20a96edbf9894e327a99f21acf3571422df5c7b0Tinderbox User/*
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * Copyright (C) 2004, 2005, 2007, 2008 Internet Systems Consortium, Inc. ("ISC")
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * Copyright (C) 2003 Internet Software Consortium.
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews *
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * Permission to use, copy, modify, and/or distribute this software for any
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * purpose with or without fee is hereby granted, provided that the above
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * copyright notice and this permission notice appear in all copies.
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews *
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
f97d56e757b9a293ffbaa915ca4d792ae84ba85aTinderbox User * PERFORMANCE OF THIS SOFTWARE.
f97d56e757b9a293ffbaa915ca4d792ae84ba85aTinderbox User */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews/* $Id: ifiter_getifaddrs.c,v 1.11 2008/03/20 23:47:00 tbox Exp $ */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews/*! \file
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * \brief
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * Obtain the list of network interfaces using the getifaddrs(3) library.
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver */
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt#include <ifaddrs.h>
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt/*% Iterator Magic */
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt#define IFITER_MAGIC ISC_MAGIC('I', 'F', 'I', 'G')
3d751891410f9892ca1c1deba2f7d8556ae91b0cMark Andrews/*% Valid Iterator */
ac5ed748602c890d596bed07b0b23b8b5f42b2f6Mark Andrews#define VALID_IFITER(t) ISC_MAGIC_VALID(t, IFITER_MAGIC)
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver#ifdef __linux
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Huntstatic isc_boolean_t seenv6 = ISC_FALSE;
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt#endif
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews/*% Iterator structure */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsstruct isc_interfaceiter {
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews unsigned int magic; /*%< Magic number. */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_mem_t *mctx;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews void *buf; /*%< (unused) */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews unsigned int bufsize; /*%< (always 0) */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews struct ifaddrs *ifaddrs; /*%< List of ifaddrs */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews struct ifaddrs *pos; /*%< Ptr to current ifaddr */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_interface_t current; /*%< Current interface data. */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_result_t result; /*%< Last result code. */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews#ifdef __linux
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews FILE * proc;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews char entry[ISC_IF_INET6_SZ];
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_result_t valid;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews#endif
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt};
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Huntisc_result_t
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Huntisc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) {
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt isc_interfaceiter_t *iter;
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt isc_result_t result;
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt char strbuf[ISC_STRERRORSIZE];
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver REQUIRE(mctx != NULL);
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver REQUIRE(iterp != NULL);
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver REQUIRE(*iterp == NULL);
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt iter = isc_mem_get(mctx, sizeof(*iter));
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt if (iter == NULL)
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt return (ISC_R_NOMEMORY);
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt iter->mctx = mctx;
06e28e50bd06bf3127b560c97a81f67306bacb02Mark Andrews iter->buf = NULL;
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt iter->bufsize = 0;
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt iter->ifaddrs = NULL;
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt#ifdef __linux
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver /*
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver * Only open "/proc/net/if_inet6" if we have never seen a IPv6
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver * address returned by getifaddrs().
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews if (!seenv6)
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver iter->proc = fopen("/proc/net/if_inet6", "r");
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver else
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver iter->proc = NULL;
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver iter->valid = ISC_R_FAILURE;
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver#endif
88112d5fcb6b9e1d0f80105a9d2a6f09440c2401Mark Andrews
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver if (getifaddrs(&iter->ifaddrs) < 0) {
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver isc__strerror(errno, strbuf, sizeof(strbuf));
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver UNEXPECTED_ERROR(__FILE__, __LINE__,
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_msgcat_get(isc_msgcat,
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews ISC_MSGSET_IFITERGETIFADDRS,
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews ISC_MSG_GETIFADDRS,
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews "getting interface "
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt "addresses: getifaddrs: %s"),
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews strbuf);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews result = ISC_R_UNEXPECTED;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews goto failure;
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver }
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver /*
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt * A newly created iterator has an undefined position
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt * until isc_interfaceiter_first() is called.
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt */
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver iter->pos = NULL;
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt iter->result = ISC_R_FAILURE;
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt iter->magic = IFITER_MAGIC;
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver *iterp = iter;
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver return (ISC_R_SUCCESS);
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver failure:
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver#ifdef __linux
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver if (iter->proc != NULL)
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver fclose(iter->proc);
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver#endif
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver if (iter->ifaddrs != NULL) /* just in case */
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver freeifaddrs(iter->ifaddrs);
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver isc_mem_put(mctx, iter, sizeof(*iter));
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver return (result);
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver}
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver/*
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver * Get information about the current interface to iter->current.
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver * If successful, return ISC_R_SUCCESS.
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver * If the interface has an unsupported address family,
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver * return ISC_R_IGNORE.
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver */
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryverstatic isc_result_t
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryverinternal_current(isc_interfaceiter_t *iter) {
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver struct ifaddrs *ifa;
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver int family;
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver unsigned int namelen;
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver REQUIRE(VALID_IFITER(iter));
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver ifa = iter->pos;
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver#ifdef __linux
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver if (iter->pos == NULL)
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver return (linux_if_inet6_current(iter));
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver#endif
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver INSIST(ifa != NULL);
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver INSIST(ifa->ifa_name != NULL);
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver if (ifa->ifa_addr == NULL)
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver return (ISC_R_IGNORE);
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt family = ifa->ifa_addr->sa_family;
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt if (family != AF_INET && family != AF_INET6)
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt return (ISC_R_IGNORE);
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt#ifdef __linux
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt if (family == AF_INET6)
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt seenv6 = ISC_TRUE;
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt#endif
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt memset(&iter->current, 0, sizeof(iter->current));
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt namelen = strlen(ifa->ifa_name);
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt if (namelen > sizeof(iter->current.name) - 1)
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt namelen = sizeof(iter->current.name) - 1;
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt memset(iter->current.name, 0, sizeof(iter->current.name));
3a26e75e3c475b6f2f34716fa2847bf015db57c5Mark Andrews memcpy(iter->current.name, ifa->ifa_name, namelen);
3a26e75e3c475b6f2f34716fa2847bf015db57c5Mark Andrews
3a26e75e3c475b6f2f34716fa2847bf015db57c5Mark Andrews iter->current.flags = 0;
3a26e75e3c475b6f2f34716fa2847bf015db57c5Mark Andrews
3a26e75e3c475b6f2f34716fa2847bf015db57c5Mark Andrews if ((ifa->ifa_flags & IFF_UP) != 0)
536098609270345606f4e442064bd15b19d1768eMark Andrews iter->current.flags |= INTERFACE_F_UP;
3a26e75e3c475b6f2f34716fa2847bf015db57c5Mark Andrews
3a26e75e3c475b6f2f34716fa2847bf015db57c5Mark Andrews if ((ifa->ifa_flags & IFF_POINTOPOINT) != 0)
3a26e75e3c475b6f2f34716fa2847bf015db57c5Mark Andrews iter->current.flags |= INTERFACE_F_POINTTOPOINT;
3a26e75e3c475b6f2f34716fa2847bf015db57c5Mark Andrews
3a26e75e3c475b6f2f34716fa2847bf015db57c5Mark Andrews if ((ifa->ifa_flags & IFF_LOOPBACK) != 0)
3a26e75e3c475b6f2f34716fa2847bf015db57c5Mark Andrews iter->current.flags |= INTERFACE_F_LOOPBACK;
3a26e75e3c475b6f2f34716fa2847bf015db57c5Mark Andrews
3a26e75e3c475b6f2f34716fa2847bf015db57c5Mark Andrews iter->current.af = family;
3a26e75e3c475b6f2f34716fa2847bf015db57c5Mark Andrews
3a26e75e3c475b6f2f34716fa2847bf015db57c5Mark Andrews get_addr(family, &iter->current.address, ifa->ifa_addr, ifa->ifa_name);
3a26e75e3c475b6f2f34716fa2847bf015db57c5Mark Andrews
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver if (ifa->ifa_netmask != NULL)
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver get_addr(family, &iter->current.netmask, ifa->ifa_netmask,
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver ifa->ifa_name);
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver if (ifa->ifa_dstaddr != NULL &&
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver (iter->current.flags & IFF_POINTOPOINT) != 0)
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver get_addr(family, &iter->current.dstaddress, ifa->ifa_dstaddr,
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver ifa->ifa_name);
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver return (ISC_R_SUCCESS);
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver}
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver/*
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver * Step the iterator to the next interface. Unlike
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver * isc_interfaceiter_next(), this may leave the iterator
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver * positioned on an interface that will ultimately
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt * be ignored. Return ISC_R_NOMORE if there are no more
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver * interfaces, otherwise ISC_R_SUCCESS.
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver */
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverstatic isc_result_t
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryverinternal_next(isc_interfaceiter_t *iter) {
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver if (iter->pos != NULL)
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver iter->pos = iter->pos->ifa_next;
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt if (iter->pos == NULL) {
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt#ifdef __linux
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt if (!seenv6)
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt return (linux_if_inet6_next(iter));
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt#endif
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt return (ISC_R_NOMORE);
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver }
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver return (ISC_R_SUCCESS);
cef76ee5bd845a80e06da934edce4225bdba22a1Mark Andrews}
cef76ee5bd845a80e06da934edce4225bdba22a1Mark Andrews
cef76ee5bd845a80e06da934edce4225bdba22a1Mark Andrewsstatic void
cef76ee5bd845a80e06da934edce4225bdba22a1Mark Andrewsinternal_destroy(isc_interfaceiter_t *iter) {
cef76ee5bd845a80e06da934edce4225bdba22a1Mark Andrews
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver#ifdef __linux
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt if (iter->proc != NULL)
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt fclose(iter->proc);
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt iter->proc = NULL;
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt#endif
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt if (iter->ifaddrs)
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt freeifaddrs(iter->ifaddrs);
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt iter->ifaddrs = NULL;
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver}
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverstatic
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryvervoid internal_first(isc_interfaceiter_t *iter) {
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver#ifdef __linux
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver linux_if_inet6_first(iter);
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver#endif
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver iter->pos = iter->ifaddrs;
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver}
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver