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