/contrib/ntp/include/isc/interfaceiter.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 139 lines · 35 code · 19 blank · 85 comment · 0 complexity · 6e23f6faef48da65aac2802eecbd0bb6 MD5 · raw file

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