1 /* $NetBSD: ntp_rfc2553.h,v 1.2 2003/12/04 16:23:36 drochner Exp $ */
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * Copyright (c) 1982, 1986, 1990, 1993
34 * The Regents of the University of California. All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. All advertising materials mentioning features or use of this software
45 * must display the following acknowledgement:
46 * This product includes software developed by the University of
47 * California, Berkeley and its contributors.
48 * 4. Neither the name of the University nor the names of its contributors
49 * may be used to endorse or promote products derived from this software
50 * without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * @(#)in.h 8.3 (Berkeley) 1/3/94
68 * Compatability shims with the rfc2553 API to simplify ntp.
70 #ifndef _NTP_RFC2553_H_
71 #define _NTP_RFC2553_H_
74 * Ensure that we include the configuration file before we check
81 #include "ntp_types.h"
84 * Don't include any additional IPv6 definitions
85 * We are defining our own here.
90 * If various macros are not defined we need to define them
94 #define AF_INET6 AF_MAX
95 #define PF_INET6 AF_INET6
98 #if !defined(_SS_MAXSIZE) && !defined(_SS_ALIGNSIZE)
100 #define _SS_MAXSIZE 128
101 #define _SS_ALIGNSIZE (sizeof(ntp_uint64_t))
102 #ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR
103 #define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(u_char) - sizeof(ntp_u_int8_t))
104 #define _SS_PAD2SIZE (_SS_MAXSIZE - sizeof(u_char) - sizeof(ntp_u_int8_t) - \
105 _SS_PAD1SIZE - _SS_ALIGNSIZE)
107 #define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(short))
108 #define _SS_PAD2SIZE (_SS_MAXSIZE - sizeof(short) - \
109 _SS_PAD1SIZE - _SS_ALIGNSIZE)
110 #endif /* HAVE_SA_LEN_IN_STRUCT_SOCKADDR */
114 * If we don't have the sockaddr_storage structure
115 * we need to define it
118 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
119 struct sockaddr_storage
{
120 #ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR
121 ntp_u_int8_t ss_len
; /* address length */
122 ntp_u_int8_t ss_family
; /* address family */
124 short ss_family
; /* address family */
126 char __ss_pad1
[_SS_PAD1SIZE
];
127 ntp_uint64_t __ss_align
; /* force desired structure storage alignment */
128 char __ss_pad2
[_SS_PAD2SIZE
];
133 * Finally if the platform doesn't support IPv6 we need some
134 * additional definitions
138 * Flag values for getaddrinfo()
140 #ifndef AI_NUMERICHOST
141 #define AI_PASSIVE 0x00000001 /* get address to use bind() */
142 #define AI_CANONNAME 0x00000002 /* fill ai_canonname */
143 #define AI_NUMERICHOST 0x00000004 /* prevent name resolution */
144 /* valid flags for addrinfo */
146 (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_ADDRCONFIG)
148 #define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */
151 #ifndef ISC_PLATFORM_HAVEIPV6
153 * Definition of some useful macros to handle IP6 addresses
155 #ifdef ISC_PLATFORM_NEEDIN6ADDRANY
157 #define IN6ADDR_ANY_INIT {{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }}
159 #define IN6ADDR_ANY_INIT \
160 {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
161 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
170 #define in6_addr in_addr6
175 ntp_u_int8_t __u6_addr8
[16];
176 ntp_u_int16_t __u6_addr16
[8];
177 ntp_u_int32_t __u6_addr32
[4];
178 } __u6_addr
; /* 128-bit IP6 address */
181 #define s6_addr __u6_addr.__u6_addr8
184 #if defined(ISC_PLATFORM_HAVEIPV6) && defined(ISC_PLATFORM_NEEDIN6ADDRANY)
185 extern const struct in6_addr in6addr_any
;
189 #ifndef HAVE_SOCKADDR_IN6
190 struct sockaddr_in6
{
191 #ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR
192 ntp_u_int8_t sin6_len
; /* length of this struct(sa_family_t)*/
193 ntp_u_int8_t sin6_family
; /* AF_INET6 (sa_family_t) */
195 short sin6_family
; /* AF_INET6 (sa_family_t) */
197 ntp_u_int16_t sin6_port
; /* Transport layer port # (in_port_t)*/
198 ntp_u_int32_t sin6_flowinfo
; /* IP6 flow information */
199 struct in6_addr sin6_addr
; /* IP6 address */
200 ntp_u_int32_t sin6_scope_id
; /* scope zone index */
207 #ifndef IN6_IS_ADDR_UNSPECIFIED
208 #define IN6_IS_ADDR_UNSPECIFIED(a) \
209 ((*(const ntp_u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \
210 (*(const ntp_u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \
211 (*(const ntp_u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \
212 (*(const ntp_u_int32_t *)(const void *)(&(a)->s6_addr[12]) == 0))
217 #ifndef IN6_IS_ADDR_MULTICAST
218 #define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff)
221 * Unicast link / site local.
223 #ifndef IN6_IS_ADDR_LINKLOCAL
224 #define IN6_IS_ADDR_LINKLOCAL(a) (\
225 (*((u_long *)((a)->s6_addr) ) == 0xfe) && \
226 ((*((u_long *)((a)->s6_addr) + 1) & 0xc0) == 0x80))
229 #ifndef IN6_IS_ADDR_SITELOCAL
230 #define IN6_IS_ADDR_SITELOCAL(a) (\
231 (*((u_long *)((a)->s6_addr) ) == 0xfe) && \
232 ((*((u_long *)((a)->s6_addr) + 1) & 0xc0) == 0xc0))
236 int ai_flags
; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
237 int ai_family
; /* PF_xxx */
238 int ai_socktype
; /* SOCK_xxx */
239 int ai_protocol
; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
240 size_t ai_addrlen
; /* length of ai_addr */
241 char *ai_canonname
; /* canonical name for hostname */
242 struct sockaddr
*ai_addr
; /* binary address */
243 struct addrinfo
*ai_next
; /* next structure in linked list */
247 * Error return codes from getaddrinfo()
249 #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */
250 #define EAI_AGAIN 2 /* temporary failure in name resolution */
251 #define EAI_BADFLAGS 3 /* invalid value for ai_flags */
252 #define EAI_FAIL 4 /* non-recoverable failure in name resolution */
253 #define EAI_FAMILY 5 /* ai_family not supported */
254 #define EAI_MEMORY 6 /* memory allocation failure */
255 #define EAI_NODATA 7 /* no address associated with hostname */
256 #define EAI_NONAME 8 /* hostname nor servname provided, or not known */
257 #define EAI_SERVICE 9 /* servname not supported for ai_socktype */
258 #define EAI_SOCKTYPE 10 /* ai_socktype not supported */
259 #define EAI_SYSTEM 11 /* system error returned in errno */
260 #define EAI_BADHINTS 12
261 #define EAI_PROTOCOL 13
265 int getaddrinfo
P((const char *, const char *,
266 const struct addrinfo
*, struct addrinfo
**));
267 int getnameinfo
P((const struct sockaddr
*, u_int
, char *,
268 size_t, char *, size_t, int));
269 void freeaddrinfo
P((struct addrinfo
*));
270 char *gai_strerror
P((int));
273 * Constants for getnameinfo()
276 #define NI_MAXHOST 1025
277 #define NI_MAXSERV 32
281 * Flag values for getnameinfo()
283 #ifndef NI_NUMERICHOST
284 #define NI_NOFQDN 0x00000001
285 #define NI_NUMERICHOST 0x00000002
286 #define NI_NAMEREQD 0x00000004
287 #define NI_NUMERICSERV 0x00000008
288 #define NI_DGRAM 0x00000010
289 #define NI_WITHSCOPEID 0x00000020
292 #endif /* ISC_PLATFORM_HAVEIPV6 */
294 #endif /* !_NTP_RFC2553_H_ */