1135446Strhodes/*
2193149Sdougb * Copyright (C) 2004-2007  Internet Systems Consortium, Inc. ("ISC")
3135446Strhodes * Copyright (C) 1999-2001  Internet Software Consortium.
4135446Strhodes *
5193149Sdougb * Permission to use, copy, modify, and/or distribute this software for any
6135446Strhodes * purpose with or without fee is hereby granted, provided that the above
7135446Strhodes * copyright notice and this permission notice appear in all copies.
8135446Strhodes *
9135446Strhodes * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10135446Strhodes * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11135446Strhodes * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12135446Strhodes * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13135446Strhodes * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14135446Strhodes * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15135446Strhodes * PERFORMANCE OF THIS SOFTWARE.
16135446Strhodes */
17135446Strhodes
18234010Sdougb/* $Id: interfaceiter.h,v 1.17 2007/06/19 23:47:18 tbox Exp $ */
19135446Strhodes
20135446Strhodes#ifndef ISC_INTERFACEITER_H
21135446Strhodes#define ISC_INTERFACEITER_H 1
22135446Strhodes
23135446Strhodes/*****
24135446Strhodes ***** Module Info
25135446Strhodes *****/
26135446Strhodes
27193149Sdougb/*! \file isc/interfaceiter.h
28170222Sdougb * \brief Iterates over the list of network interfaces.
29135446Strhodes *
30135446Strhodes * Interfaces whose address family is not supported are ignored and never
31135446Strhodes * returned by the iterator.  Interfaces whose netmask, interface flags,
32135446Strhodes * or similar cannot be obtained are also ignored, and the failure is logged.
33135446Strhodes *
34135446Strhodes * Standards:
35135446Strhodes *	The API for scanning varies greatly among operating systems.
36135446Strhodes *	This module attempts to hide the differences.
37135446Strhodes */
38135446Strhodes
39135446Strhodes/***
40135446Strhodes *** Imports
41135446Strhodes ***/
42135446Strhodes
43135446Strhodes#include <isc/lang.h>
44135446Strhodes#include <isc/netaddr.h>
45135446Strhodes#include <isc/types.h>
46135446Strhodes
47170222Sdougb/*!
48170222Sdougb * \brief Public structure describing a network interface.
49135446Strhodes */
50135446Strhodes
51135446Strhodesstruct isc_interface {
52170222Sdougb	char name[32];			/*%< Interface name, null-terminated. */
53170222Sdougb	unsigned int af;		/*%< Address family. */
54170222Sdougb	isc_netaddr_t address;		/*%< Local address. */
55170222Sdougb	isc_netaddr_t netmask;		/*%< Network mask. */
56170222Sdougb	isc_netaddr_t dstaddress; 	/*%< Destination address (point-to-point only). */
57170222Sdougb	isc_uint32_t flags;		/*%< Flags; see INTERFACE flags. */
58135446Strhodes};
59135446Strhodes
60170222Sdougb/*@{*/
61170222Sdougb/*! Interface flags. */
62135446Strhodes
63135446Strhodes#define INTERFACE_F_UP			0x00000001U
64135446Strhodes#define INTERFACE_F_POINTTOPOINT	0x00000002U
65135446Strhodes#define INTERFACE_F_LOOPBACK		0x00000004U
66170222Sdougb/*@}*/
67135446Strhodes
68135446Strhodes/***
69135446Strhodes *** Functions
70135446Strhodes ***/
71135446Strhodes
72135446StrhodesISC_LANG_BEGINDECLS
73135446Strhodes
74135446Strhodesisc_result_t
75135446Strhodesisc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp);
76170222Sdougb/*!<
77170222Sdougb * \brief Create an iterator for traversing the operating system's list
78135446Strhodes * of network interfaces.
79135446Strhodes *
80135446Strhodes * Returns:
81170222Sdougb *\li	#ISC_R_SUCCESS
82170222Sdougb * \li	#ISC_R_NOMEMORY
83170222Sdougb *\li	Various network-related errors
84135446Strhodes */
85135446Strhodes
86135446Strhodesisc_result_t
87135446Strhodesisc_interfaceiter_first(isc_interfaceiter_t *iter);
88170222Sdougb/*!<
89170222Sdougb * \brief Position the iterator on the first interface.
90135446Strhodes *
91135446Strhodes * Returns:
92170222Sdougb *\li	#ISC_R_SUCCESS		Success.
93170222Sdougb *\li	#ISC_R_NOMORE		There are no interfaces.
94135446Strhodes */
95135446Strhodes
96135446Strhodesisc_result_t
97135446Strhodesisc_interfaceiter_current(isc_interfaceiter_t *iter,
98135446Strhodes			  isc_interface_t *ifdata);
99170222Sdougb/*!<
100170222Sdougb * \brief Get information about the interface the iterator is currently
101135446Strhodes * positioned at and store it at *ifdata.
102135446Strhodes *
103135446Strhodes * Requires:
104170222Sdougb *\li 	The iterator has been successfully positioned using
105135446Strhodes * 	isc_interface_iter_first() / isc_interface_iter_next().
106135446Strhodes *
107135446Strhodes * Returns:
108170222Sdougb *\li	#ISC_R_SUCCESS		Success.
109135446Strhodes */
110135446Strhodes
111135446Strhodesisc_result_t
112135446Strhodesisc_interfaceiter_next(isc_interfaceiter_t *iter);
113170222Sdougb/*!<
114170222Sdougb * \brief Position the iterator on the next interface.
115135446Strhodes *
116135446Strhodes * Requires:
117170222Sdougb * \li	The iterator has been successfully positioned using
118135446Strhodes * 	isc_interface_iter_first() / isc_interface_iter_next().
119135446Strhodes *
120135446Strhodes * Returns:
121170222Sdougb *\li	#ISC_R_SUCCESS		Success.
122170222Sdougb *\li	#ISC_R_NOMORE		There are no more interfaces.
123135446Strhodes */
124135446Strhodes
125135446Strhodesvoid
126135446Strhodesisc_interfaceiter_destroy(isc_interfaceiter_t **iterp);
127170222Sdougb/*!<
128170222Sdougb * \brief Destroy the iterator.
129135446Strhodes */
130135446Strhodes
131135446StrhodesISC_LANG_ENDDECLS
132135446Strhodes
133135446Strhodes#endif /* ISC_INTERFACEITER_H */
134