1258945Sroberto/* 2258945Sroberto * Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC") 3258945Sroberto * Copyright (C) 1999-2001 Internet Software Consortium. 4258945Sroberto * 5258945Sroberto * Permission to use, copy, modify, and/or distribute this software for any 6258945Sroberto * purpose with or without fee is hereby granted, provided that the above 7258945Sroberto * copyright notice and this permission notice appear in all copies. 8258945Sroberto * 9258945Sroberto * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10258945Sroberto * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11258945Sroberto * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12258945Sroberto * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13258945Sroberto * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14258945Sroberto * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15258945Sroberto * PERFORMANCE OF THIS SOFTWARE. 16258945Sroberto */ 17258945Sroberto 18258945Sroberto/* $Id: interfaceiter.h,v 1.17 2007/06/19 23:47:18 tbox Exp $ */ 19258945Sroberto 20258945Sroberto#ifndef ISC_INTERFACEITER_H 21258945Sroberto#define ISC_INTERFACEITER_H 1 22258945Sroberto 23258945Sroberto/***** 24258945Sroberto ***** Module Info 25258945Sroberto *****/ 26258945Sroberto 27258945Sroberto/*! \file isc/interfaceiter.h 28258945Sroberto * \brief Iterates over the list of network interfaces. 29258945Sroberto * 30258945Sroberto * Interfaces whose address family is not supported are ignored and never 31258945Sroberto * returned by the iterator. Interfaces whose netmask, interface flags, 32258945Sroberto * or similar cannot be obtained are also ignored, and the failure is logged. 33258945Sroberto * 34258945Sroberto * Standards: 35258945Sroberto * The API for scanning varies greatly among operating systems. 36258945Sroberto * This module attempts to hide the differences. 37258945Sroberto */ 38258945Sroberto 39258945Sroberto/*** 40258945Sroberto *** Imports 41258945Sroberto ***/ 42258945Sroberto 43258945Sroberto#include <isc/lang.h> 44258945Sroberto#include <isc/netaddr.h> 45258945Sroberto#include <isc/types.h> 46258945Sroberto 47258945Sroberto/*! 48258945Sroberto * \brief Public structure describing a network interface. 49258945Sroberto */ 50258945Sroberto 51258945Srobertostruct isc_interface { 52258945Sroberto char name[32]; /*%< Interface name, null-terminated. */ 53258945Sroberto unsigned int af; /*%< Address family. */ 54258945Sroberto isc_netaddr_t address; /*%< Local address. */ 55258945Sroberto isc_netaddr_t netmask; /*%< Network mask. */ 56258945Sroberto isc_netaddr_t broadcast; /*&< Broadcast address. */ 57258945Sroberto isc_netaddr_t dstaddress; /*%< Destination address (point-to-point only). */ 58258945Sroberto isc_uint32_t flags; /*%< Flags; see INTERFACE flags. */ 59258945Sroberto unsigned int ifindex; /*%< Interface index for IP(V6)_MULTICAST_IF. */ 60258945Sroberto}; 61258945Sroberto 62258945Sroberto/*@{*/ 63258945Sroberto/*! Interface flags. */ 64258945Sroberto 65258945Sroberto#define INTERFACE_F_UP 0x00000001U 66258945Sroberto#define INTERFACE_F_POINTTOPOINT 0x00000002U 67258945Sroberto#define INTERFACE_F_LOOPBACK 0x00000004U 68258945Sroberto#define INTERFACE_F_BROADCAST 0x00000008U 69258945Sroberto#define INTERFACE_F_MULTICAST 0x00000010U 70258945Sroberto#define INTERFACE_F_PRIVACY 0x00000020U /* RFC 4941 */ 71258945Sroberto/*@}*/ 72258945Sroberto 73258945Sroberto/*** 74258945Sroberto *** Functions 75258945Sroberto ***/ 76258945Sroberto 77258945SrobertoISC_LANG_BEGINDECLS 78258945Sroberto 79258945Srobertoisc_result_t 80258945Srobertoisc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp); 81258945Sroberto/*!< 82258945Sroberto * \brief Create an iterator for traversing the operating system's list 83258945Sroberto * of network interfaces. 84258945Sroberto * 85258945Sroberto * Returns: 86258945Sroberto *\li #ISC_R_SUCCESS 87258945Sroberto * \li #ISC_R_NOMEMORY 88258945Sroberto *\li Various network-related errors 89258945Sroberto */ 90258945Sroberto 91258945Srobertoisc_result_t 92258945Srobertoisc_interfaceiter_first(isc_interfaceiter_t *iter); 93258945Sroberto/*!< 94258945Sroberto * \brief Position the iterator on the first interface. 95258945Sroberto * 96258945Sroberto * Returns: 97258945Sroberto *\li #ISC_R_SUCCESS Success. 98258945Sroberto *\li #ISC_R_NOMORE There are no interfaces. 99258945Sroberto */ 100258945Sroberto 101258945Srobertoisc_result_t 102258945Srobertoisc_interfaceiter_current(isc_interfaceiter_t *iter, 103258945Sroberto isc_interface_t *ifdata); 104258945Sroberto/*!< 105258945Sroberto * \brief Get information about the interface the iterator is currently 106258945Sroberto * positioned at and store it at *ifdata. 107258945Sroberto * 108258945Sroberto * Requires: 109258945Sroberto *\li The iterator has been successfully positioned using 110258945Sroberto * isc_interface_iter_first() / isc_interface_iter_next(). 111258945Sroberto * 112258945Sroberto * Returns: 113258945Sroberto *\li #ISC_R_SUCCESS Success. 114258945Sroberto */ 115258945Sroberto 116258945Srobertoisc_result_t 117258945Srobertoisc_interfaceiter_next(isc_interfaceiter_t *iter); 118258945Sroberto/*!< 119258945Sroberto * \brief Position the iterator on the next interface. 120258945Sroberto * 121258945Sroberto * Requires: 122258945Sroberto * \li The iterator has been successfully positioned using 123258945Sroberto * isc_interface_iter_first() / isc_interface_iter_next(). 124258945Sroberto * 125258945Sroberto * Returns: 126258945Sroberto *\li #ISC_R_SUCCESS Success. 127258945Sroberto *\li #ISC_R_NOMORE There are no more interfaces. 128258945Sroberto */ 129258945Sroberto 130258945Srobertovoid 131258945Srobertoisc_interfaceiter_destroy(isc_interfaceiter_t **iterp); 132258945Sroberto/*!< 133258945Sroberto * \brief Destroy the iterator. 134258945Sroberto */ 135258945Sroberto 136258945SrobertoISC_LANG_ENDDECLS 137258945Sroberto 138258945Sroberto#endif /* ISC_INTERFACEITER_H */ 139