6fb9b25791778f69002eb72be6235e20d98ec452Tinderbox User * Copyright (C) 2003-2005, 2007-2009, 2014, 2016 Internet Systems Consortium, Inc. ("ISC")
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt/* $Id: ifiter_getifaddrs.c,v 1.13 2009/09/24 23:48:13 tbox Exp $ */
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt * Obtain the list of network interfaces using the getifaddrs(3) library.
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt/*% Iterator Magic */
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt/*% Valid Iterator */
dcf426e9b546d4bcc0681904551752af43c1bcd6Evan Hunt#define VALID_IFITER(t) ISC_MAGIC_VALID(t, IFITER_MAGIC)
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt/*% Iterator structure */
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt struct ifaddrs *pos; /*%< Ptr to current ifaddr */
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt isc_interface_t current; /*%< Current interface data. */
55e5c51e661e23e24573db84114a3837817745c9Evan Huntisc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) {
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt * Only open "/proc/net/if_inet6" if we have never seen a IPv6
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt * address returned by getifaddrs().
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt "getting interface "
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt "addresses: getifaddrs: %s"),
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt * A newly created iterator has an undefined position
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt * until isc_interfaceiter_first() is called.
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt * Get information about the current interface to iter->current.
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt * If successful, return ISC_R_SUCCESS.
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt * If the interface has an unsupported address family,
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt * return ISC_R_IGNORE.
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt memset(iter->current.name, 0, sizeof(iter->current.name));
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt memmove(iter->current.name, ifa->ifa_name, namelen);
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt get_addr(family, &iter->current.address, ifa->ifa_addr, ifa->ifa_name);
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt get_addr(family, &iter->current.netmask, ifa->ifa_netmask,
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt (iter->current.flags & INTERFACE_F_POINTTOPOINT) != 0)
609b8d08176469485edce25f3c2f50365bbd3819Mark Andrews get_addr(family, &iter->current.dstaddress, ifa->ifa_dstaddr,
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt * Step the iterator to the next interface. Unlike
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt * isc_interfaceiter_next(), this may leave the iterator
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt * positioned on an interface that will ultimately
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt * be ignored. Return ISC_R_NOMORE if there are no more
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt * interfaces, otherwise ISC_R_SUCCESS.