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