ntp_rfc2553.h revision 267654
1279264Sdelphij/*
296593Smarkm * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
396593Smarkm * All rights reserved.
4142429Snectar *
596593Smarkm * Redistribution and use in source and binary forms, with or without
696593Smarkm * modification, are permitted provided that the following conditions
796593Smarkm * are met:
896593Smarkm * 1. Redistributions of source code must retain the above copyright
996593Smarkm *    notice, this list of conditions and the following disclaimer.
1096593Smarkm * 2. Redistributions in binary form must reproduce the above copyright
1196593Smarkm *    notice, this list of conditions and the following disclaimer in the
1296593Smarkm *    documentation and/or other materials provided with the distribution.
1396593Smarkm * 3. Neither the name of the project nor the names of its contributors
1496593Smarkm *    may be used to endorse or promote products derived from this software
1596593Smarkm *    without specific prior written permission.
1696593Smarkm *
1796593Smarkm * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
1896593Smarkm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1996593Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20215698Ssimon * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21215698Ssimon * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22215698Ssimon * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23215698Ssimon * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24215698Ssimon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2596593Smarkm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2696593Smarkm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2796593Smarkm * SUCH DAMAGE.
2896593Smarkm */
2996593Smarkm
3096593Smarkm/*
3196593Smarkm * Copyright (c) 1982, 1986, 1990, 1993
3296593Smarkm *	The Regents of the University of California.  All rights reserved.
3396593Smarkm *
3496593Smarkm * Redistribution and use in source and binary forms, with or without
3596593Smarkm * modification, are permitted provided that the following conditions
3696593Smarkm * are met:
3796593Smarkm * 1. Redistributions of source code must retain the above copyright
3896593Smarkm *    notice, this list of conditions and the following disclaimer.
3996593Smarkm * 2. Redistributions in binary form must reproduce the above copyright
4096593Smarkm *    notice, this list of conditions and the following disclaimer in the
41279264Sdelphij *    documentation and/or other materials provided with the distribution.
42279264Sdelphij * 3. All advertising materials mentioning features or use of this software
4396593Smarkm *    must display the following acknowledgement:
4496593Smarkm *	This product includes software developed by the University of
45215698Ssimon *	California, Berkeley and its contributors.
46215698Ssimon * 4. Neither the name of the University nor the names of its contributors
47215698Ssimon *    may be used to endorse or promote products derived from this software
48215698Ssimon *    without specific prior written permission.
49142429Snectar *
50215698Ssimon * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51142429Snectar * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52142429Snectar * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53279264Sdelphij * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54279264Sdelphij * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55279264Sdelphij * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5696593Smarkm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57279264Sdelphij * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58279264Sdelphij * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59279264Sdelphij * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60279264Sdelphij * SUCH DAMAGE.
61279264Sdelphij *
62279264Sdelphij *	@(#)in.h	8.3 (Berkeley) 1/3/94
63215698Ssimon */
64279264Sdelphij
65279264Sdelphij/*
66279264Sdelphij * Compatability shims with the rfc2553 API to simplify ntp.
67279264Sdelphij */
68279264Sdelphij#ifndef _NTP_RFC2553_H_
69215698Ssimon#define _NTP_RFC2553_H_
70279264Sdelphij
7196593Smarkm/*
7296593Smarkm * Ensure that we include the configuration file before we check
7396593Smarkm * for IPV6
7496593Smarkm */
7596593Smarkm#include <config.h>
7696593Smarkm
7796593Smarkm#include <netdb.h>
7896593Smarkm
7996593Smarkm#include "ntp_types.h"
8096593Smarkm
8196593Smarkm/*
8296593Smarkm * Don't include any additional IPv6 definitions
8396593Smarkm * We are defining our own here.
8496593Smarkm */
8596593Smarkm#define ISC_IPV6_H 1
8696593Smarkm
8796593Smarkm /*
8896593Smarkm * If various macros are not defined we need to define them
8996593Smarkm */
9096593Smarkm
9196593Smarkm#ifndef AF_INET6
9296593Smarkm#define AF_INET6	AF_MAX
9396593Smarkm#define PF_INET6	AF_INET6
9496593Smarkm#endif
9596593Smarkm
9696593Smarkm#if !defined(_SS_MAXSIZE) && !defined(_SS_ALIGNSIZE)
9796593Smarkm
9896593Smarkm#define	_SS_MAXSIZE	128
9996593Smarkm#define	_SS_ALIGNSIZE	(sizeof(ntp_uint64_t))
10096593Smarkm#ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR
10196593Smarkm#define	_SS_PAD1SIZE	(_SS_ALIGNSIZE - sizeof(u_char) - sizeof(ntp_u_int8_t))
10296593Smarkm#define	_SS_PAD2SIZE	(_SS_MAXSIZE - sizeof(u_char) - sizeof(ntp_u_int8_t) - \
10396593Smarkm				_SS_PAD1SIZE - _SS_ALIGNSIZE)
10496593Smarkm#else
10596593Smarkm#define	_SS_PAD1SIZE	(_SS_ALIGNSIZE - sizeof(short))
10696593Smarkm#define	_SS_PAD2SIZE	(_SS_MAXSIZE - sizeof(short) - \
10796593Smarkm				_SS_PAD1SIZE - _SS_ALIGNSIZE)
10896593Smarkm#endif /* HAVE_SA_LEN_IN_STRUCT_SOCKADDR */
10996593Smarkm#endif
11096593Smarkm
11196593Smarkm/*
11296593Smarkm * If we don't have the sockaddr_storage structure
11396593Smarkm * we need to define it
11496593Smarkm */
11596593Smarkm
11696593Smarkm#ifndef HAVE_STRUCT_SOCKADDR_STORAGE
11796593Smarkmstruct sockaddr_storage {
11896593Smarkm#ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR
11996593Smarkm	ntp_u_int8_t	ss_len;		/* address length */
12096593Smarkm	ntp_u_int8_t	ss_family;	/* address family */
12196593Smarkm#else
12296593Smarkm	short		ss_family;	/* address family */
12396593Smarkm#endif
12496593Smarkm	char		__ss_pad1[_SS_PAD1SIZE];
12596593Smarkm	ntp_uint64_t	__ss_align;	/* force desired structure storage alignment */
12696593Smarkm	char		__ss_pad2[_SS_PAD2SIZE];
12796593Smarkm};
12896593Smarkm#endif
12996593Smarkm
13096593Smarkm/*
13196593Smarkm * Finally if the platform doesn't support IPv6 we need some
13296593Smarkm * additional definitions
133142429Snectar */
13496593Smarkm
135100946Snectar/*
136279264Sdelphij * Flag values for getaddrinfo()
137215698Ssimon */
138215698Ssimon#ifndef AI_NUMERICHOST
139215698Ssimon#define	AI_PASSIVE	0x00000001 /* get address to use bind() */
140215698Ssimon#define	AI_CANONNAME	0x00000002 /* fill ai_canonname */
14196593Smarkm#define	AI_NUMERICHOST	0x00000004 /* prevent name resolution */
14296593Smarkm/* valid flags for addrinfo */
14396593Smarkm#define AI_MASK \
14496593Smarkm    (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_ADDRCONFIG)
14596593Smarkm
14696593Smarkm#define	AI_ADDRCONFIG	0x00000400 /* only if any address is assigned */
14796593Smarkm#endif
14896593Smarkm
149215698Ssimon#ifndef ISC_PLATFORM_HAVEIPV6
15096593Smarkm/*
15196593Smarkm * Definition of some useful macros to handle IP6 addresses
15296593Smarkm */
153215698Ssimon#ifdef ISC_PLATFORM_NEEDIN6ADDRANY
15496593Smarkm#ifdef SYS_WINNT
155215698Ssimon#define IN6ADDR_ANY_INIT 	{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }}
15696593Smarkm#else
15796593Smarkm#define IN6ADDR_ANY_INIT \
158215698Ssimon	{{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
15996593Smarkm	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
16096593Smarkm#endif
16196593Smarkm#endif
16296593Smarkm
16396593Smarkm
16496593Smarkm/*
165142429Snectar * IPv6 address
16696593Smarkm */
16796593Smarkm#ifdef SYS_WINNT
16896593Smarkm#define in6_addr in_addr6
16996593Smarkm#else
17096593Smarkm
17196593Smarkmstruct in6_addr {
17296593Smarkm	union {
17396593Smarkm		ntp_u_int8_t   __u6_addr8[16];
17496593Smarkm		ntp_u_int16_t  __u6_addr16[8];
17596593Smarkm		ntp_u_int32_t  __u6_addr32[4];
17696593Smarkm	} __u6_addr;			/* 128-bit IP6 address */
17796593Smarkm};
17896593Smarkm
17996593Smarkm#define s6_addr   __u6_addr.__u6_addr8
18096593Smarkm#endif
18196593Smarkm
18296593Smarkm#if defined(ISC_PLATFORM_HAVEIPV6) && defined(ISC_PLATFORM_NEEDIN6ADDRANY)
18396593Smarkmextern const struct in6_addr in6addr_any;
18496593Smarkm#endif
18596593Smarkm
18696593Smarkm#define SIN6_LEN
18796593Smarkm#ifndef HAVE_SOCKADDR_IN6
18896593Smarkmstruct sockaddr_in6 {
18996593Smarkm#ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR
19096593Smarkm	ntp_u_int8_t	sin6_len;	/* length of this struct(sa_family_t)*/
19196593Smarkm	ntp_u_int8_t	sin6_family;	/* AF_INET6 (sa_family_t) */
19296593Smarkm#else
19396593Smarkm	short		sin6_family;	/* AF_INET6 (sa_family_t) */
19496593Smarkm#endif
19596593Smarkm	ntp_u_int16_t	sin6_port;	/* Transport layer port # (in_port_t)*/
196142429Snectar	ntp_u_int32_t	sin6_flowinfo;	/* IP6 flow information */
19796593Smarkm	struct in6_addr	sin6_addr;	/* IP6 address */
19896593Smarkm	ntp_u_int32_t	sin6_scope_id;	/* scope zone index */
19996593Smarkm};
20096593Smarkm#endif
20196593Smarkm
20296593Smarkm/*
20396593Smarkm * Unspecified
20496593Smarkm */
20596593Smarkm#ifndef IN6_IS_ADDR_UNSPECIFIED
206142429Snectar#define IN6_IS_ADDR_UNSPECIFIED(a)	\
20796593Smarkm	((*(const ntp_u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) &&	\
20896593Smarkm	 (*(const ntp_u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) &&	\
209142429Snectar	 (*(const ntp_u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) &&	\
210142429Snectar	 (*(const ntp_u_int32_t *)(const void *)(&(a)->s6_addr[12]) == 0))
21196593Smarkm#endif
21296593Smarkm/*
21396593Smarkm * Multicast
21496593Smarkm */
21596593Smarkm#ifndef IN6_IS_ADDR_MULTICAST
216#define IN6_IS_ADDR_MULTICAST(a)	((a)->s6_addr[0] == 0xff)
217#endif
218/*
219 * Unicast link / site local.
220 */
221#ifndef IN6_IS_ADDR_LINKLOCAL
222#define IN6_IS_ADDR_LINKLOCAL(a)	(\
223(*((u_long *)((a)->s6_addr)    ) == 0xfe) && \
224((*((u_long *)((a)->s6_addr) + 1) & 0xc0) == 0x80))
225#endif
226
227#ifndef IN6_IS_ADDR_SITELOCAL
228#define IN6_IS_ADDR_SITELOCAL(a)	(\
229(*((u_long *)((a)->s6_addr)    ) == 0xfe) && \
230((*((u_long *)((a)->s6_addr) + 1) & 0xc0) == 0xc0))
231#endif
232
233struct addrinfo {
234	int	ai_flags;	/* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
235	int	ai_family;	/* PF_xxx */
236	int	ai_socktype;	/* SOCK_xxx */
237	int	ai_protocol;	/* 0 or IPPROTO_xxx for IPv4 and IPv6 */
238	size_t	ai_addrlen;	/* length of ai_addr */
239	char	*ai_canonname;	/* canonical name for hostname */
240	struct	sockaddr *ai_addr;	/* binary address */
241	struct	addrinfo *ai_next;	/* next structure in linked list */
242};
243
244/*
245 * Error return codes from getaddrinfo()
246 */
247#define	EAI_ADDRFAMILY	 1	/* address family for hostname not supported */
248#define	EAI_AGAIN	 2	/* temporary failure in name resolution */
249#define	EAI_BADFLAGS	 3	/* invalid value for ai_flags */
250#define	EAI_FAIL	 4	/* non-recoverable failure in name resolution */
251#define	EAI_FAMILY	 5	/* ai_family not supported */
252#define	EAI_MEMORY	 6	/* memory allocation failure */
253#define	EAI_NODATA	 7	/* no address associated with hostname */
254#define	EAI_NONAME	 8	/* hostname nor servname provided, or not known */
255#define	EAI_SERVICE	 9	/* servname not supported for ai_socktype */
256#define	EAI_SOCKTYPE	10	/* ai_socktype not supported */
257#define	EAI_SYSTEM	11	/* system error returned in errno */
258#define	EAI_BADHINTS	12
259#define	EAI_PROTOCOL	13
260#define	EAI_MAX		14
261
262
263int	getaddrinfo P((const char *, const char *,
264			 const struct addrinfo *, struct addrinfo **));
265int	getnameinfo P((const struct sockaddr *, u_int, char *,
266			 size_t, char *, size_t, int));
267void	freeaddrinfo P((struct addrinfo *));
268char	*gai_strerror P((int));
269
270/*
271 * Constants for getnameinfo()
272 */
273#ifndef NI_MAXHOST
274#define	NI_MAXHOST	1025
275#define	NI_MAXSERV	32
276#endif
277
278/*
279 * Flag values for getnameinfo()
280 */
281#ifndef NI_NUMERICHOST
282#define	NI_NOFQDN	0x00000001
283#define	NI_NUMERICHOST	0x00000002
284#define	NI_NAMEREQD	0x00000004
285#define	NI_NUMERICSERV	0x00000008
286#define	NI_DGRAM	0x00000010
287#define NI_WITHSCOPEID	0x00000020
288#endif
289
290#endif /* ISC_PLATFORM_HAVEIPV6 */
291
292#endif /* !_NTP_RFC2553_H_ */
293