/contrib/bind9/lib/isc/include/isc/interfaceiter.h

https://bitbucket.org/freebsd/freebsd-head/ · C Header · 133 lines · 30 code · 19 blank · 84 comment · 0 complexity · f4992182f955d735e1faf67eb83ce233 MD5 · raw file

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