1118e757roberto/*
2118e757roberto * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
3118e757roberto * All rights reserved.
4118e757roberto *
5118e757roberto * Redistribution and use in source and binary forms, with or without
6118e757roberto * modification, are permitted provided that the following conditions
7118e757roberto * are met:
8118e757roberto * 1. Redistributions of source code must retain the above copyright
9118e757roberto *    notice, this list of conditions and the following disclaimer.
10118e757roberto * 2. Redistributions in binary form must reproduce the above copyright
11118e757roberto *    notice, this list of conditions and the following disclaimer in the
12118e757roberto *    documentation and/or other materials provided with the distribution.
13118e757roberto * 3. Neither the name of the project nor the names of its contributors
14118e757roberto *    may be used to endorse or promote products derived from this software
15118e757roberto *    without specific prior written permission.
16118e757roberto *
17118e757roberto * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18118e757roberto * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19118e757roberto * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20118e757roberto * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21118e757roberto * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22118e757roberto * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23118e757roberto * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24118e757roberto * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25118e757roberto * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26118e757roberto * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27118e757roberto * SUCH DAMAGE.
28118e757roberto */
29118e757roberto
30118e757roberto/*
31118e757roberto * Copyright (c) 1982, 1986, 1990, 1993
32118e757roberto *	The Regents of the University of California.  All rights reserved.
33118e757roberto *
34118e757roberto * Redistribution and use in source and binary forms, with or without
35118e757roberto * modification, are permitted provided that the following conditions
36118e757roberto * are met:
37118e757roberto * 1. Redistributions of source code must retain the above copyright
38118e757roberto *    notice, this list of conditions and the following disclaimer.
39118e757roberto * 2. Redistributions in binary form must reproduce the above copyright
40118e757roberto *    notice, this list of conditions and the following disclaimer in the
41118e757roberto *    documentation and/or other materials provided with the distribution.
42118e757roberto * 3. All advertising materials mentioning features or use of this software
43118e757roberto *    must display the following acknowledgement:
44118e757roberto *	This product includes software developed by the University of
45118e757roberto *	California, Berkeley and its contributors.
46118e757roberto * 4. Neither the name of the University nor the names of its contributors
47118e757roberto *    may be used to endorse or promote products derived from this software
48118e757roberto *    without specific prior written permission.
49118e757roberto *
50118e757roberto * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51118e757roberto * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52118e757roberto * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53118e757roberto * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54118e757roberto * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55118e757roberto * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56118e757roberto * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57118e757roberto * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58118e757roberto * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59118e757roberto * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60118e757roberto * SUCH DAMAGE.
61118e757roberto *
62118e757roberto *	@(#)in.h	8.3 (Berkeley) 1/3/94
63118e757roberto */
64118e757roberto
65118e757roberto/*
66118e757roberto * Compatability shims with the rfc2553 API to simplify ntp.
67118e757roberto */
68d54cfbdroberto#ifndef NTP_RFC2553_H
69d54cfbdroberto#define NTP_RFC2553_H
70118e757roberto
717a6072eroberto#include <netdb.h>
72d54cfbdroberto#include <isc/net.h>
73118e757roberto
74118e757roberto#include "ntp_types.h"
75047f369cy#include "ntp_malloc.h"
76118e757roberto
77047f369cystruct addrinfo *copy_addrinfo_impl(const struct addrinfo *
78047f369cy#ifdef EREALLOC_CALLSITE	/* from ntp_malloc.h */
79047f369cy							   ,
80047f369cy				    const char *, int
81047f369cy#endif
82047f369cy					 );
83047f369cystruct addrinfo *copy_addrinfo_list_impl(const struct addrinfo *
84047f369cy#ifdef EREALLOC_CALLSITE	/* from ntp_malloc.h */
85047f369cy								,
86047f369cy					 const char *, int
87047f369cy#endif
88047f369cy					 );
89047f369cy#ifdef EREALLOC_CALLSITE
90047f369cy# define copy_addrinfo(l) \
91047f369cy	 copy_addrinfo_impl((l), __FILE__, __LINE__)
92047f369cy# define copy_addrinfo_list(l) \
93047f369cy	 copy_addrinfo_list_impl((l), __FILE__, __LINE__)
94047f369cy#else
95047f369cy# define copy_addrinfo(l)	copy_addrinfo_impl(l)
96047f369cy# define copy_addrinfo_list(l)	copy_addrinfo_list_impl(l)
97047f369cy#endif
987a6072eroberto
99d54cfbdroberto/*
1007a6072eroberto * If various macros are not defined we need to define them
1017a6072eroberto */
1027a6072eroberto
103118e757roberto#ifndef AF_INET6
104d54cfbdroberto# define AF_INET6	AF_MAX
105d54cfbdroberto# define PF_INET6	AF_INET6
106118e757roberto#endif
107118e757roberto
1087a6072eroberto#if !defined(_SS_MAXSIZE) && !defined(_SS_ALIGNSIZE)
109118e757roberto
110d54cfbdroberto# define	_SS_MAXSIZE	128
111d54cfbdroberto# define	_SS_ALIGNSIZE	(sizeof(ntp_uint64_t))
112d54cfbdroberto# ifdef ISC_PLATFORM_HAVESALEN
113d54cfbdroberto#  define	_SS_PAD1SIZE	(_SS_ALIGNSIZE - sizeof(u_char) - sizeof(ntp_u_int8_t))
114d54cfbdroberto#  define	_SS_PAD2SIZE	(_SS_MAXSIZE - sizeof(u_char) - sizeof(ntp_u_int8_t) - \
1157a6072eroberto				_SS_PAD1SIZE - _SS_ALIGNSIZE)
116d54cfbdroberto# else
117d54cfbdroberto#  define	_SS_PAD1SIZE	(_SS_ALIGNSIZE - sizeof(short))
118d54cfbdroberto#  define	_SS_PAD2SIZE	(_SS_MAXSIZE - sizeof(short) - \
1197a6072eroberto				_SS_PAD1SIZE - _SS_ALIGNSIZE)
120d54cfbdroberto# endif /* ISC_PLATFORM_HAVESALEN */
121d54cfbdroberto#endif
122d54cfbdroberto
123d54cfbdroberto#ifndef INET6_ADDRSTRLEN
124d54cfbdroberto# define	INET6_ADDRSTRLEN	46	/* max len of IPv6 addr in ascii */
1257a6072eroberto#endif
126118e757roberto
127118e757roberto/*
1287a6072eroberto * If we don't have the sockaddr_storage structure
1297a6072eroberto * we need to define it
130118e757roberto */
1317a6072eroberto
1327a6072eroberto#ifndef HAVE_STRUCT_SOCKADDR_STORAGE
1337a6072erobertostruct sockaddr_storage {
134d54cfbdroberto#ifdef ISC_PLATFORM_HAVESALEN
1357a6072eroberto	ntp_u_int8_t	ss_len;		/* address length */
1367a6072eroberto	ntp_u_int8_t	ss_family;	/* address family */
137118e757roberto#else
1387a6072eroberto	short		ss_family;	/* address family */
1397a6072eroberto#endif
1407a6072eroberto	char		__ss_pad1[_SS_PAD1SIZE];
1417a6072eroberto	ntp_uint64_t	__ss_align;	/* force desired structure storage alignment */
1427a6072eroberto	char		__ss_pad2[_SS_PAD2SIZE];
1437a6072eroberto};
1447a6072eroberto#endif
1457a6072eroberto
146118e757roberto/*
1477a6072eroberto * Finally if the platform doesn't support IPv6 we need some
1487a6072eroberto * additional definitions
149118e757roberto */
150118e757roberto
1517a6072eroberto/*
1527a6072eroberto * Flag values for getaddrinfo()
1537a6072eroberto */
154d54cfbdroberto#ifndef AI_PASSIVE
1557a6072eroberto#define	AI_PASSIVE	0x00000001 /* get address to use bind() */
1567a6072eroberto#define	AI_CANONNAME	0x00000002 /* fill ai_canonname */
1577a6072eroberto#define	AI_NUMERICHOST	0x00000004 /* prevent name resolution */
1587a6072eroberto/* valid flags for addrinfo */
1597a6072eroberto#define AI_MASK \
1607a6072eroberto    (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_ADDRCONFIG)
161118e757roberto
1627a6072eroberto#define	AI_ADDRCONFIG	0x00000400 /* only if any address is assigned */
163d54cfbdroberto#endif	/* !AI_PASSIVE */
164118e757roberto
165d54cfbdroberto#ifndef AI_NUMERICHOST		/* such as AIX 4.3 */
166d54cfbdroberto# define Z_AI_NUMERICHOST	0
167118e757roberto#else
168d54cfbdroberto# define Z_AI_NUMERICHOST	AI_NUMERICHOST
1697a6072eroberto#endif
170118e757roberto
171d54cfbdroberto#ifndef AI_NUMERICSERV		/* not in RFC 2553 */
172d54cfbdroberto# define Z_AI_NUMERICSERV	0
1737a6072eroberto#else
174d54cfbdroberto# define Z_AI_NUMERICSERV	AI_NUMERICSERV
1757a6072eroberto#endif
1767a6072eroberto
177d54cfbdroberto#ifndef ISC_PLATFORM_HAVEIPV6
178118e757roberto
179d54cfbdroberto#ifdef SYS_WINNT
180d54cfbdroberto# define in6_addr in_addr6
181118e757roberto#endif
182118e757roberto
183118e757robertostruct addrinfo {
184118e757roberto	int	ai_flags;	/* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
185118e757roberto	int	ai_family;	/* PF_xxx */
186118e757roberto	int	ai_socktype;	/* SOCK_xxx */
187118e757roberto	int	ai_protocol;	/* 0 or IPPROTO_xxx for IPv4 and IPv6 */
188118e757roberto	size_t	ai_addrlen;	/* length of ai_addr */
189118e757roberto	char	*ai_canonname;	/* canonical name for hostname */
190118e757roberto	struct	sockaddr *ai_addr;	/* binary address */
191118e757roberto	struct	addrinfo *ai_next;	/* next structure in linked list */
192118e757roberto};
193118e757roberto
194118e757roberto/*
195118e757roberto * Error return codes from getaddrinfo()
196118e757roberto */
197118e757roberto#define	EAI_ADDRFAMILY	 1	/* address family for hostname not supported */
198118e757roberto#define	EAI_AGAIN	 2	/* temporary failure in name resolution */
199118e757roberto#define	EAI_BADFLAGS	 3	/* invalid value for ai_flags */
200118e757roberto#define	EAI_FAIL	 4	/* non-recoverable failure in name resolution */
201118e757roberto#define	EAI_FAMILY	 5	/* ai_family not supported */
202118e757roberto#define	EAI_MEMORY	 6	/* memory allocation failure */
203118e757roberto#define	EAI_NODATA	 7	/* no address associated with hostname */
204118e757roberto#define	EAI_NONAME	 8	/* hostname nor servname provided, or not known */
205118e757roberto#define	EAI_SERVICE	 9	/* servname not supported for ai_socktype */
206118e757roberto#define	EAI_SOCKTYPE	10	/* ai_socktype not supported */
207118e757roberto#define	EAI_SYSTEM	11	/* system error returned in errno */
208118e757roberto#define	EAI_BADHINTS	12
209118e757roberto#define	EAI_PROTOCOL	13
210118e757roberto#define	EAI_MAX		14
211118e757roberto
212118e757roberto
213d54cfbdrobertoint	getaddrinfo (const char *, const char *,
214d54cfbdroberto			 const struct addrinfo *, struct addrinfo **);
215d54cfbdrobertoint	getnameinfo (const struct sockaddr *, u_int, char *,
216d54cfbdroberto			 size_t, char *, size_t, int);
217d54cfbdrobertovoid	freeaddrinfo (struct addrinfo *);
218d54cfbdrobertochar	*gai_strerror (int);
219118e757roberto
220118e757roberto/*
221118e757roberto * Constants for getnameinfo()
222118e757roberto */
2237a6072eroberto#ifndef NI_MAXHOST
224118e757roberto#define	NI_MAXHOST	1025
225118e757roberto#define	NI_MAXSERV	32
2267a6072eroberto#endif
227118e757roberto
228118e757roberto/*
229118e757roberto * Flag values for getnameinfo()
230118e757roberto */
2317a6072eroberto#ifndef NI_NUMERICHOST
232118e757roberto#define	NI_NOFQDN	0x00000001
233118e757roberto#define	NI_NUMERICHOST	0x00000002
234118e757roberto#define	NI_NAMEREQD	0x00000004
235118e757roberto#define	NI_NUMERICSERV	0x00000008
236118e757roberto#define	NI_DGRAM	0x00000010
237118e757roberto#define NI_WITHSCOPEID	0x00000020
2387a6072eroberto#endif
239118e757roberto
240d54cfbdroberto#endif /* !ISC_PLATFORM_HAVEIPV6 */
241d54cfbdroberto
242d54cfbdroberto/*
243d54cfbdroberto * Set up some macros to look for IPv6 and IPv6 multicast
244d54cfbdroberto */
245d54cfbdroberto
246d54cfbdroberto#if defined(ISC_PLATFORM_HAVEIPV6) && defined(WANT_IPV6)
247d54cfbdroberto# define INCLUDE_IPV6_SUPPORT
248d54cfbdroberto# if defined(IPV6_JOIN_GROUP) && defined(IPV6_LEAVE_GROUP)
249d54cfbdroberto#  define INCLUDE_IPV6_MULTICAST_SUPPORT
250d54cfbdroberto# endif	/* IPV6 Multicast Support */
251d54cfbdroberto#endif  /* IPv6 Support */
252118e757roberto
253d54cfbdroberto#endif /* !NTP_RFC2553_H */
254