1 /* $NetBSD: netdb.h,v 1.30 2003/05/05 14:20:03 bjh21 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) 1980, 1983, 1988, 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 * @(#)netdb.h 8.1 (Berkeley) 6/2/93 65 * Id: netdb.h,v 4.9.1.2 1993/05/17 09:59:01 vixie Exp 66 * - 67 * Portions Copyright (c) 1993 by Digital Equipment Corporation. 68 * 69 * Permission to use, copy, modify, and distribute this software for any 70 * purpose with or without fee is hereby granted, provided that the above 71 * copyright notice and this permission notice appear in all copies, and that 72 * the name of Digital Equipment Corporation not be used in advertising or 73 * publicity pertaining to distribution of the document or software without 74 * specific, written prior permission. 75 * 76 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL 77 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 78 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT 79 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 80 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 81 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 82 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 83 * SOFTWARE. 84 * - 85 * --Copyright-- 86 */ 87 88 #ifndef _NETDB_H_ 89 #define _NETDB_H_ 90 91 #include <machine/ansi.h> 92 #include <sys/ansi.h> 93 #include <sys/cdefs.h> 94 #include <sys/featuretest.h> 95 #include <inttypes.h> 96 97 /* 98 * Data types 99 */ 100 #ifndef socklen_t 101 typedef __socklen_t socklen_t; 102 #define socklen_t __socklen_t 103 #endif 104 105 #ifdef _BSD_SIZE_T_ 106 typedef _BSD_SIZE_T_ size_t; 107 #undef _BSD_SIZE_T_ 108 #endif 109 110 #if defined(_NETBSD_SOURCE) 111 #define _PATH_HEQUIV "/etc/hosts.equiv" 112 #define _PATH_HOSTS "/etc/hosts" 113 #define _PATH_NETWORKS "/etc/networks" 114 #define _PATH_PROTOCOLS "/etc/protocols" 115 #define _PATH_SERVICES "/etc/services" 116 #endif 117 118 extern int h_errno; 119 120 /* 121 * Structures returned by network data base library. All addresses are 122 * supplied in host order, and returned in network order (suitable for 123 * use in system calls). 124 */ 125 struct hostent { 126 char *h_name; /* official name of host */ 127 char **h_aliases; /* alias list */ 128 int h_addrtype; /* host address type */ 129 int h_length; /* length of address */ 130 char **h_addr_list; /* list of addresses from name server */ 131 #define h_addr h_addr_list[0] /* address, for backward compatibility */ 132 }; 133 134 /* 135 * Assumption here is that a network number 136 * fits in an unsigned long -- probably a poor one. 137 */ 138 struct netent { 139 char *n_name; /* official name of net */ 140 char **n_aliases; /* alias list */ 141 int n_addrtype; /* net address type */ 142 unsigned long n_net; /* network # XXX */ 143 }; 144 145 struct servent { 146 char *s_name; /* official service name */ 147 char **s_aliases; /* alias list */ 148 int s_port; /* port # */ 149 char *s_proto; /* protocol to use */ 150 }; 151 152 struct protoent { 153 char *p_name; /* official protocol name */ 154 char **p_aliases; /* alias list */ 155 int p_proto; /* protocol # */ 156 }; 157 158 /* 159 * Note: ai_addrlen used to be a size_t, per RFC 2553. 160 * In XNS5.2, and subsequently in POSIX-2001 and 161 * draft-ietf-ipngwg-rfc2553bis-02.txt it was changed to a socklen_t. 162 * To accomodate for this while preserving binary compatibility with the 163 * old interface, we prepend or append 32 bits of padding, depending on 164 * the (LP64) architecture's endianness. 165 * 166 * This should be deleted the next time the libc major number is 167 * incremented. 168 */ 169 #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \ 170 defined(_NETBSD_SOURCE) 171 struct addrinfo { 172 int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */ 173 int ai_family; /* PF_xxx */ 174 int ai_socktype; /* SOCK_xxx */ 175 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ 176 #if defined(__sparc64__) 177 int __ai_pad0; 178 #endif 179 socklen_t ai_addrlen; /* length of ai_addr */ 180 #if defined(__alpha__) || (defined(__i386__) && defined(_LP64)) 181 int __ai_pad0; 182 #endif 183 char *ai_canonname; /* canonical name for hostname */ 184 struct sockaddr *ai_addr; /* binary address */ 185 struct addrinfo *ai_next; /* next structure in linked list */ 186 }; 187 #endif 188 189 /* 190 * Error return codes from gethostbyname() and gethostbyaddr() 191 * (left in extern int h_errno). 192 */ 193 194 #if defined(_NETBSD_SOURCE) 195 #define NETDB_INTERNAL -1 /* see errno */ 196 #define NETDB_SUCCESS 0 /* no problem */ 197 #endif 198 #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */ 199 #define TRY_AGAIN 2 /* Non-Authoritative Host not found, or SERVERFAIL */ 200 #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ 201 #define NO_DATA 4 /* Valid name, no data record of requested type */ 202 #if defined(_NETBSD_SOURCE) 203 #define NO_ADDRESS NO_DATA /* no address, look for MX record */ 204 #endif 205 206 /* 207 * Error return codes from getaddrinfo() 208 */ 209 #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \ 210 defined(_NETBSD_SOURCE) 211 #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ 212 #define EAI_AGAIN 2 /* temporary failure in name resolution */ 213 #define EAI_BADFLAGS 3 /* invalid value for ai_flags */ 214 #define EAI_FAIL 4 /* non-recoverable failure in name resolution */ 215 #define EAI_FAMILY 5 /* ai_family not supported */ 216 #define EAI_MEMORY 6 /* memory allocation failure */ 217 #define EAI_NODATA 7 /* no address associated with hostname */ 218 #define EAI_NONAME 8 /* hostname nor servname provided, or not known */ 219 #define EAI_SERVICE 9 /* servname not supported for ai_socktype */ 220 #define EAI_SOCKTYPE 10 /* ai_socktype not supported */ 221 #define EAI_SYSTEM 11 /* system error returned in errno */ 222 #define EAI_BADHINTS 12 223 #define EAI_PROTOCOL 13 224 #define EAI_MAX 14 225 #endif /* _POSIX_C_SOURCE >= 200112 || _XOPEN_SOURCE >= 520 || _NETBSD_SOURCE */ 226 227 /* 228 * Flag values for getaddrinfo() 229 */ 230 #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \ 231 defined(_NETBSD_SOURCE) 232 #define AI_PASSIVE 0x00000001 /* get address to use bind() */ 233 #define AI_CANONNAME 0x00000002 /* fill ai_canonname */ 234 #define AI_NUMERICHOST 0x00000004 /* prevent name resolution */ 235 /* valid flags for addrinfo */ 236 #define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST) 237 #endif 238 239 #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \ 240 defined(_NETBSD_SOURCE) 241 /* 242 * Constants for getnameinfo() 243 */ 244 #if defined(_NETBSD_SOURCE) 245 #define NI_MAXHOST 1025 246 #define NI_MAXSERV 32 247 #endif 248 249 /* 250 * Flag values for getnameinfo() 251 */ 252 #define NI_NOFQDN 0x00000001 253 #define NI_NUMERICHOST 0x00000002 254 #define NI_NAMEREQD 0x00000004 255 #define NI_NUMERICSERV 0x00000008 256 #define NI_DGRAM 0x00000010 257 #if defined(_NETBSD_SOURCE) 258 #define NI_WITHSCOPEID 0x00000020 /*KAME extension*/ 259 #endif 260 261 /* 262 * Scope delimit character 263 */ 264 #if defined(_NETBSD_SOURCE) 265 #define SCOPE_DELIMITER '%' /*KAME extension*/ 266 #endif 267 #endif /* (_POSIX_C_SOURCE - 0) >= 200112L || ... */ 268 269 __BEGIN_DECLS 270 void endhostent __P((void)); 271 void endnetent __P((void)); 272 void endprotoent __P((void)); 273 void endservent __P((void)); 274 #if (_XOPEN_SOURCE - 0) >= 500 && (_XOPEN_SOURCE - 0) < 600 || \ 275 defined(_NETBSD_SOURCE) 276 void freehostent __P((struct hostent *)); 277 #endif 278 struct hostent *gethostbyaddr __P((const char *, socklen_t, int)); 279 struct hostent *gethostbyname __P((const char *)); 280 #if defined(_NETBSD_SOURCE) 281 struct hostent *gethostbyname2 __P((const char *, int)); 282 #endif 283 struct hostent *gethostent __P((void)); 284 #if (_XOPEN_SOURCE - 0) >= 520 && (_XOPEN_SOURCE - 0) < 600 || \ 285 defined(_NETBSD_SOURCE) 286 #if 0 /* we do not ship these */ 287 struct hostent *getipnodebyaddr __P((const void *, size_t, int, int *)); 288 struct hostent *getipnodebyname __P((const char *, int, int, int *)); 289 #endif 290 #endif 291 struct netent *getnetbyaddr __P((unsigned long, int)); 292 struct netent *getnetbyname __P((const char *)); 293 struct netent *getnetent __P((void)); 294 struct protoent *getprotobyname __P((const char *)); 295 struct protoent *getprotobynumber __P((int)); 296 struct protoent *getprotoent __P((void)); 297 struct servent *getservbyname __P((const char *, const char *)); 298 struct servent *getservbyport __P((int, const char *)); 299 struct servent *getservent __P((void)); 300 #if defined(_NETBSD_SOURCE) 301 void herror __P((const char *)); 302 const char *hstrerror __P((int)); 303 #endif 304 void sethostent __P((int)); 305 #if defined(_NETBSD_SOURCE) 306 /* void sethostfile __P((const char *)); */ 307 #endif 308 void setnetent __P((int)); 309 void setprotoent __P((int)); 310 #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \ 311 defined(_NETBSD_SOURCE) 312 int getaddrinfo __P((const char *, const char *, 313 const struct addrinfo *, struct addrinfo **)); 314 int getnameinfo __P((const struct sockaddr *, socklen_t, char *, 315 socklen_t, char *, socklen_t, int)); 316 void freeaddrinfo __P((struct addrinfo *)); 317 char *gai_strerror __P((int)); 318 #endif 319 void setservent __P((int)); 320 __END_DECLS 321 322 #endif /* !_NETDB_H_ */ 323