00001 /* 00002 * Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC") 00003 * Copyright (C) 1999-2001 Internet Software Consortium. 00004 * 00005 * Permission to use, copy, modify, and/or distribute this software for any 00006 * purpose with or without fee is hereby granted, provided that the above 00007 * copyright notice and this permission notice appear in all copies. 00008 * 00009 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 00010 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 00011 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 00012 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 00013 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 00014 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00015 * PERFORMANCE OF THIS SOFTWARE. 00016 */ 00017 00018 /* $Id: interfaceiter.h,v 1.17 2007/06/19 23:47:18 tbox Exp $ */ 00019 00020 #ifndef ISC_INTERFACEITER_H 00021 #define ISC_INTERFACEITER_H 1 00022 00023 /***** 00024 ***** Module Info 00025 *****/ 00026 00027 /*! \file isc/interfaceiter.h 00028 * \brief Iterates over the list of network interfaces. 00029 * 00030 * Interfaces whose address family is not supported are ignored and never 00031 * returned by the iterator. Interfaces whose netmask, interface flags, 00032 * or similar cannot be obtained are also ignored, and the failure is logged. 00033 * 00034 * Standards: 00035 * The API for scanning varies greatly among operating systems. 00036 * This module attempts to hide the differences. 00037 */ 00038 00039 /*** 00040 *** Imports 00041 ***/ 00042 00043 #include <isc/lang.h> 00044 #include <isc/netaddr.h> 00045 #include <isc/types.h> 00046 00047 /*! 00048 * \brief Public structure describing a network interface. 00049 */ 00050 00051 struct isc_interface { 00052 char name[32]; /*%< Interface name, null-terminated. */ 00053 unsigned int af; /*%< Address family. */ 00054 isc_netaddr_t address; /*%< Local address. */ 00055 isc_netaddr_t netmask; /*%< Network mask. */ 00056 isc_netaddr_t dstaddress; /*%< Destination address (point-to-point only). */ 00057 isc_uint32_t flags; /*%< Flags; see INTERFACE flags. */ 00058 }; 00059 00060 /*@{*/ 00061 /*! Interface flags. */ 00062 00063 #define INTERFACE_F_UP 0x00000001U 00064 #define INTERFACE_F_POINTTOPOINT 0x00000002U 00065 #define INTERFACE_F_LOOPBACK 0x00000004U 00066 /*@}*/ 00067 00068 /*** 00069 *** Functions 00070 ***/ 00071 00072 ISC_LANG_BEGINDECLS 00073 00074 isc_result_t 00075 isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp); 00076 /*!< 00077 * \brief Create an iterator for traversing the operating system's list 00078 * of network interfaces. 00079 * 00080 * Returns: 00081 *\li #ISC_R_SUCCESS 00082 * \li #ISC_R_NOMEMORY 00083 *\li Various network-related errors 00084 */ 00085 00086 isc_result_t 00087 isc_interfaceiter_first(isc_interfaceiter_t *iter); 00088 /*!< 00089 * \brief Position the iterator on the first interface. 00090 * 00091 * Returns: 00092 *\li #ISC_R_SUCCESS Success. 00093 *\li #ISC_R_NOMORE There are no interfaces. 00094 */ 00095 00096 isc_result_t 00097 isc_interfaceiter_current(isc_interfaceiter_t *iter, 00098 isc_interface_t *ifdata); 00099 /*!< 00100 * \brief Get information about the interface the iterator is currently 00101 * positioned at and store it at *ifdata. 00102 * 00103 * Requires: 00104 *\li The iterator has been successfully positioned using 00105 * isc_interface_iter_first() / isc_interface_iter_next(). 00106 * 00107 * Returns: 00108 *\li #ISC_R_SUCCESS Success. 00109 */ 00110 00111 isc_result_t 00112 isc_interfaceiter_next(isc_interfaceiter_t *iter); 00113 /*!< 00114 * \brief Position the iterator on the next interface. 00115 * 00116 * Requires: 00117 * \li The iterator has been successfully positioned using 00118 * isc_interface_iter_first() / isc_interface_iter_next(). 00119 * 00120 * Returns: 00121 *\li #ISC_R_SUCCESS Success. 00122 *\li #ISC_R_NOMORE There are no more interfaces. 00123 */ 00124 00125 void 00126 isc_interfaceiter_destroy(isc_interfaceiter_t **iterp); 00127 /*!< 00128 * \brief Destroy the iterator. 00129 */ 00130 00131 ISC_LANG_ENDDECLS 00132 00133 #endif /* ISC_INTERFACEITER_H */