1132451Sroberto/*
2132451Sroberto * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
3132451Sroberto * All rights reserved.
4132451Sroberto *
5132451Sroberto * Redistribution and use in source and binary forms, with or without
6132451Sroberto * modification, are permitted provided that the following conditions
7132451Sroberto * are met:
8132451Sroberto * 1. Redistributions of source code must retain the above copyright
9132451Sroberto *    notice, this list of conditions and the following disclaimer.
10132451Sroberto * 2. Redistributions in binary form must reproduce the above copyright
11132451Sroberto *    notice, this list of conditions and the following disclaimer in the
12132451Sroberto *    documentation and/or other materials provided with the distribution.
13132451Sroberto * 3. Neither the name of the project nor the names of its contributors
14132451Sroberto *    may be used to endorse or promote products derived from this software
15132451Sroberto *    without specific prior written permission.
16132451Sroberto *
17132451Sroberto * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18132451Sroberto * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19132451Sroberto * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20132451Sroberto * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21132451Sroberto * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22132451Sroberto * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23132451Sroberto * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24132451Sroberto * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25132451Sroberto * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26132451Sroberto * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27132451Sroberto * SUCH DAMAGE.
28132451Sroberto */
29132451Sroberto
30132451Sroberto/*
31132451Sroberto * Copyright (c) 1982, 1986, 1990, 1993
32132451Sroberto *	The Regents of the University of California.  All rights reserved.
33132451Sroberto *
34132451Sroberto * Redistribution and use in source and binary forms, with or without
35132451Sroberto * modification, are permitted provided that the following conditions
36132451Sroberto * are met:
37132451Sroberto * 1. Redistributions of source code must retain the above copyright
38132451Sroberto *    notice, this list of conditions and the following disclaimer.
39132451Sroberto * 2. Redistributions in binary form must reproduce the above copyright
40132451Sroberto *    notice, this list of conditions and the following disclaimer in the
41132451Sroberto *    documentation and/or other materials provided with the distribution.
42132451Sroberto * 3. All advertising materials mentioning features or use of this software
43132451Sroberto *    must display the following acknowledgement:
44132451Sroberto *	This product includes software developed by the University of
45132451Sroberto *	California, Berkeley and its contributors.
46132451Sroberto * 4. Neither the name of the University nor the names of its contributors
47132451Sroberto *    may be used to endorse or promote products derived from this software
48132451Sroberto *    without specific prior written permission.
49132451Sroberto *
50132451Sroberto * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51132451Sroberto * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52132451Sroberto * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53132451Sroberto * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54132451Sroberto * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55132451Sroberto * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56132451Sroberto * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57132451Sroberto * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58132451Sroberto * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59132451Sroberto * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60132451Sroberto * SUCH DAMAGE.
61132451Sroberto *
62132451Sroberto *	@(#)in.h	8.3 (Berkeley) 1/3/94
63132451Sroberto */
64132451Sroberto
65132451Sroberto/*
66132451Sroberto * Compatability shims with the rfc2553 API to simplify ntp.
67132451Sroberto */
68285612Sdelphij#ifndef NTP_RFC2553_H
69285612Sdelphij#define NTP_RFC2553_H
70132451Sroberto
71182007Sroberto#include <netdb.h>
72285612Sdelphij#include <isc/net.h>
73182007Sroberto
74132451Sroberto#include "ntp_types.h"
75285612Sdelphij#include "ntp_malloc.h"
76132451Sroberto
77285612Sdelphijstruct addrinfo *copy_addrinfo_impl(const struct addrinfo *
78285612Sdelphij#ifdef EREALLOC_CALLSITE	/* from ntp_malloc.h */
79285612Sdelphij							   ,
80285612Sdelphij				    const char *, int
81285612Sdelphij#endif
82285612Sdelphij					 );
83285612Sdelphijstruct addrinfo *copy_addrinfo_list_impl(const struct addrinfo *
84285612Sdelphij#ifdef EREALLOC_CALLSITE	/* from ntp_malloc.h */
85285612Sdelphij								,
86285612Sdelphij					 const char *, int
87285612Sdelphij#endif
88285612Sdelphij					 );
89285612Sdelphij#ifdef EREALLOC_CALLSITE
90285612Sdelphij# define copy_addrinfo(l) \
91285612Sdelphij	 copy_addrinfo_impl((l), __FILE__, __LINE__)
92285612Sdelphij# define copy_addrinfo_list(l) \
93285612Sdelphij	 copy_addrinfo_list_impl((l), __FILE__, __LINE__)
94285612Sdelphij#else
95285612Sdelphij# define copy_addrinfo(l)	copy_addrinfo_impl(l)
96285612Sdelphij# define copy_addrinfo_list(l)	copy_addrinfo_list_impl(l)
97285612Sdelphij#endif
98285612Sdelphij
99182007Sroberto/*
100182007Sroberto * If various macros are not defined we need to define them
101182007Sroberto */
102182007Sroberto
103132451Sroberto#ifndef AF_INET6
104285612Sdelphij# define AF_INET6	AF_MAX
105285612Sdelphij# define PF_INET6	AF_INET6
106132451Sroberto#endif
107132451Sroberto
108182007Sroberto#if !defined(_SS_MAXSIZE) && !defined(_SS_ALIGNSIZE)
109132451Sroberto
110285612Sdelphij# define	_SS_MAXSIZE	128
111285612Sdelphij# define	_SS_ALIGNSIZE	(sizeof(ntp_uint64_t))
112285612Sdelphij# ifdef ISC_PLATFORM_HAVESALEN
113285612Sdelphij#  define	_SS_PAD1SIZE	(_SS_ALIGNSIZE - sizeof(u_char) - sizeof(ntp_u_int8_t))
114285612Sdelphij#  define	_SS_PAD2SIZE	(_SS_MAXSIZE - sizeof(u_char) - sizeof(ntp_u_int8_t) - \
115182007Sroberto				_SS_PAD1SIZE - _SS_ALIGNSIZE)
116285612Sdelphij# else
117285612Sdelphij#  define	_SS_PAD1SIZE	(_SS_ALIGNSIZE - sizeof(short))
118285612Sdelphij#  define	_SS_PAD2SIZE	(_SS_MAXSIZE - sizeof(short) - \
119182007Sroberto				_SS_PAD1SIZE - _SS_ALIGNSIZE)
120285612Sdelphij# endif /* ISC_PLATFORM_HAVESALEN */
121182007Sroberto#endif
122132451Sroberto
123285612Sdelphij#ifndef INET6_ADDRSTRLEN
124285612Sdelphij# define	INET6_ADDRSTRLEN	46	/* max len of IPv6 addr in ascii */
125285612Sdelphij#endif
126285612Sdelphij
127132451Sroberto/*
128182007Sroberto * If we don't have the sockaddr_storage structure
129182007Sroberto * we need to define it
130132451Sroberto */
131182007Sroberto
132182007Sroberto#ifndef HAVE_STRUCT_SOCKADDR_STORAGE
133182007Srobertostruct sockaddr_storage {
134285612Sdelphij#ifdef ISC_PLATFORM_HAVESALEN
135182007Sroberto	ntp_u_int8_t	ss_len;		/* address length */
136182007Sroberto	ntp_u_int8_t	ss_family;	/* address family */
137132451Sroberto#else
138182007Sroberto	short		ss_family;	/* address family */
139182007Sroberto#endif
140182007Sroberto	char		__ss_pad1[_SS_PAD1SIZE];
141182007Sroberto	ntp_uint64_t	__ss_align;	/* force desired structure storage alignment */
142182007Sroberto	char		__ss_pad2[_SS_PAD2SIZE];
143182007Sroberto};
144182007Sroberto#endif
145182007Sroberto
146132451Sroberto/*
147182007Sroberto * Finally if the platform doesn't support IPv6 we need some
148182007Sroberto * additional definitions
149132451Sroberto */
150132451Sroberto
151182007Sroberto/*
152182007Sroberto * Flag values for getaddrinfo()
153182007Sroberto */
154285612Sdelphij#ifndef AI_PASSIVE
155182007Sroberto#define	AI_PASSIVE	0x00000001 /* get address to use bind() */
156182007Sroberto#define	AI_CANONNAME	0x00000002 /* fill ai_canonname */
157182007Sroberto#define	AI_NUMERICHOST	0x00000004 /* prevent name resolution */
158182007Sroberto/* valid flags for addrinfo */
159182007Sroberto#define AI_MASK \
160182007Sroberto    (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_ADDRCONFIG)
161132451Sroberto
162182007Sroberto#define	AI_ADDRCONFIG	0x00000400 /* only if any address is assigned */
163285612Sdelphij#endif	/* !AI_PASSIVE */
164132451Sroberto
165285612Sdelphij#ifndef AI_NUMERICHOST		/* such as AIX 4.3 */
166285612Sdelphij# define Z_AI_NUMERICHOST	0
167132451Sroberto#else
168285612Sdelphij# define Z_AI_NUMERICHOST	AI_NUMERICHOST
169132451Sroberto#endif
170132451Sroberto
171285612Sdelphij#ifndef AI_NUMERICSERV		/* not in RFC 2553 */
172285612Sdelphij# define Z_AI_NUMERICSERV	0
173182007Sroberto#else
174285612Sdelphij# define Z_AI_NUMERICSERV	AI_NUMERICSERV
175182007Sroberto#endif
176182007Sroberto
177285612Sdelphij#ifndef ISC_PLATFORM_HAVEIPV6
178132451Sroberto
179285612Sdelphij#ifdef SYS_WINNT
180285612Sdelphij# define in6_addr in_addr6
181132451Sroberto#endif
182132451Sroberto
183132451Srobertostruct addrinfo {
184132451Sroberto	int	ai_flags;	/* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
185132451Sroberto	int	ai_family;	/* PF_xxx */
186132451Sroberto	int	ai_socktype;	/* SOCK_xxx */
187132451Sroberto	int	ai_protocol;	/* 0 or IPPROTO_xxx for IPv4 and IPv6 */
188132451Sroberto	size_t	ai_addrlen;	/* length of ai_addr */
189132451Sroberto	char	*ai_canonname;	/* canonical name for hostname */
190132451Sroberto	struct	sockaddr *ai_addr;	/* binary address */
191132451Sroberto	struct	addrinfo *ai_next;	/* next structure in linked list */
192132451Sroberto};
193132451Sroberto
194132451Sroberto/*
195132451Sroberto * Error return codes from getaddrinfo()
196132451Sroberto */
197132451Sroberto#define	EAI_ADDRFAMILY	 1	/* address family for hostname not supported */
198132451Sroberto#define	EAI_AGAIN	 2	/* temporary failure in name resolution */
199132451Sroberto#define	EAI_BADFLAGS	 3	/* invalid value for ai_flags */
200132451Sroberto#define	EAI_FAIL	 4	/* non-recoverable failure in name resolution */
201132451Sroberto#define	EAI_FAMILY	 5	/* ai_family not supported */
202132451Sroberto#define	EAI_MEMORY	 6	/* memory allocation failure */
203132451Sroberto#define	EAI_NODATA	 7	/* no address associated with hostname */
204132451Sroberto#define	EAI_NONAME	 8	/* hostname nor servname provided, or not known */
205132451Sroberto#define	EAI_SERVICE	 9	/* servname not supported for ai_socktype */
206132451Sroberto#define	EAI_SOCKTYPE	10	/* ai_socktype not supported */
207132451Sroberto#define	EAI_SYSTEM	11	/* system error returned in errno */
208132451Sroberto#define	EAI_BADHINTS	12
209132451Sroberto#define	EAI_PROTOCOL	13
210132451Sroberto#define	EAI_MAX		14
211132451Sroberto
212132451Sroberto
213285612Sdelphijint	getaddrinfo (const char *, const char *,
214285612Sdelphij			 const struct addrinfo *, struct addrinfo **);
215285612Sdelphijint	getnameinfo (const struct sockaddr *, u_int, char *,
216285612Sdelphij			 size_t, char *, size_t, int);
217285612Sdelphijvoid	freeaddrinfo (struct addrinfo *);
218285612Sdelphijchar	*gai_strerror (int);
219132451Sroberto
220132451Sroberto/*
221132451Sroberto * Constants for getnameinfo()
222132451Sroberto */
223182007Sroberto#ifndef NI_MAXHOST
224132451Sroberto#define	NI_MAXHOST	1025
225132451Sroberto#define	NI_MAXSERV	32
226182007Sroberto#endif
227132451Sroberto
228132451Sroberto/*
229132451Sroberto * Flag values for getnameinfo()
230132451Sroberto */
231182007Sroberto#ifndef NI_NUMERICHOST
232132451Sroberto#define	NI_NOFQDN	0x00000001
233132451Sroberto#define	NI_NUMERICHOST	0x00000002
234132451Sroberto#define	NI_NAMEREQD	0x00000004
235132451Sroberto#define	NI_NUMERICSERV	0x00000008
236132451Sroberto#define	NI_DGRAM	0x00000010
237132451Sroberto#define NI_WITHSCOPEID	0x00000020
238182007Sroberto#endif
239132451Sroberto
240285612Sdelphij#endif /* !ISC_PLATFORM_HAVEIPV6 */
241132451Sroberto
242285612Sdelphij/*
243285612Sdelphij * Set up some macros to look for IPv6 and IPv6 multicast
244285612Sdelphij */
245285612Sdelphij
246285612Sdelphij#if defined(ISC_PLATFORM_HAVEIPV6) && defined(WANT_IPV6)
247285612Sdelphij# define INCLUDE_IPV6_SUPPORT
248285612Sdelphij# if defined(IPV6_JOIN_GROUP) && defined(IPV6_LEAVE_GROUP)
249285612Sdelphij#  define INCLUDE_IPV6_MULTICAST_SUPPORT
250285612Sdelphij# endif	/* IPV6 Multicast Support */
251285612Sdelphij#endif  /* IPv6 Support */
252285612Sdelphij
253285612Sdelphij#endif /* !NTP_RFC2553_H */
254