/contrib/ntp/include/isc/sockaddr.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 202 lines · 65 code · 29 blank · 108 comment · 0 complexity · 90d66bc20da58a1c69ee9f54c1b793a1 MD5 · raw file

  1. /*
  2. * Copyright (C) 1998-2002 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: sockaddr.h,v 1.39 2002/04/03 06:38:36 marka Exp $ */
  18. #ifndef ISC_SOCKADDR_H
  19. #define ISC_SOCKADDR_H 1
  20. #include <isc/lang.h>
  21. #include <isc/net.h>
  22. #include <isc/types.h>
  23. struct isc_sockaddr {
  24. union {
  25. struct sockaddr sa;
  26. struct sockaddr_in sin;
  27. struct sockaddr_in6 sin6;
  28. } type;
  29. unsigned int length; /* XXXRTH beginning? */
  30. ISC_LINK(struct isc_sockaddr) link;
  31. };
  32. typedef ISC_LIST(struct isc_sockaddr) isc_sockaddrlist_t;
  33. ISC_LANG_BEGINDECLS
  34. isc_boolean_t
  35. isc_sockaddr_equal(const isc_sockaddr_t *a, const isc_sockaddr_t *b);
  36. /*
  37. * Return ISC_TRUE iff the socket addresses 'a' and 'b' are equal.
  38. */
  39. isc_boolean_t
  40. isc_sockaddr_eqaddr(const isc_sockaddr_t *a, const isc_sockaddr_t *b);
  41. /*
  42. * Return ISC_TRUE iff the address parts of the socket addresses
  43. * 'a' and 'b' are equal, ignoring the ports.
  44. */
  45. isc_boolean_t
  46. isc_sockaddr_eqaddrprefix(const isc_sockaddr_t *a, const isc_sockaddr_t *b,
  47. unsigned int prefixlen);
  48. /*
  49. * Return ISC_TRUE iff the most significant 'prefixlen' bits of the
  50. * socket addresses 'a' and 'b' are equal, ignoring the ports.
  51. */
  52. unsigned int
  53. isc_sockaddr_hash(const isc_sockaddr_t *sockaddr, isc_boolean_t address_only);
  54. /*
  55. * Return a hash value for the socket address 'sockaddr'. If 'address_only'
  56. * is ISC_TRUE, the hash value will not depend on the port.
  57. *
  58. * IPv6 addresses containing mapped IPv4 addresses generate the same hash
  59. * value as the equivalent IPv4 address.
  60. */
  61. void
  62. isc_sockaddr_any(isc_sockaddr_t *sockaddr);
  63. /*
  64. * Return the IPv4 wildcard address.
  65. */
  66. void
  67. isc_sockaddr_any6(isc_sockaddr_t *sockaddr);
  68. /*
  69. * Return the IPv6 wildcard address.
  70. */
  71. void
  72. isc_sockaddr_anyofpf(isc_sockaddr_t *sockaddr, int family);
  73. /*
  74. * Set '*sockaddr' to the wildcard address of protocol family
  75. * 'family'.
  76. *
  77. * Requires:
  78. * 'family' is AF_INET or AF_INET6.
  79. */
  80. void
  81. isc_sockaddr_fromin(isc_sockaddr_t *sockaddr, const struct in_addr *ina,
  82. in_port_t port);
  83. /*
  84. * Construct an isc_sockaddr_t from an IPv4 address and port.
  85. */
  86. void
  87. isc_sockaddr_fromin6(isc_sockaddr_t *sockaddr, const struct in6_addr *ina6,
  88. in_port_t port);
  89. /*
  90. * Construct an isc_sockaddr_t from an IPv6 address and port.
  91. */
  92. void
  93. isc_sockaddr_v6fromin(isc_sockaddr_t *sockaddr, const struct in_addr *ina,
  94. in_port_t port);
  95. /*
  96. * Construct an IPv6 isc_sockaddr_t representing a mapped IPv4 address.
  97. */
  98. void
  99. isc_sockaddr_fromnetaddr(isc_sockaddr_t *sockaddr, const isc_netaddr_t *na,
  100. in_port_t port);
  101. /*
  102. * Construct an isc_sockaddr_t from an isc_netaddr_t and port.
  103. */
  104. int
  105. isc_sockaddr_pf(const isc_sockaddr_t *sockaddr);
  106. /*
  107. * Get the protocol family of 'sockaddr'.
  108. *
  109. * Requires:
  110. *
  111. * 'sockaddr' is a valid sockaddr with an address family of AF_INET
  112. * or AF_INET6.
  113. *
  114. * Returns:
  115. *
  116. * The protocol family of 'sockaddr', e.g. PF_INET or PF_INET6.
  117. */
  118. void
  119. isc_sockaddr_setport(isc_sockaddr_t *sockaddr, in_port_t port);
  120. /*
  121. * Set the port of 'sockaddr' to 'port'.
  122. */
  123. in_port_t
  124. isc_sockaddr_getport(isc_sockaddr_t *sockaddr);
  125. /*
  126. * Get the port stored in 'sockaddr'.
  127. */
  128. isc_result_t
  129. isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target);
  130. /*
  131. * Append a text representation of 'sockaddr' to the buffer 'target'.
  132. * The text will include both the IP address (v4 or v6) and the port.
  133. * The text is null terminated, but the terminating null is not
  134. * part of the buffer's used region.
  135. *
  136. * Returns:
  137. * ISC_R_SUCCESS
  138. * ISC_R_NOSPACE The text or the null termination did not fit.
  139. */
  140. void
  141. isc_sockaddr_format(const isc_sockaddr_t *sa, char *array, unsigned int size);
  142. /*
  143. * Format a human-readable representation of the socket address '*sa'
  144. * into the character array 'array', which is of size 'size'.
  145. * The resulting string is guaranteed to be null-terminated.
  146. */
  147. isc_boolean_t
  148. isc_sockaddr_ismulticast(isc_sockaddr_t *sa);
  149. /*
  150. * Returns ISC_TRUE if the address is a multicast address.
  151. */
  152. isc_boolean_t
  153. isc_sockaddr_isexperimental(isc_sockaddr_t *sa);
  154. /*
  155. * Returns ISC_TRUE if the address is a experimental (CLASS E) address.
  156. */
  157. isc_boolean_t
  158. isc_sockaddr_islinklocal(isc_sockaddr_t *sa);
  159. /*
  160. * Returns ISC_TRUE if the address is a link local addresss.
  161. */
  162. isc_boolean_t
  163. isc_sockaddr_issitelocal(isc_sockaddr_t *sa);
  164. /*
  165. * Returns ISC_TRUE if the address is a sitelocal address.
  166. */
  167. #define ISC_SOCKADDR_FORMATSIZE \
  168. sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:XXX.XXX.XXX.XXX#YYYYY")
  169. /*
  170. * Minimum size of array to pass to isc_sockaddr_format().
  171. */
  172. ISC_LANG_ENDDECLS
  173. #endif /* ISC_SOCKADDR_H */