ip_helper.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  3. * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #ifndef __PJ_IP_ROUTE_H__
  20. #define __PJ_IP_ROUTE_H__
  21. /**
  22. * @file ip_helper.h
  23. * @brief IP helper API
  24. */
  25. #include <pj/sock.h>
  26. #include <pj/string.h>
  27. PJ_BEGIN_DECL
  28. /**
  29. * @defgroup pj_ip_helper IP Interface and Routing Helper
  30. * @ingroup PJ_IO
  31. * @{
  32. *
  33. * This module provides functions to query local host's IP interface and
  34. * routing table.
  35. */
  36. /**
  37. * This structure describes IP routing entry.
  38. */
  39. typedef union pj_ip_route_entry
  40. {
  41. /** IP routing entry for IP version 4 routing */
  42. struct
  43. {
  44. pj_in_addr if_addr; /**< Local interface IP address. */
  45. pj_in_addr dst_addr; /**< Destination IP address. */
  46. pj_in_addr mask; /**< Destination mask. */
  47. } ipv4;
  48. } pj_ip_route_entry;
  49. /**
  50. * This structure describes options for pj_enum_ip_interface2().
  51. */
  52. typedef struct pj_enum_ip_option
  53. {
  54. /**
  55. * Family of the address to be retrieved. Application may specify
  56. * pj_AF_UNSPEC() to retrieve all addresses, or pj_AF_INET() or
  57. * pj_AF_INET6() to retrieve interfaces with specific address family.
  58. *
  59. * Default: pj_AF_UNSPEC().
  60. */
  61. int af;
  62. /**
  63. * IPv6 addresses can have a DEPRECATED flag, if this flag is set, any
  64. * DEPRECATED IPv6 address will be omitted. Currently this is only
  65. * available for Linux, on other platforms, if this flag is set,
  66. * pj_enum_ip_interface2() will return PJ_ENOTSUP.
  67. *
  68. * Default: PJ_FALSE.
  69. */
  70. pj_bool_t omit_deprecated_ipv6;
  71. } pj_enum_ip_option;
  72. /**
  73. * Get default values of IP enumeration option.
  74. *
  75. * @param opt The IP enumeration option.
  76. */
  77. PJ_INLINE(void) pj_enum_ip_option_default(pj_enum_ip_option *opt)
  78. {
  79. pj_bzero(opt, sizeof(*opt));
  80. }
  81. /**
  82. * Enumerate the local IP interfaces currently active in the host.
  83. *
  84. * @param af Family of the address to be retrieved. Application
  85. * may specify pj_AF_UNSPEC() to retrieve all addresses,
  86. * or pj_AF_INET() or pj_AF_INET6() to retrieve interfaces
  87. * with specific address family.
  88. * @param count On input, specify the number of entries. On output,
  89. * it will be filled with the actual number of entries.
  90. * @param ifs Array of socket addresses, which address part will
  91. * be filled with the interface address. The address
  92. * family part will be initialized with the address
  93. * family of the IP address.
  94. *
  95. * @return PJ_SUCCESS on success, or the appropriate error code.
  96. */
  97. PJ_DECL(pj_status_t) pj_enum_ip_interface(int af,
  98. unsigned *count,
  99. pj_sockaddr ifs[]);
  100. /**
  101. * Enumerate the local IP interfaces currently active in the host with
  102. * capability to filter DEPRECATED IPv6 addresses (currently only for Linux).
  103. *
  104. * @param opt The option, default option will be used if NULL.
  105. * @param count On input, specify the number of entries. On output,
  106. * it will be filled with the actual number of entries.
  107. * @param ifs Array of socket (with flags) addresses, which address part
  108. * will be filled with the interface address. The address
  109. * family part will be initialized with the address
  110. * family of the IP address.
  111. *
  112. * @return PJ_SUCCESS on success, or the appropriate error code.
  113. */
  114. PJ_DECL(pj_status_t) pj_enum_ip_interface2(const pj_enum_ip_option *opt,
  115. unsigned *count,
  116. pj_sockaddr ifs[]);
  117. /**
  118. * Enumerate the IP routing table for this host.
  119. *
  120. * @param count On input, specify the number of routes entries. On output,
  121. * it will be filled with the actual number of route entries.
  122. * @param routes Array of IP routing entries.
  123. *
  124. * @return PJ_SUCCESS on success, or the appropriate error code.
  125. */
  126. PJ_DECL(pj_status_t) pj_enum_ip_route(unsigned *count,
  127. pj_ip_route_entry routes[]);
  128. /** @} */
  129. PJ_END_DECL
  130. #endif /* __PJ_IP_ROUTE_H__ */