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