1 /* $NetBSD: ntp_rfc2553.h,v 1.1.1.2 2012/01/31 21:23:24 kardel Exp $ */ 2 3 /* 4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. Neither the name of the project nor the names of its contributors 16 * may be used to endorse or promote products derived from this software 17 * without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31 32 /* 33 * Copyright (c) 1982, 1986, 1990, 1993 34 * The Regents of the University of California. All rights reserved. 35 * 36 * Redistribution and use in source and binary forms, with or without 37 * modification, are permitted provided that the following conditions 38 * are met: 39 * 1. Redistributions of source code must retain the above copyright 40 * notice, this list of conditions and the following disclaimer. 41 * 2. Redistributions in binary form must reproduce the above copyright 42 * notice, this list of conditions and the following disclaimer in the 43 * documentation and/or other materials provided with the distribution. 44 * 3. All advertising materials mentioning features or use of this software 45 * must display the following acknowledgement: 46 * This product includes software developed by the University of 47 * California, Berkeley and its contributors. 48 * 4. Neither the name of the University nor the names of its contributors 49 * may be used to endorse or promote products derived from this software 50 * without specific prior written permission. 51 * 52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 62 * SUCH DAMAGE. 63 * 64 * @(#)in.h 8.3 (Berkeley) 1/3/94 65 */ 66 67 /* 68 * Compatability shims with the rfc2553 API to simplify ntp. 69 */ 70 #ifndef NTP_RFC2553_H 71 #define NTP_RFC2553_H 72 73 /* 74 * Ensure that we include the configuration file before we check 75 * for IPV6 76 */ 77 #include <config.h> 78 #include <netdb.h> 79 #include <isc/net.h> 80 81 #include "ntp_types.h" 82 83 84 /* 85 * If various macros are not defined we need to define them 86 */ 87 88 #ifndef AF_INET6 89 # define AF_INET6 AF_MAX 90 # define PF_INET6 AF_INET6 91 #endif 92 93 #if !defined(_SS_MAXSIZE) && !defined(_SS_ALIGNSIZE) 94 95 # define _SS_MAXSIZE 128 96 # define _SS_ALIGNSIZE (sizeof(ntp_uint64_t)) 97 # ifdef ISC_PLATFORM_HAVESALEN 98 # define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(u_char) - sizeof(ntp_u_int8_t)) 99 # define _SS_PAD2SIZE (_SS_MAXSIZE - sizeof(u_char) - sizeof(ntp_u_int8_t) - \ 100 _SS_PAD1SIZE - _SS_ALIGNSIZE) 101 # else 102 # define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(short)) 103 # define _SS_PAD2SIZE (_SS_MAXSIZE - sizeof(short) - \ 104 _SS_PAD1SIZE - _SS_ALIGNSIZE) 105 # endif /* ISC_PLATFORM_HAVESALEN */ 106 #endif 107 108 #ifndef INET6_ADDRSTRLEN 109 # define INET6_ADDRSTRLEN 46 /* max len of IPv6 addr in ascii */ 110 #endif 111 112 /* 113 * If we don't have the sockaddr_storage structure 114 * we need to define it 115 */ 116 117 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE 118 struct sockaddr_storage { 119 #ifdef ISC_PLATFORM_HAVESALEN 120 ntp_u_int8_t ss_len; /* address length */ 121 ntp_u_int8_t ss_family; /* address family */ 122 #else 123 short ss_family; /* address family */ 124 #endif 125 char __ss_pad1[_SS_PAD1SIZE]; 126 ntp_uint64_t __ss_align; /* force desired structure storage alignment */ 127 char __ss_pad2[_SS_PAD2SIZE]; 128 }; 129 #endif 130 131 /* 132 * Finally if the platform doesn't support IPv6 we need some 133 * additional definitions 134 */ 135 136 /* 137 * Flag values for getaddrinfo() 138 */ 139 #ifndef AI_PASSIVE 140 #define AI_PASSIVE 0x00000001 /* get address to use bind() */ 141 #define AI_CANONNAME 0x00000002 /* fill ai_canonname */ 142 #define AI_NUMERICHOST 0x00000004 /* prevent name resolution */ 143 /* valid flags for addrinfo */ 144 #define AI_MASK \ 145 (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_ADDRCONFIG) 146 147 #define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */ 148 #endif /* !AI_PASSIVE */ 149 150 #ifndef AI_NUMERICHOST /* such as AIX 4.3 */ 151 # define Z_AI_NUMERICHOST 0 152 #else 153 # define Z_AI_NUMERICHOST AI_NUMERICHOST 154 #endif 155 156 #ifndef AI_NUMERICSERV /* not in RFC 2553 */ 157 # define Z_AI_NUMERICSERV 0 158 #else 159 # define Z_AI_NUMERICSERV AI_NUMERICSERV 160 #endif 161 162 #ifndef ISC_PLATFORM_HAVEIPV6 163 164 #ifdef SYS_WINNT 165 # define in6_addr in_addr6 166 #endif 167 168 struct addrinfo { 169 int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */ 170 int ai_family; /* PF_xxx */ 171 int ai_socktype; /* SOCK_xxx */ 172 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ 173 size_t ai_addrlen; /* length of ai_addr */ 174 char *ai_canonname; /* canonical name for hostname */ 175 struct sockaddr *ai_addr; /* binary address */ 176 struct addrinfo *ai_next; /* next structure in linked list */ 177 }; 178 179 /* 180 * Error return codes from getaddrinfo() 181 */ 182 #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ 183 #define EAI_AGAIN 2 /* temporary failure in name resolution */ 184 #define EAI_BADFLAGS 3 /* invalid value for ai_flags */ 185 #define EAI_FAIL 4 /* non-recoverable failure in name resolution */ 186 #define EAI_FAMILY 5 /* ai_family not supported */ 187 #define EAI_MEMORY 6 /* memory allocation failure */ 188 #define EAI_NODATA 7 /* no address associated with hostname */ 189 #define EAI_NONAME 8 /* hostname nor servname provided, or not known */ 190 #define EAI_SERVICE 9 /* servname not supported for ai_socktype */ 191 #define EAI_SOCKTYPE 10 /* ai_socktype not supported */ 192 #define EAI_SYSTEM 11 /* system error returned in errno */ 193 #define EAI_BADHINTS 12 194 #define EAI_PROTOCOL 13 195 #define EAI_MAX 14 196 197 198 int getaddrinfo (const char *, const char *, 199 const struct addrinfo *, struct addrinfo **); 200 int getnameinfo (const struct sockaddr *, u_int, char *, 201 size_t, char *, size_t, int); 202 void freeaddrinfo (struct addrinfo *); 203 char *gai_strerror (int); 204 205 /* 206 * Constants for getnameinfo() 207 */ 208 #ifndef NI_MAXHOST 209 #define NI_MAXHOST 1025 210 #define NI_MAXSERV 32 211 #endif 212 213 /* 214 * Flag values for getnameinfo() 215 */ 216 #ifndef NI_NUMERICHOST 217 #define NI_NOFQDN 0x00000001 218 #define NI_NUMERICHOST 0x00000002 219 #define NI_NAMEREQD 0x00000004 220 #define NI_NUMERICSERV 0x00000008 221 #define NI_DGRAM 0x00000010 222 #define NI_WITHSCOPEID 0x00000020 223 #endif 224 225 #endif /* !ISC_PLATFORM_HAVEIPV6 */ 226 227 /* 228 * Set up some macros to look for IPv6 and IPv6 multicast 229 */ 230 231 #if defined(ISC_PLATFORM_HAVEIPV6) && defined(WANT_IPV6) 232 # define INCLUDE_IPV6_SUPPORT 233 # if defined(IPV6_JOIN_GROUP) && defined(IPV6_LEAVE_GROUP) 234 # define INCLUDE_IPV6_MULTICAST_SUPPORT 235 # endif /* IPV6 Multicast Support */ 236 #endif /* IPv6 Support */ 237 238 #endif /* !NTP_RFC2553_H */ 239