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