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