ntp_rfc2553.h revision 290000
1247841Sbapt/*
2263020Sbapt * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
3257353Sbdrewery * All rights reserved.
4247841Sbapt *
5247841Sbapt * Redistribution and use in source and binary forms, with or without
6247841Sbapt * modification, are permitted provided that the following conditions
7247841Sbapt * are met:
8247841Sbapt * 1. Redistributions of source code must retain the above copyright
9247841Sbapt *    notice, this list of conditions and the following disclaimer.
10247841Sbapt * 2. Redistributions in binary form must reproduce the above copyright
11247841Sbapt *    notice, this list of conditions and the following disclaimer in the
12247841Sbapt *    documentation and/or other materials provided with the distribution.
13247841Sbapt * 3. Neither the name of the project nor the names of its contributors
14247841Sbapt *    may be used to endorse or promote products derived from this software
15247841Sbapt *    without specific prior written permission.
16247841Sbapt *
17247841Sbapt * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18247841Sbapt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19247841Sbapt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20247841Sbapt * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21247841Sbapt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22247841Sbapt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23247841Sbapt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24247841Sbapt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25247841Sbapt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26247841Sbapt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27247841Sbapt * SUCH DAMAGE.
28247841Sbapt */
29247841Sbapt
30247841Sbapt/*
31247841Sbapt * Copyright (c) 1982, 1986, 1990, 1993
32261144Sbapt *	The Regents of the University of California.  All rights reserved.
33247841Sbapt *
34247841Sbapt * Redistribution and use in source and binary forms, with or without
35247841Sbapt * modification, are permitted provided that the following conditions
36259613Sbdrewery * are met:
37247841Sbapt * 1. Redistributions of source code must retain the above copyright
38255457Sbapt *    notice, this list of conditions and the following disclaimer.
39259613Sbdrewery * 2. Redistributions in binary form must reproduce the above copyright
40263020Sbapt *    notice, this list of conditions and the following disclaimer in the
41247841Sbapt *    documentation and/or other materials provided with the distribution.
42247841Sbapt * 3. All advertising materials mentioning features or use of this software
43247841Sbapt *    must display the following acknowledgement:
44247841Sbapt *	This product includes software developed by the University of
45247841Sbapt *	California, Berkeley and its contributors.
46247841Sbapt * 4. Neither the name of the University nor the names of its contributors
47247841Sbapt *    may be used to endorse or promote products derived from this software
48247841Sbapt *    without specific prior written permission.
49247841Sbapt *
50247841Sbapt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51247841Sbapt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52247841Sbapt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53247841Sbapt * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54247841Sbapt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55247841Sbapt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56247841Sbapt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57259613Sbdrewery * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58259613Sbdrewery * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59259613Sbdrewery * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60259613Sbdrewery * SUCH DAMAGE.
61259613Sbdrewery *
62247841Sbapt *	@(#)in.h	8.3 (Berkeley) 1/3/94
63247841Sbapt */
64247841Sbapt
65247841Sbapt/*
66247841Sbapt * Compatability shims with the rfc2553 API to simplify ntp.
67259613Sbdrewery */
68247841Sbapt#ifndef NTP_RFC2553_H
69263621Sbdrewery#define NTP_RFC2553_H
70247841Sbapt
71247841Sbapt#include <netdb.h>
72247841Sbapt#include <isc/net.h>
73247841Sbapt
74247841Sbapt#include "ntp_types.h"
75247841Sbapt#include "ntp_malloc.h"
76257328Sbdrewery
77247841Sbaptstruct addrinfo *copy_addrinfo_impl(const struct addrinfo *
78259613Sbdrewery#ifdef EREALLOC_CALLSITE	/* from ntp_malloc.h */
79247841Sbapt							   ,
80263621Sbdrewery				    const char *, int
81247841Sbapt#endif
82247841Sbapt					 );
83247841Sbaptstruct addrinfo *copy_addrinfo_list_impl(const struct addrinfo *
84247841Sbapt#ifdef EREALLOC_CALLSITE	/* from ntp_malloc.h */
85247841Sbapt								,
86247841Sbapt					 const char *, int
87259613Sbdrewery#endif
88247841Sbapt					 );
89263621Sbdrewery#ifdef EREALLOC_CALLSITE
90247841Sbapt# define copy_addrinfo(l) \
91247841Sbapt	 copy_addrinfo_impl((l), __FILE__, __LINE__)
92247841Sbapt# define copy_addrinfo_list(l) \
93247841Sbapt	 copy_addrinfo_list_impl((l), __FILE__, __LINE__)
94247841Sbapt#else
95247841Sbapt# define copy_addrinfo(l)	copy_addrinfo_impl(l)
96259613Sbdrewery# define copy_addrinfo_list(l)	copy_addrinfo_list_impl(l)
97247841Sbapt#endif
98263621Sbdrewery
99247841Sbapt/*
100247841Sbapt * If various macros are not defined we need to define them
101247841Sbapt */
102247841Sbapt
103247841Sbapt#ifndef AF_INET6
104247841Sbapt# define AF_INET6	AF_MAX
105259613Sbdrewery# define PF_INET6	AF_INET6
106247841Sbapt#endif
107263621Sbdrewery
108257353Sbdrewery#if !defined(_SS_MAXSIZE) && !defined(_SS_ALIGNSIZE)
109257353Sbdrewery
110257353Sbdrewery# define	_SS_MAXSIZE	128
111257353Sbdrewery# define	_SS_ALIGNSIZE	(sizeof(ntp_uint64_t))
112257353Sbdrewery# ifdef ISC_PLATFORM_HAVESALEN
113257353Sbdrewery#  define	_SS_PAD1SIZE	(_SS_ALIGNSIZE - sizeof(u_char) - sizeof(ntp_u_int8_t))
114259613Sbdrewery#  define	_SS_PAD2SIZE	(_SS_MAXSIZE - sizeof(u_char) - sizeof(ntp_u_int8_t) - \
115257353Sbdrewery				_SS_PAD1SIZE - _SS_ALIGNSIZE)
116263621Sbdrewery# else
117257353Sbdrewery#  define	_SS_PAD1SIZE	(_SS_ALIGNSIZE - sizeof(short))
118257353Sbdrewery#  define	_SS_PAD2SIZE	(_SS_MAXSIZE - sizeof(short) - \
119257353Sbdrewery				_SS_PAD1SIZE - _SS_ALIGNSIZE)
120257353Sbdrewery# endif /* ISC_PLATFORM_HAVESALEN */
121257353Sbdrewery#endif
122257353Sbdrewery
123259613Sbdrewery#ifndef INET6_ADDRSTRLEN
124257353Sbdrewery# define	INET6_ADDRSTRLEN	46	/* max len of IPv6 addr in ascii */
125263621Sbdrewery#endif
126257353Sbdrewery
127259613Sbdrewery/*
128259613Sbdrewery * If we don't have the sockaddr_storage structure
129259613Sbdrewery * we need to define it
130259613Sbdrewery */
131259613Sbdrewery
132259613Sbdrewery#ifndef HAVE_STRUCT_SOCKADDR_STORAGE
133259613Sbdrewerystruct sockaddr_storage {
134263621Sbdrewery#ifdef ISC_PLATFORM_HAVESALEN
135259613Sbdrewery	ntp_u_int8_t	ss_len;		/* address length */
136287873Sdelphij	ntp_u_int8_t	ss_family;	/* address family */
137287873Sdelphij#else
138287873Sdelphij	short		ss_family;	/* address family */
139287873Sdelphij#endif
140287873Sdelphij	char		__ss_pad1[_SS_PAD1SIZE];
141287873Sdelphij	ntp_uint64_t	__ss_align;	/* force desired structure storage alignment */
142287873Sdelphij	char		__ss_pad2[_SS_PAD2SIZE];
143287873Sdelphij};
144287873Sdelphij#endif
145247841Sbapt
146247841Sbapt/*
147247841Sbapt * Finally if the platform doesn't support IPv6 we need some
148247841Sbapt * additional definitions
149247841Sbapt */
150247841Sbapt
151247841Sbapt/*
152247841Sbapt * Flag values for getaddrinfo()
153247841Sbapt */
154247841Sbapt#ifndef AI_PASSIVE
155247841Sbapt#define	AI_PASSIVE	0x00000001 /* get address to use bind() */
156247841Sbapt#define	AI_CANONNAME	0x00000002 /* fill ai_canonname */
157247841Sbapt#define	AI_NUMERICHOST	0x00000004 /* prevent name resolution */
158247841Sbapt/* valid flags for addrinfo */
159255457Sbapt#define AI_MASK \
160255457Sbapt    (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_ADDRCONFIG)
161255457Sbapt
162255457Sbapt#define	AI_ADDRCONFIG	0x00000400 /* only if any address is assigned */
163255457Sbapt#endif	/* !AI_PASSIVE */
164255457Sbapt
165255457Sbapt#ifndef AI_NUMERICHOST		/* such as AIX 4.3 */
166255457Sbapt# define Z_AI_NUMERICHOST	0
167255457Sbapt#else
168255457Sbapt# define Z_AI_NUMERICHOST	AI_NUMERICHOST
169255457Sbapt#endif
170255457Sbapt
171255457Sbapt#ifndef AI_NUMERICSERV		/* not in RFC 2553 */
172255457Sbapt# define Z_AI_NUMERICSERV	0
173255457Sbapt#else
174255457Sbapt# define Z_AI_NUMERICSERV	AI_NUMERICSERV
175255457Sbapt#endif
176255457Sbapt
177255457Sbapt#ifndef ISC_PLATFORM_HAVEIPV6
178255457Sbapt
179255457Sbapt#ifdef SYS_WINNT
180255457Sbapt# define in6_addr in_addr6
181255457Sbapt#endif
182255457Sbapt
183255457Sbaptstruct addrinfo {
184255457Sbapt	int	ai_flags;	/* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
185255457Sbapt	int	ai_family;	/* PF_xxx */
186255457Sbapt	int	ai_socktype;	/* SOCK_xxx */
187255457Sbapt	int	ai_protocol;	/* 0 or IPPROTO_xxx for IPv4 and IPv6 */
188255457Sbapt	size_t	ai_addrlen;	/* length of ai_addr */
189255457Sbapt	char	*ai_canonname;	/* canonical name for hostname */
190255457Sbapt	struct	sockaddr *ai_addr;	/* binary address */
191255457Sbapt	struct	addrinfo *ai_next;	/* next structure in linked list */
192255457Sbapt};
193255457Sbapt
194255457Sbapt/*
195255457Sbapt * Error return codes from getaddrinfo()
196255457Sbapt */
197255457Sbapt#define	EAI_ADDRFAMILY	 1	/* address family for hostname not supported */
198255457Sbapt#define	EAI_AGAIN	 2	/* temporary failure in name resolution */
199255457Sbapt#define	EAI_BADFLAGS	 3	/* invalid value for ai_flags */
200255457Sbapt#define	EAI_FAIL	 4	/* non-recoverable failure in name resolution */
201255457Sbapt#define	EAI_FAMILY	 5	/* ai_family not supported */
202255457Sbapt#define	EAI_MEMORY	 6	/* memory allocation failure */
203255457Sbapt#define	EAI_NODATA	 7	/* no address associated with hostname */
204255457Sbapt#define	EAI_NONAME	 8	/* hostname nor servname provided, or not known */
205255457Sbapt#define	EAI_SERVICE	 9	/* servname not supported for ai_socktype */
206255457Sbapt#define	EAI_SOCKTYPE	10	/* ai_socktype not supported */
207255457Sbapt#define	EAI_SYSTEM	11	/* system error returned in errno */
208255457Sbapt#define	EAI_BADHINTS	12
209255457Sbapt#define	EAI_PROTOCOL	13
210255457Sbapt#define	EAI_MAX		14
211255457Sbapt
212255457Sbapt
213255457Sbaptint	getaddrinfo (const char *, const char *,
214255457Sbapt			 const struct addrinfo *, struct addrinfo **);
215255457Sbaptint	getnameinfo (const struct sockaddr *, u_int, char *,
216255457Sbapt			 size_t, char *, size_t, int);
217255457Sbaptvoid	freeaddrinfo (struct addrinfo *);
218255457Sbaptchar	*gai_strerror (int);
219255457Sbapt
220255457Sbapt/*
221255457Sbapt * Constants for getnameinfo()
222255457Sbapt */
223255457Sbapt#ifndef NI_MAXHOST
224255457Sbapt#define	NI_MAXHOST	1025
225255457Sbapt#define	NI_MAXSERV	32
226255457Sbapt#endif
227255457Sbapt
228255457Sbapt/*
229255457Sbapt * Flag values for getnameinfo()
230255457Sbapt */
231255457Sbapt#ifndef NI_NUMERICHOST
232255457Sbapt#define	NI_NOFQDN	0x00000001
233255457Sbapt#define	NI_NUMERICHOST	0x00000002
234255457Sbapt#define	NI_NAMEREQD	0x00000004
235255457Sbapt#define	NI_NUMERICSERV	0x00000008
236255457Sbapt#define	NI_DGRAM	0x00000010
237255457Sbapt#define NI_WITHSCOPEID	0x00000020
238255457Sbapt#endif
239255457Sbapt
240255457Sbapt#endif /* !ISC_PLATFORM_HAVEIPV6 */
241255457Sbapt
242255457Sbapt/*
243255457Sbapt * Set up some macros to look for IPv6 and IPv6 multicast
244255457Sbapt */
245255457Sbapt
246255457Sbapt#if defined(ISC_PLATFORM_HAVEIPV6) && defined(WANT_IPV6)
247255457Sbapt# define INCLUDE_IPV6_SUPPORT
248255457Sbapt# if defined(IPV6_JOIN_GROUP) && defined(IPV6_LEAVE_GROUP)
249255457Sbapt#  define INCLUDE_IPV6_MULTICAST_SUPPORT
250255457Sbapt# endif	/* IPV6 Multicast Support */
251255457Sbapt#endif  /* IPv6 Support */
252255457Sbapt
253255457Sbapt#endif /* !NTP_RFC2553_H */
254255457Sbapt