bind9/lib/isc/include/isc/interfaceiter.h
Evan Hunt 10accd6260 clean up uses of ISC_R_NOMEMORY
the isc_mem allocation functions can no longer fail; as a result,
ISC_R_NOMEMORY is now rarely used: only when an external library
such as libjson-c or libfstrm could return NULL. (even in
these cases, arguably we should assert rather than returning
ISC_R_NOMEMORY.)

code and comments that mentioned ISC_R_NOMEMORY have been
cleaned up, and the following functions have been changed to
type void, since (in most cases) the only value they could
return was ISC_R_SUCCESS:

- dns_dns64_create()
- dns_dyndb_create()
- dns_ipkeylist_resize()
- dns_kasp_create()
- dns_kasp_key_create()
- dns_keystore_create()
- dns_order_create()
- dns_order_add()
- dns_peerlist_new()
- dns_tkeyctx_create()
- dns_view_create()
- dns_zone_setorigin()
- dns_zone_setfile()
- dns_zone_setstream()
- dns_zone_getdbtype()
- dns_zone_setjournal()
- dns_zone_setkeydirectory()
- isc_lex_openstream()
- isc_portset_create()
- isc_symtab_create()

(the exception is dns_view_create(), which could have returned
other error codes in the event of a crypto library failure when
calling isc_file_sanitize(), but that should be a RUNTIME_CHECK
anyway.)
2025-01-23 15:54:57 -08:00

121 lines
2.9 KiB
C

/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* SPDX-License-Identifier: MPL-2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
#pragma once
/*****
***** Module Info
*****/
/*! \file isc/interfaceiter.h
* \brief Iterates over the list of network interfaces.
*
* Interfaces whose address family is not supported are ignored and never
* returned by the iterator. Interfaces whose netmask, interface flags,
* or similar cannot be obtained are also ignored, and the failure is logged.
*
* Standards:
* The API for scanning varies greatly among operating systems.
* This module attempts to hide the differences.
*/
/***
*** Imports
***/
#include <inttypes.h>
#include <isc/netaddr.h>
#include <isc/types.h>
/*!
* \brief Public structure describing a network interface.
*/
struct isc_interface {
char name[32]; /*%< Interface name, null-terminated. */
unsigned int af; /*%< Address family. */
isc_netaddr_t address; /*%< Local address. */
isc_netaddr_t netmask; /*%< Network mask. */
isc_netaddr_t dstaddress; /*%< Destination address
* (point-to-point
* only). */
uint32_t flags; /*%< Flags; see INTERFACE flags. */
};
/*@{*/
/*! Interface flags. */
#define INTERFACE_F_UP 0x00000001U
#define INTERFACE_F_POINTTOPOINT 0x00000002U
#define INTERFACE_F_LOOPBACK 0x00000004U
/*@}*/
/***
*** Functions
***/
isc_result_t
isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp);
/*!<
* \brief Create an iterator for traversing the operating system's list
* of network interfaces.
*
* Returns:
*\li #ISC_R_SUCCESS
*\li Various network-related errors
*/
isc_result_t
isc_interfaceiter_first(isc_interfaceiter_t *iter);
/*!<
* \brief Position the iterator on the first interface.
*
* Returns:
*\li #ISC_R_SUCCESS Success.
*\li #ISC_R_NOMORE There are no interfaces.
*/
isc_result_t
isc_interfaceiter_current(isc_interfaceiter_t *iter, isc_interface_t *ifdata);
/*!<
* \brief Get information about the interface the iterator is currently
* positioned at and store it at *ifdata.
*
* Requires:
*\li The iterator has been successfully positioned using
* isc_interface_iter_first() / isc_interface_iter_next().
*
* Returns:
*\li #ISC_R_SUCCESS Success.
*/
isc_result_t
isc_interfaceiter_next(isc_interfaceiter_t *iter);
/*!<
* \brief Position the iterator on the next interface.
*
* Requires:
* \li The iterator has been successfully positioned using
* isc_interface_iter_first() / isc_interface_iter_next().
*
* Returns:
*\li #ISC_R_SUCCESS Success.
*\li #ISC_R_NOMORE There are no more interfaces.
*/
void
isc_interfaceiter_destroy(isc_interfaceiter_t **iterp);
/*!<
* \brief Destroy the iterator.
*/