ntp_rfc2553.h revision 1.1.1.2 1 1.1 kardel /* $NetBSD: ntp_rfc2553.h,v 1.1.1.2 2012/01/31 21:23:24 kardel Exp $ */
2 1.1 kardel
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 /*
74 1.1 kardel * Ensure that we include the configuration file before we check
75 1.1 kardel * for IPV6
76 1.1 kardel */
77 1.1 kardel #include <config.h>
78 1.1 kardel #include <netdb.h>
79 1.1 kardel #include <isc/net.h>
80 1.1 kardel
81 1.1 kardel #include "ntp_types.h"
82 1.1 kardel
83 1.1 kardel
84 1.1.1.2 kardel /*
85 1.1 kardel * If various macros are not defined we need to define them
86 1.1 kardel */
87 1.1 kardel
88 1.1 kardel #ifndef AF_INET6
89 1.1 kardel # define AF_INET6 AF_MAX
90 1.1 kardel # define PF_INET6 AF_INET6
91 1.1 kardel #endif
92 1.1 kardel
93 1.1 kardel #if !defined(_SS_MAXSIZE) && !defined(_SS_ALIGNSIZE)
94 1.1 kardel
95 1.1 kardel # define _SS_MAXSIZE 128
96 1.1 kardel # define _SS_ALIGNSIZE (sizeof(ntp_uint64_t))
97 1.1 kardel # ifdef ISC_PLATFORM_HAVESALEN
98 1.1 kardel # define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(u_char) - sizeof(ntp_u_int8_t))
99 1.1 kardel # define _SS_PAD2SIZE (_SS_MAXSIZE - sizeof(u_char) - sizeof(ntp_u_int8_t) - \
100 1.1 kardel _SS_PAD1SIZE - _SS_ALIGNSIZE)
101 1.1 kardel # else
102 1.1 kardel # define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(short))
103 1.1 kardel # define _SS_PAD2SIZE (_SS_MAXSIZE - sizeof(short) - \
104 1.1 kardel _SS_PAD1SIZE - _SS_ALIGNSIZE)
105 1.1 kardel # endif /* ISC_PLATFORM_HAVESALEN */
106 1.1 kardel #endif
107 1.1 kardel
108 1.1 kardel #ifndef INET6_ADDRSTRLEN
109 1.1 kardel # define INET6_ADDRSTRLEN 46 /* max len of IPv6 addr in ascii */
110 1.1 kardel #endif
111 1.1 kardel
112 1.1 kardel /*
113 1.1 kardel * If we don't have the sockaddr_storage structure
114 1.1 kardel * we need to define it
115 1.1 kardel */
116 1.1 kardel
117 1.1 kardel #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
118 1.1 kardel struct sockaddr_storage {
119 1.1 kardel #ifdef ISC_PLATFORM_HAVESALEN
120 1.1 kardel ntp_u_int8_t ss_len; /* address length */
121 1.1 kardel ntp_u_int8_t ss_family; /* address family */
122 1.1 kardel #else
123 1.1 kardel short ss_family; /* address family */
124 1.1 kardel #endif
125 1.1 kardel char __ss_pad1[_SS_PAD1SIZE];
126 1.1 kardel ntp_uint64_t __ss_align; /* force desired structure storage alignment */
127 1.1 kardel char __ss_pad2[_SS_PAD2SIZE];
128 1.1 kardel };
129 1.1 kardel #endif
130 1.1 kardel
131 1.1 kardel /*
132 1.1 kardel * Finally if the platform doesn't support IPv6 we need some
133 1.1 kardel * additional definitions
134 1.1 kardel */
135 1.1 kardel
136 1.1 kardel /*
137 1.1 kardel * Flag values for getaddrinfo()
138 1.1 kardel */
139 1.1 kardel #ifndef AI_PASSIVE
140 1.1 kardel #define AI_PASSIVE 0x00000001 /* get address to use bind() */
141 1.1 kardel #define AI_CANONNAME 0x00000002 /* fill ai_canonname */
142 1.1 kardel #define AI_NUMERICHOST 0x00000004 /* prevent name resolution */
143 1.1 kardel /* valid flags for addrinfo */
144 1.1 kardel #define AI_MASK \
145 1.1 kardel (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_ADDRCONFIG)
146 1.1 kardel
147 1.1 kardel #define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */
148 1.1 kardel #endif /* !AI_PASSIVE */
149 1.1 kardel
150 1.1 kardel #ifndef AI_NUMERICHOST /* such as AIX 4.3 */
151 1.1.1.2 kardel # define Z_AI_NUMERICHOST 0
152 1.1.1.2 kardel #else
153 1.1.1.2 kardel # define Z_AI_NUMERICHOST AI_NUMERICHOST
154 1.1.1.2 kardel #endif
155 1.1.1.2 kardel
156 1.1.1.2 kardel #ifndef AI_NUMERICSERV /* not in RFC 2553 */
157 1.1.1.2 kardel # define Z_AI_NUMERICSERV 0
158 1.1.1.2 kardel #else
159 1.1.1.2 kardel # define Z_AI_NUMERICSERV AI_NUMERICSERV
160 1.1 kardel #endif
161 1.1 kardel
162 1.1 kardel #ifndef ISC_PLATFORM_HAVEIPV6
163 1.1 kardel
164 1.1 kardel #ifdef SYS_WINNT
165 1.1 kardel # define in6_addr in_addr6
166 1.1 kardel #endif
167 1.1 kardel
168 1.1 kardel struct addrinfo {
169 1.1 kardel int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
170 1.1 kardel int ai_family; /* PF_xxx */
171 1.1 kardel int ai_socktype; /* SOCK_xxx */
172 1.1 kardel int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
173 1.1 kardel size_t ai_addrlen; /* length of ai_addr */
174 1.1 kardel char *ai_canonname; /* canonical name for hostname */
175 1.1 kardel struct sockaddr *ai_addr; /* binary address */
176 1.1 kardel struct addrinfo *ai_next; /* next structure in linked list */
177 1.1 kardel };
178 1.1 kardel
179 1.1 kardel /*
180 1.1 kardel * Error return codes from getaddrinfo()
181 1.1 kardel */
182 1.1 kardel #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */
183 1.1 kardel #define EAI_AGAIN 2 /* temporary failure in name resolution */
184 1.1 kardel #define EAI_BADFLAGS 3 /* invalid value for ai_flags */
185 1.1 kardel #define EAI_FAIL 4 /* non-recoverable failure in name resolution */
186 1.1 kardel #define EAI_FAMILY 5 /* ai_family not supported */
187 1.1 kardel #define EAI_MEMORY 6 /* memory allocation failure */
188 1.1 kardel #define EAI_NODATA 7 /* no address associated with hostname */
189 1.1 kardel #define EAI_NONAME 8 /* hostname nor servname provided, or not known */
190 1.1 kardel #define EAI_SERVICE 9 /* servname not supported for ai_socktype */
191 1.1 kardel #define EAI_SOCKTYPE 10 /* ai_socktype not supported */
192 1.1 kardel #define EAI_SYSTEM 11 /* system error returned in errno */
193 1.1 kardel #define EAI_BADHINTS 12
194 1.1 kardel #define EAI_PROTOCOL 13
195 1.1 kardel #define EAI_MAX 14
196 1.1 kardel
197 1.1 kardel
198 1.1 kardel int getaddrinfo (const char *, const char *,
199 1.1 kardel const struct addrinfo *, struct addrinfo **);
200 1.1 kardel int getnameinfo (const struct sockaddr *, u_int, char *,
201 1.1 kardel size_t, char *, size_t, int);
202 1.1 kardel void freeaddrinfo (struct addrinfo *);
203 1.1 kardel char *gai_strerror (int);
204 1.1 kardel
205 1.1 kardel /*
206 1.1 kardel * Constants for getnameinfo()
207 1.1 kardel */
208 1.1 kardel #ifndef NI_MAXHOST
209 1.1 kardel #define NI_MAXHOST 1025
210 1.1 kardel #define NI_MAXSERV 32
211 1.1 kardel #endif
212 1.1 kardel
213 1.1 kardel /*
214 1.1 kardel * Flag values for getnameinfo()
215 1.1 kardel */
216 1.1 kardel #ifndef NI_NUMERICHOST
217 1.1 kardel #define NI_NOFQDN 0x00000001
218 1.1 kardel #define NI_NUMERICHOST 0x00000002
219 1.1 kardel #define NI_NAMEREQD 0x00000004
220 1.1 kardel #define NI_NUMERICSERV 0x00000008
221 1.1 kardel #define NI_DGRAM 0x00000010
222 1.1 kardel #define NI_WITHSCOPEID 0x00000020
223 1.1 kardel #endif
224 1.1 kardel
225 1.1 kardel #endif /* !ISC_PLATFORM_HAVEIPV6 */
226 1.1 kardel
227 1.1 kardel /*
228 1.1 kardel * Set up some macros to look for IPv6 and IPv6 multicast
229 1.1 kardel */
230 1.1 kardel
231 1.1 kardel #if defined(ISC_PLATFORM_HAVEIPV6) && defined(WANT_IPV6)
232 1.1 kardel # define INCLUDE_IPV6_SUPPORT
233 1.1 kardel # if defined(IPV6_JOIN_GROUP) && defined(IPV6_LEAVE_GROUP)
234 1.1 kardel # define INCLUDE_IPV6_MULTICAST_SUPPORT
235 1.1 kardel # endif /* IPV6 Multicast Support */
236 1.1 kardel #endif /* IPv6 Support */
237 1.1 kardel
238 1.1 kardel #endif /* !NTP_RFC2553_H */
239