1 /*	$NetBSD: interfaceiter.h,v 1.4 2014/12/10 04:38:00 christos Exp $	*/
2 
3 /*
4  * Copyright (C) 2004-2007  Internet Systems Consortium, Inc. ("ISC")
5  * Copyright (C) 1999-2001  Internet Software Consortium.
6  *
7  * Permission to use, copy, modify, and/or distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /* Id: interfaceiter.h,v 1.17 2007/06/19 23:47:18 tbox Exp  */
21 
22 #ifndef ISC_INTERFACEITER_H
23 #define ISC_INTERFACEITER_H 1
24 
25 /*****
26  ***** Module Info
27  *****/
28 
29 /*! \file isc/interfaceiter.h
30  * \brief Iterates over the list of network interfaces.
31  *
32  * Interfaces whose address family is not supported are ignored and never
33  * returned by the iterator.  Interfaces whose netmask, interface flags,
34  * or similar cannot be obtained are also ignored, and the failure is logged.
35  *
36  * Standards:
37  *	The API for scanning varies greatly among operating systems.
38  *	This module attempts to hide the differences.
39  */
40 
41 /***
42  *** Imports
43  ***/
44 
45 #include <isc/lang.h>
46 #include <isc/netaddr.h>
47 #include <isc/types.h>
48 
49 /*!
50  * \brief Public structure describing a network interface.
51  */
52 
53 struct isc_interface {
54 	char name[32];			/*%< Interface name, null-terminated. */
55 	unsigned int af;		/*%< Address family. */
56 	isc_netaddr_t address;		/*%< Local address. */
57 	isc_netaddr_t netmask;		/*%< Network mask. */
58 	isc_netaddr_t dstaddress; 	/*%< Destination address (point-to-point only). */
59 	isc_uint32_t flags;		/*%< Flags; see INTERFACE flags. */
60 };
61 
62 /*@{*/
63 /*! Interface flags. */
64 
65 #define INTERFACE_F_UP			0x00000001U
66 #define INTERFACE_F_POINTTOPOINT	0x00000002U
67 #define INTERFACE_F_LOOPBACK		0x00000004U
68 /*@}*/
69 
70 /***
71  *** Functions
72  ***/
73 
74 ISC_LANG_BEGINDECLS
75 
76 isc_result_t
77 isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp);
78 /*!<
79  * \brief Create an iterator for traversing the operating system's list
80  * of network interfaces.
81  *
82  * Returns:
83  *\li	#ISC_R_SUCCESS
84  * \li	#ISC_R_NOMEMORY
85  *\li	Various network-related errors
86  */
87 
88 isc_result_t
89 isc_interfaceiter_first(isc_interfaceiter_t *iter);
90 /*!<
91  * \brief Position the iterator on the first interface.
92  *
93  * Returns:
94  *\li	#ISC_R_SUCCESS		Success.
95  *\li	#ISC_R_NOMORE		There are no interfaces.
96  */
97 
98 isc_result_t
99 isc_interfaceiter_current(isc_interfaceiter_t *iter,
100 			  isc_interface_t *ifdata);
101 /*!<
102  * \brief Get information about the interface the iterator is currently
103  * positioned at and store it at *ifdata.
104  *
105  * Requires:
106  *\li 	The iterator has been successfully positioned using
107  * 	isc_interface_iter_first() / isc_interface_iter_next().
108  *
109  * Returns:
110  *\li	#ISC_R_SUCCESS		Success.
111  */
112 
113 isc_result_t
114 isc_interfaceiter_next(isc_interfaceiter_t *iter);
115 /*!<
116  * \brief Position the iterator on the next interface.
117  *
118  * Requires:
119  * \li	The iterator has been successfully positioned using
120  * 	isc_interface_iter_first() / isc_interface_iter_next().
121  *
122  * Returns:
123  *\li	#ISC_R_SUCCESS		Success.
124  *\li	#ISC_R_NOMORE		There are no more interfaces.
125  */
126 
127 void
128 isc_interfaceiter_destroy(isc_interfaceiter_t **iterp);
129 /*!<
130  * \brief Destroy the iterator.
131  */
132 
133 ISC_LANG_ENDDECLS
134 
135 #endif /* ISC_INTERFACEITER_H */
136