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 */ 68132451Sroberto#ifndef _NTP_RFC2553_H_ 69132451Sroberto#define _NTP_RFC2553_H_ 70132451Sroberto 71182007Sroberto/* 72182007Sroberto * Ensure that we include the configuration file before we check 73182007Sroberto * for IPV6 74182007Sroberto */ 75182007Sroberto#include <config.h> 76132451Sroberto 77182007Sroberto#include <netdb.h> 78182007Sroberto 79132451Sroberto#include "ntp_types.h" 80132451Sroberto 81182007Sroberto/* 82182007Sroberto * Don't include any additional IPv6 definitions 83182007Sroberto * We are defining our own here. 84182007Sroberto */ 85182007Sroberto#define ISC_IPV6_H 1 86182007Sroberto 87182007Sroberto /* 88182007Sroberto * If various macros are not defined we need to define them 89182007Sroberto */ 90182007Sroberto 91132451Sroberto#ifndef AF_INET6 92132451Sroberto#define AF_INET6 AF_MAX 93132451Sroberto#define PF_INET6 AF_INET6 94132451Sroberto#endif 95132451Sroberto 96182007Sroberto#if !defined(_SS_MAXSIZE) && !defined(_SS_ALIGNSIZE) 97132451Sroberto 98182007Sroberto#define _SS_MAXSIZE 128 99182007Sroberto#define _SS_ALIGNSIZE (sizeof(ntp_uint64_t)) 100182007Sroberto#ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR 101182007Sroberto#define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(u_char) - sizeof(ntp_u_int8_t)) 102182007Sroberto#define _SS_PAD2SIZE (_SS_MAXSIZE - sizeof(u_char) - sizeof(ntp_u_int8_t) - \ 103182007Sroberto _SS_PAD1SIZE - _SS_ALIGNSIZE) 104182007Sroberto#else 105182007Sroberto#define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(short)) 106182007Sroberto#define _SS_PAD2SIZE (_SS_MAXSIZE - sizeof(short) - \ 107182007Sroberto _SS_PAD1SIZE - _SS_ALIGNSIZE) 108182007Sroberto#endif /* HAVE_SA_LEN_IN_STRUCT_SOCKADDR */ 109182007Sroberto#endif 110132451Sroberto 111132451Sroberto/* 112182007Sroberto * If we don't have the sockaddr_storage structure 113182007Sroberto * we need to define it 114132451Sroberto */ 115182007Sroberto 116182007Sroberto#ifndef HAVE_STRUCT_SOCKADDR_STORAGE 117182007Srobertostruct sockaddr_storage { 118182007Sroberto#ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR 119182007Sroberto ntp_u_int8_t ss_len; /* address length */ 120182007Sroberto ntp_u_int8_t ss_family; /* address family */ 121132451Sroberto#else 122182007Sroberto short ss_family; /* address family */ 123182007Sroberto#endif 124182007Sroberto char __ss_pad1[_SS_PAD1SIZE]; 125182007Sroberto ntp_uint64_t __ss_align; /* force desired structure storage alignment */ 126182007Sroberto char __ss_pad2[_SS_PAD2SIZE]; 127182007Sroberto}; 128182007Sroberto#endif 129182007Sroberto 130132451Sroberto/* 131182007Sroberto * Finally if the platform doesn't support IPv6 we need some 132182007Sroberto * additional definitions 133132451Sroberto */ 134132451Sroberto 135182007Sroberto/* 136182007Sroberto * Flag values for getaddrinfo() 137182007Sroberto */ 138182007Sroberto#ifndef AI_NUMERICHOST 139182007Sroberto#define AI_PASSIVE 0x00000001 /* get address to use bind() */ 140182007Sroberto#define AI_CANONNAME 0x00000002 /* fill ai_canonname */ 141182007Sroberto#define AI_NUMERICHOST 0x00000004 /* prevent name resolution */ 142182007Sroberto/* valid flags for addrinfo */ 143182007Sroberto#define AI_MASK \ 144182007Sroberto (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_ADDRCONFIG) 145132451Sroberto 146182007Sroberto#define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */ 147132451Sroberto#endif 148132451Sroberto 149182007Sroberto#ifndef ISC_PLATFORM_HAVEIPV6 150132451Sroberto/* 151132451Sroberto * Definition of some useful macros to handle IP6 addresses 152132451Sroberto */ 153182007Sroberto#ifdef ISC_PLATFORM_NEEDIN6ADDRANY 154132451Sroberto#ifdef SYS_WINNT 155132451Sroberto#define IN6ADDR_ANY_INIT {{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }} 156132451Sroberto#else 157132451Sroberto#define IN6ADDR_ANY_INIT \ 158132451Sroberto {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 159132451Sroberto 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} 160132451Sroberto#endif 161182007Sroberto#endif 162132451Sroberto 163182007Sroberto 164182007Sroberto/* 165182007Sroberto * IPv6 address 166182007Sroberto */ 167182007Sroberto#ifdef SYS_WINNT 168182007Sroberto#define in6_addr in_addr6 169182007Sroberto#else 170182007Sroberto 171182007Srobertostruct in6_addr { 172182007Sroberto union { 173182007Sroberto ntp_u_int8_t __u6_addr8[16]; 174182007Sroberto ntp_u_int16_t __u6_addr16[8]; 175182007Sroberto ntp_u_int32_t __u6_addr32[4]; 176182007Sroberto } __u6_addr; /* 128-bit IP6 address */ 177182007Sroberto}; 178182007Sroberto 179182007Sroberto#define s6_addr __u6_addr.__u6_addr8 180182007Sroberto#endif 181182007Sroberto 182182007Sroberto#if defined(ISC_PLATFORM_HAVEIPV6) && defined(ISC_PLATFORM_NEEDIN6ADDRANY) 183132451Srobertoextern const struct in6_addr in6addr_any; 184182007Sroberto#endif 185132451Sroberto 186132451Sroberto#define SIN6_LEN 187132451Sroberto#ifndef HAVE_SOCKADDR_IN6 188132451Srobertostruct sockaddr_in6 { 189132451Sroberto#ifdef HAVE_SA_LEN_IN_STRUCT_SOCKADDR 190182007Sroberto ntp_u_int8_t sin6_len; /* length of this struct(sa_family_t)*/ 191182007Sroberto ntp_u_int8_t sin6_family; /* AF_INET6 (sa_family_t) */ 192132451Sroberto#else 193132451Sroberto short sin6_family; /* AF_INET6 (sa_family_t) */ 194132451Sroberto#endif 195182007Sroberto ntp_u_int16_t sin6_port; /* Transport layer port # (in_port_t)*/ 196182007Sroberto ntp_u_int32_t sin6_flowinfo; /* IP6 flow information */ 197132451Sroberto struct in6_addr sin6_addr; /* IP6 address */ 198182007Sroberto ntp_u_int32_t sin6_scope_id; /* scope zone index */ 199132451Sroberto}; 200132451Sroberto#endif 201132451Sroberto 202132451Sroberto/* 203132451Sroberto * Unspecified 204132451Sroberto */ 205132451Sroberto#ifndef IN6_IS_ADDR_UNSPECIFIED 206132451Sroberto#define IN6_IS_ADDR_UNSPECIFIED(a) \ 207182007Sroberto ((*(const ntp_u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 208182007Sroberto (*(const ntp_u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 209182007Sroberto (*(const ntp_u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ 210182007Sroberto (*(const ntp_u_int32_t *)(const void *)(&(a)->s6_addr[12]) == 0)) 211132451Sroberto#endif 212132451Sroberto/* 213132451Sroberto * Multicast 214132451Sroberto */ 215132451Sroberto#ifndef IN6_IS_ADDR_MULTICAST 216132451Sroberto#define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff) 217132451Sroberto#endif 218132451Sroberto/* 219182007Sroberto * Unicast link / site local. 220132451Sroberto */ 221182007Sroberto#ifndef IN6_IS_ADDR_LINKLOCAL 222182007Sroberto#define IN6_IS_ADDR_LINKLOCAL(a) (\ 223182007Sroberto(*((u_long *)((a)->s6_addr) ) == 0xfe) && \ 224182007Sroberto((*((u_long *)((a)->s6_addr) + 1) & 0xc0) == 0x80)) 225182007Sroberto#endif 226132451Sroberto 227182007Sroberto#ifndef IN6_IS_ADDR_SITELOCAL 228182007Sroberto#define IN6_IS_ADDR_SITELOCAL(a) (\ 229182007Sroberto(*((u_long *)((a)->s6_addr) ) == 0xfe) && \ 230182007Sroberto((*((u_long *)((a)->s6_addr) + 1) & 0xc0) == 0xc0)) 231132451Sroberto#endif 232132451Sroberto 233132451Srobertostruct addrinfo { 234132451Sroberto int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */ 235132451Sroberto int ai_family; /* PF_xxx */ 236132451Sroberto int ai_socktype; /* SOCK_xxx */ 237132451Sroberto int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ 238132451Sroberto size_t ai_addrlen; /* length of ai_addr */ 239132451Sroberto char *ai_canonname; /* canonical name for hostname */ 240132451Sroberto struct sockaddr *ai_addr; /* binary address */ 241132451Sroberto struct addrinfo *ai_next; /* next structure in linked list */ 242132451Sroberto}; 243132451Sroberto 244132451Sroberto/* 245132451Sroberto * Error return codes from getaddrinfo() 246132451Sroberto */ 247132451Sroberto#define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ 248132451Sroberto#define EAI_AGAIN 2 /* temporary failure in name resolution */ 249132451Sroberto#define EAI_BADFLAGS 3 /* invalid value for ai_flags */ 250132451Sroberto#define EAI_FAIL 4 /* non-recoverable failure in name resolution */ 251132451Sroberto#define EAI_FAMILY 5 /* ai_family not supported */ 252132451Sroberto#define EAI_MEMORY 6 /* memory allocation failure */ 253132451Sroberto#define EAI_NODATA 7 /* no address associated with hostname */ 254132451Sroberto#define EAI_NONAME 8 /* hostname nor servname provided, or not known */ 255132451Sroberto#define EAI_SERVICE 9 /* servname not supported for ai_socktype */ 256132451Sroberto#define EAI_SOCKTYPE 10 /* ai_socktype not supported */ 257132451Sroberto#define EAI_SYSTEM 11 /* system error returned in errno */ 258132451Sroberto#define EAI_BADHINTS 12 259132451Sroberto#define EAI_PROTOCOL 13 260132451Sroberto#define EAI_MAX 14 261132451Sroberto 262132451Sroberto 263182007Srobertoint getaddrinfo P((const char *, const char *, 264182007Sroberto const struct addrinfo *, struct addrinfo **)); 265182007Srobertoint getnameinfo P((const struct sockaddr *, u_int, char *, 266182007Sroberto size_t, char *, size_t, int)); 267182007Srobertovoid freeaddrinfo P((struct addrinfo *)); 268182007Srobertochar *gai_strerror P((int)); 269132451Sroberto 270132451Sroberto/* 271132451Sroberto * Constants for getnameinfo() 272132451Sroberto */ 273182007Sroberto#ifndef NI_MAXHOST 274132451Sroberto#define NI_MAXHOST 1025 275132451Sroberto#define NI_MAXSERV 32 276182007Sroberto#endif 277132451Sroberto 278132451Sroberto/* 279132451Sroberto * Flag values for getnameinfo() 280132451Sroberto */ 281182007Sroberto#ifndef NI_NUMERICHOST 282132451Sroberto#define NI_NOFQDN 0x00000001 283132451Sroberto#define NI_NUMERICHOST 0x00000002 284132451Sroberto#define NI_NAMEREQD 0x00000004 285132451Sroberto#define NI_NUMERICSERV 0x00000008 286132451Sroberto#define NI_DGRAM 0x00000010 287132451Sroberto#define NI_WITHSCOPEID 0x00000020 288182007Sroberto#endif 289132451Sroberto 290182007Sroberto#endif /* ISC_PLATFORM_HAVEIPV6 */ 291132451Sroberto 292132451Sroberto#endif /* !_NTP_RFC2553_H_ */ 293