/contrib/ntp/include/ntp_rfc2553.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 292 lines · 148 code · 32 blank · 112 comment · 13 complexity · 461e4cdef8486c0da5ae2b9632200002 MD5 · raw file

  1. /*
  2. * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the project nor the names of its contributors
  14. * may be used to endorse or promote products derived from this software
  15. * without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. * SUCH DAMAGE.
  28. */
  29. /*
  30. * Copyright (c) 1982, 1986, 1990, 1993
  31. * The Regents of the University of California. All rights reserved.
  32. *
  33. * Redistribution and use in source and binary forms, with or without
  34. * modification, are permitted provided that the following conditions
  35. * are met:
  36. * 1. Redistributions of source code must retain the above copyright
  37. * notice, this list of conditions and the following disclaimer.
  38. * 2. Redistributions in binary form must reproduce the above copyright
  39. * notice, this list of conditions and the following disclaimer in the
  40. * documentation and/or other materials provided with the distribution.
  41. * 3. All advertising materials mentioning features or use of this software
  42. * must display the following acknowledgement:
  43. * This product includes software developed by the University of
  44. * California, Berkeley and its contributors.
  45. * 4. Neither the name of the University nor the names of its contributors
  46. * may be used to endorse or promote products derived from this software
  47. * without specific prior written permission.
  48. *
  49. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  50. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  51. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  52. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  53. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  54. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  55. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  56. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  57. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  58. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  59. * SUCH DAMAGE.
  60. *
  61. * @(#)in.h 8.3 (Berkeley) 1/3/94
  62. */
  63. /*
  64. * Compatability shims with the rfc2553 API to simplify ntp.
  65. */
  66. #ifndef _NTP_RFC2553_H_
  67. #define _NTP_RFC2553_H_
  68. /*
  69. * Ensure that we include the configuration file before we check
  70. * for IPV6
  71. */
  72. #include <config.h>
  73. #include <netdb.h>
  74. #include "ntp_types.h"
  75. /*
  76. * Don't include any additional IPv6 definitions
  77. * We are defining our own here.
  78. */
  79. #define ISC_IPV6_H 1
  80. /*
  81. * If various macros are not defined we need to define them
  82. */
  83. #ifndef AF_INET6
  84. #define AF_INET6 AF_MAX
  85. #define PF_INET6 AF_INET6
  86. #endif
  87. #if !defined(_SS_MAXSIZE) && !defined(_SS_ALIGNSIZE)
  88. #define _SS_MAXSIZE 128
  89. #define _SS_ALIGNSIZE (sizeof(ntp_uint64_t))
  90. #ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR
  91. #define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(u_char) - sizeof(ntp_u_int8_t))
  92. #define _SS_PAD2SIZE (_SS_MAXSIZE - sizeof(u_char) - sizeof(ntp_u_int8_t) - \
  93. _SS_PAD1SIZE - _SS_ALIGNSIZE)
  94. #else
  95. #define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(short))
  96. #define _SS_PAD2SIZE (_SS_MAXSIZE - sizeof(short) - \
  97. _SS_PAD1SIZE - _SS_ALIGNSIZE)
  98. #endif /* HAVE_SA_LEN_IN_STRUCT_SOCKADDR */
  99. #endif
  100. /*
  101. * If we don't have the sockaddr_storage structure
  102. * we need to define it
  103. */
  104. #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
  105. struct sockaddr_storage {
  106. #ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR
  107. ntp_u_int8_t ss_len; /* address length */
  108. ntp_u_int8_t ss_family; /* address family */
  109. #else
  110. short ss_family; /* address family */
  111. #endif
  112. char __ss_pad1[_SS_PAD1SIZE];
  113. ntp_uint64_t __ss_align; /* force desired structure storage alignment */
  114. char __ss_pad2[_SS_PAD2SIZE];
  115. };
  116. #endif
  117. /*
  118. * Finally if the platform doesn't support IPv6 we need some
  119. * additional definitions
  120. */
  121. /*
  122. * Flag values for getaddrinfo()
  123. */
  124. #ifndef AI_NUMERICHOST
  125. #define AI_PASSIVE 0x00000001 /* get address to use bind() */
  126. #define AI_CANONNAME 0x00000002 /* fill ai_canonname */
  127. #define AI_NUMERICHOST 0x00000004 /* prevent name resolution */
  128. /* valid flags for addrinfo */
  129. #define AI_MASK \
  130. (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_ADDRCONFIG)
  131. #define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */
  132. #endif
  133. #ifndef ISC_PLATFORM_HAVEIPV6
  134. /*
  135. * Definition of some useful macros to handle IP6 addresses
  136. */
  137. #ifdef ISC_PLATFORM_NEEDIN6ADDRANY
  138. #ifdef SYS_WINNT
  139. #define IN6ADDR_ANY_INIT {{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }}
  140. #else
  141. #define IN6ADDR_ANY_INIT \
  142. {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  143. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
  144. #endif
  145. #endif
  146. /*
  147. * IPv6 address
  148. */
  149. #ifdef SYS_WINNT
  150. #define in6_addr in_addr6
  151. #else
  152. struct in6_addr {
  153. union {
  154. ntp_u_int8_t __u6_addr8[16];
  155. ntp_u_int16_t __u6_addr16[8];
  156. ntp_u_int32_t __u6_addr32[4];
  157. } __u6_addr; /* 128-bit IP6 address */
  158. };
  159. #define s6_addr __u6_addr.__u6_addr8
  160. #endif
  161. #if defined(ISC_PLATFORM_HAVEIPV6) && defined(ISC_PLATFORM_NEEDIN6ADDRANY)
  162. extern const struct in6_addr in6addr_any;
  163. #endif
  164. #define SIN6_LEN
  165. #ifndef HAVE_SOCKADDR_IN6
  166. struct sockaddr_in6 {
  167. #ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR
  168. ntp_u_int8_t sin6_len; /* length of this struct(sa_family_t)*/
  169. ntp_u_int8_t sin6_family; /* AF_INET6 (sa_family_t) */
  170. #else
  171. short sin6_family; /* AF_INET6 (sa_family_t) */
  172. #endif
  173. ntp_u_int16_t sin6_port; /* Transport layer port # (in_port_t)*/
  174. ntp_u_int32_t sin6_flowinfo; /* IP6 flow information */
  175. struct in6_addr sin6_addr; /* IP6 address */
  176. ntp_u_int32_t sin6_scope_id; /* scope zone index */
  177. };
  178. #endif
  179. /*
  180. * Unspecified
  181. */
  182. #ifndef IN6_IS_ADDR_UNSPECIFIED
  183. #define IN6_IS_ADDR_UNSPECIFIED(a) \
  184. ((*(const ntp_u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \
  185. (*(const ntp_u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \
  186. (*(const ntp_u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \
  187. (*(const ntp_u_int32_t *)(const void *)(&(a)->s6_addr[12]) == 0))
  188. #endif
  189. /*
  190. * Multicast
  191. */
  192. #ifndef IN6_IS_ADDR_MULTICAST
  193. #define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff)
  194. #endif
  195. /*
  196. * Unicast link / site local.
  197. */
  198. #ifndef IN6_IS_ADDR_LINKLOCAL
  199. #define IN6_IS_ADDR_LINKLOCAL(a) (\
  200. (*((u_long *)((a)->s6_addr) ) == 0xfe) && \
  201. ((*((u_long *)((a)->s6_addr) + 1) & 0xc0) == 0x80))
  202. #endif
  203. #ifndef IN6_IS_ADDR_SITELOCAL
  204. #define IN6_IS_ADDR_SITELOCAL(a) (\
  205. (*((u_long *)((a)->s6_addr) ) == 0xfe) && \
  206. ((*((u_long *)((a)->s6_addr) + 1) & 0xc0) == 0xc0))
  207. #endif
  208. struct addrinfo {
  209. int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
  210. int ai_family; /* PF_xxx */
  211. int ai_socktype; /* SOCK_xxx */
  212. int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
  213. size_t ai_addrlen; /* length of ai_addr */
  214. char *ai_canonname; /* canonical name for hostname */
  215. struct sockaddr *ai_addr; /* binary address */
  216. struct addrinfo *ai_next; /* next structure in linked list */
  217. };
  218. /*
  219. * Error return codes from getaddrinfo()
  220. */
  221. #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */
  222. #define EAI_AGAIN 2 /* temporary failure in name resolution */
  223. #define EAI_BADFLAGS 3 /* invalid value for ai_flags */
  224. #define EAI_FAIL 4 /* non-recoverable failure in name resolution */
  225. #define EAI_FAMILY 5 /* ai_family not supported */
  226. #define EAI_MEMORY 6 /* memory allocation failure */
  227. #define EAI_NODATA 7 /* no address associated with hostname */
  228. #define EAI_NONAME 8 /* hostname nor servname provided, or not known */
  229. #define EAI_SERVICE 9 /* servname not supported for ai_socktype */
  230. #define EAI_SOCKTYPE 10 /* ai_socktype not supported */
  231. #define EAI_SYSTEM 11 /* system error returned in errno */
  232. #define EAI_BADHINTS 12
  233. #define EAI_PROTOCOL 13
  234. #define EAI_MAX 14
  235. int getaddrinfo P((const char *, const char *,
  236. const struct addrinfo *, struct addrinfo **));
  237. int getnameinfo P((const struct sockaddr *, u_int, char *,
  238. size_t, char *, size_t, int));
  239. void freeaddrinfo P((struct addrinfo *));
  240. char *gai_strerror P((int));
  241. /*
  242. * Constants for getnameinfo()
  243. */
  244. #ifndef NI_MAXHOST
  245. #define NI_MAXHOST 1025
  246. #define NI_MAXSERV 32
  247. #endif
  248. /*
  249. * Flag values for getnameinfo()
  250. */
  251. #ifndef NI_NUMERICHOST
  252. #define NI_NOFQDN 0x00000001
  253. #define NI_NUMERICHOST 0x00000002
  254. #define NI_NAMEREQD 0x00000004
  255. #define NI_NUMERICSERV 0x00000008
  256. #define NI_DGRAM 0x00000010
  257. #define NI_WITHSCOPEID 0x00000020
  258. #endif
  259. #endif /* ISC_PLATFORM_HAVEIPV6 */
  260. #endif /* !_NTP_RFC2553_H_ */