netdb.h revision 72510
11539Srgrimes/*- 21539Srgrimes * Copyright (c) 1980, 1983, 1988, 1993 31539Srgrimes * The Regents of the University of California. All rights reserved. 41539Srgrimes * 51539Srgrimes * Redistribution and use in source and binary forms, with or without 61539Srgrimes * modification, are permitted provided that the following conditions 71539Srgrimes * are met: 81539Srgrimes * 1. Redistributions of source code must retain the above copyright 91539Srgrimes * notice, this list of conditions and the following disclaimer. 101539Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111539Srgrimes * notice, this list of conditions and the following disclaimer in the 121539Srgrimes * documentation and/or other materials provided with the distribution. 131539Srgrimes * 3. All advertising materials mentioning features or use of this software 141539Srgrimes * must display the following acknowledgement: 151539Srgrimes * This product includes software developed by the University of 161539Srgrimes * California, Berkeley and its contributors. 171539Srgrimes * 4. Neither the name of the University nor the names of its contributors 181539Srgrimes * may be used to endorse or promote products derived from this software 191539Srgrimes * without specific prior written permission. 201539Srgrimes * 211539Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221539Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231539Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241539Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251539Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261539Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271539Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281539Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291539Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301539Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311539Srgrimes * SUCH DAMAGE. 321539Srgrimes * 331539Srgrimes * - 341539Srgrimes * Portions Copyright (c) 1993 by Digital Equipment Corporation. 358858Srgrimes * 361539Srgrimes * Permission to use, copy, modify, and distribute this software for any 371539Srgrimes * purpose with or without fee is hereby granted, provided that the above 381539Srgrimes * copyright notice and this permission notice appear in all copies, and that 391539Srgrimes * the name of Digital Equipment Corporation not be used in advertising or 401539Srgrimes * publicity pertaining to distribution of the document or software without 411539Srgrimes * specific, written prior permission. 428858Srgrimes * 431539Srgrimes * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL 441539Srgrimes * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 451539Srgrimes * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT 461539Srgrimes * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 471539Srgrimes * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 481539Srgrimes * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 491539Srgrimes * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 501539Srgrimes * SOFTWARE. 511539Srgrimes * - 521539Srgrimes * --Copyright-- 531539Srgrimes */ 541539Srgrimes 5536888Speter/* 5636888Speter * @(#)netdb.h 8.1 (Berkeley) 6/2/93 5736888Speter * From: Id: netdb.h,v 8.9 1996/11/19 08:39:29 vixie Exp $ 5850473Speter * $FreeBSD: head/include/netdb.h 72510 2001-02-15 10:35:55Z ume $ 5936888Speter */ 6036888Speter 611539Srgrimes#ifndef _NETDB_H_ 621539Srgrimes#define _NETDB_H_ 631539Srgrimes 6472510Sume#include <machine/ansi.h> 6521055Speter#include <sys/cdefs.h> 6621055Speter 6772510Sume#ifdef _BSD_SIZE_T_ 6872510Sumetypedef _BSD_SIZE_T_ size_t; 6972510Sume#undef _BSD_SIZE_T_ 7072510Sume#endif 7172510Sume 7236888Speter#ifndef _PATH_HEQUIV 7336888Speter# define _PATH_HEQUIV "/etc/hosts.equiv" 7436888Speter#endif 751539Srgrimes#define _PATH_HOSTS "/etc/hosts" 761539Srgrimes#define _PATH_NETWORKS "/etc/networks" 771539Srgrimes#define _PATH_PROTOCOLS "/etc/protocols" 781539Srgrimes#define _PATH_SERVICES "/etc/services" 791539Srgrimes 8010132Speterextern int h_errno; 8110132Speter 821539Srgrimes/* 831539Srgrimes * Structures returned by network data base library. All addresses are 841539Srgrimes * supplied in host order, and returned in network order (suitable for 851539Srgrimes * use in system calls). 861539Srgrimes */ 871539Srgrimesstruct hostent { 881539Srgrimes char *h_name; /* official name of host */ 891539Srgrimes char **h_aliases; /* alias list */ 901539Srgrimes int h_addrtype; /* host address type */ 911539Srgrimes int h_length; /* length of address */ 921539Srgrimes char **h_addr_list; /* list of addresses from name server */ 9313771Smpp#define h_addr h_addr_list[0] /* address, for backward compatibility */ 941539Srgrimes}; 951539Srgrimes 961539Srgrimes/* 971539Srgrimes * Assumption here is that a network number 981539Srgrimes * fits in an unsigned long -- probably a poor one. 991539Srgrimes */ 1001539Srgrimesstruct netent { 1011539Srgrimes char *n_name; /* official name of net */ 1021539Srgrimes char **n_aliases; /* alias list */ 1031539Srgrimes int n_addrtype; /* net address type */ 1041539Srgrimes unsigned long n_net; /* network # */ 1051539Srgrimes}; 1061539Srgrimes 1071539Srgrimesstruct servent { 1081539Srgrimes char *s_name; /* official service name */ 1091539Srgrimes char **s_aliases; /* alias list */ 1101539Srgrimes int s_port; /* port # */ 1111539Srgrimes char *s_proto; /* protocol to use */ 1121539Srgrimes}; 1131539Srgrimes 1141539Srgrimesstruct protoent { 1151539Srgrimes char *p_name; /* official protocol name */ 1161539Srgrimes char **p_aliases; /* alias list */ 1171539Srgrimes int p_proto; /* protocol # */ 1181539Srgrimes}; 1191539Srgrimes 12055163Sshinstruct addrinfo { 12155163Sshin int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */ 12255163Sshin int ai_family; /* PF_xxx */ 12355163Sshin int ai_socktype; /* SOCK_xxx */ 12455163Sshin int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ 12555163Sshin size_t ai_addrlen; /* length of ai_addr */ 12655163Sshin char *ai_canonname; /* canonical name for hostname */ 12755163Sshin struct sockaddr *ai_addr; /* binary address */ 12855163Sshin struct addrinfo *ai_next; /* next structure in linked list */ 12955163Sshin}; 13055163Sshin 1311539Srgrimes/* 1321539Srgrimes * Error return codes from gethostbyname() and gethostbyaddr() 1331539Srgrimes * (left in extern int h_errno). 1341539Srgrimes */ 1351539Srgrimes 13610132Speter#define NETDB_INTERNAL -1 /* see errno */ 13710132Speter#define NETDB_SUCCESS 0 /* no problem */ 1381539Srgrimes#define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */ 13913771Smpp#define TRY_AGAIN 2 /* Non-Authoritative Host not found, or SERVERFAIL */ 1401539Srgrimes#define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ 1411539Srgrimes#define NO_DATA 4 /* Valid name, no data record of requested type */ 1421539Srgrimes#define NO_ADDRESS NO_DATA /* no address, look for MX record */ 1431539Srgrimes 14455163Sshin/* 14555163Sshin * Error return codes from getaddrinfo() 14655163Sshin */ 14755163Sshin#define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ 14855163Sshin#define EAI_AGAIN 2 /* temporary failure in name resolution */ 14955163Sshin#define EAI_BADFLAGS 3 /* invalid value for ai_flags */ 15055163Sshin#define EAI_FAIL 4 /* non-recoverable failure in name resolution */ 15155163Sshin#define EAI_FAMILY 5 /* ai_family not supported */ 15255163Sshin#define EAI_MEMORY 6 /* memory allocation failure */ 15355163Sshin#define EAI_NODATA 7 /* no address associated with hostname */ 15455163Sshin#define EAI_NONAME 8 /* hostname nor servname provided, or not known */ 15555163Sshin#define EAI_SERVICE 9 /* servname not supported for ai_socktype */ 15655163Sshin#define EAI_SOCKTYPE 10 /* ai_socktype not supported */ 15755163Sshin#define EAI_SYSTEM 11 /* system error returned in errno */ 15855163Sshin#define EAI_BADHINTS 12 15955163Sshin#define EAI_PROTOCOL 13 16055163Sshin#define EAI_RESNULL 14 16155163Sshin#define EAI_MAX 15 16255163Sshin 16355163Sshin/* 16455163Sshin * Flag values for getaddrinfo() 16555163Sshin */ 16655163Sshin#define AI_PASSIVE 0x00000001 /* get address to use bind() */ 16755163Sshin#define AI_CANONNAME 0x00000002 /* fill ai_canonname */ 16855163Sshin#define AI_NUMERICHOST 0x00000004 /* prevent name resolution */ 16955163Sshin/* valid flags for addrinfo */ 17055163Sshin#define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST) 17155163Sshin 17255163Sshin#define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */ 17355163Sshin#define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */ 17455163Sshin#define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */ 17555163Sshin#define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */ 17655163Sshin/* special recommended flags for getipnodebyname */ 17755163Sshin#define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG) 17855163Sshin 17955163Sshin/* 18055163Sshin * Constants for getnameinfo() 18155163Sshin */ 18255163Sshin#define NI_MAXHOST 1025 18355163Sshin#define NI_MAXSERV 32 18455163Sshin 18555163Sshin/* 18655163Sshin * Flag values for getnameinfo() 18755163Sshin */ 18855163Sshin#define NI_NOFQDN 0x00000001 18955163Sshin#define NI_NUMERICHOST 0x00000002 19055163Sshin#define NI_NAMEREQD 0x00000004 19155163Sshin#define NI_NUMERICSERV 0x00000008 19255163Sshin#define NI_DGRAM 0x00000010 19355163Sshin#define NI_WITHSCOPEID 0x00000020 19455163Sshin 19555163Sshin/* 19655163Sshin * Scope delimit character 19755163Sshin */ 19857033Sshin#define SCOPE_DELIMITER '%' 19955163Sshin 20072510Sume/* 20172510Sume * data types - basically forward decl for getnameinfo() 20272510Sume */ 20372510Sume#ifdef _BSD_SOCKLEN_T_ 20472510Sumetypedef _BSD_SOCKLEN_T_ socklen_t; 20572510Sume#undef _BSD_SOCKLEN_T_ 20672510Sume#endif 20772510Sume 2081539Srgrimes__BEGIN_DECLS 2091539Srgrimesvoid endhostent __P((void)); 2101539Srgrimesvoid endnetent __P((void)); 2111539Srgrimesvoid endprotoent __P((void)); 2121539Srgrimesvoid endservent __P((void)); 21355163Sshinvoid freehostent __P((struct hostent *)); 2141539Srgrimesstruct hostent *gethostbyaddr __P((const char *, int, int)); 2151539Srgrimesstruct hostent *gethostbyname __P((const char *)); 21617902Speterstruct hostent *gethostbyname2 __P((const char *, int)); 2171539Srgrimesstruct hostent *gethostent __P((void)); 21855163Sshinstruct hostent *getipnodebyaddr __P((const void *, size_t, int, int *)); 21955163Sshinstruct hostent *getipnodebyname __P((const char *, int, int, int *)); 22021055Speterstruct netent *getnetbyaddr __P((unsigned long, int)); 2211539Srgrimesstruct netent *getnetbyname __P((const char *)); 2221539Srgrimesstruct netent *getnetent __P((void)); 2231539Srgrimesstruct protoent *getprotobyname __P((const char *)); 2241539Srgrimesstruct protoent *getprotobynumber __P((int)); 2251539Srgrimesstruct protoent *getprotoent __P((void)); 2261539Srgrimesstruct servent *getservbyname __P((const char *, const char *)); 2271539Srgrimesstruct servent *getservbyport __P((int, const char *)); 2281539Srgrimesstruct servent *getservent __P((void)); 2291539Srgrimesvoid herror __P((const char *)); 23028271Ssteve__const char *hstrerror __P((int)); 2311539Srgrimesvoid sethostent __P((int)); 2321539Srgrimes/* void sethostfile __P((const char *)); */ 2331539Srgrimesvoid setnetent __P((int)); 2341539Srgrimesvoid setprotoent __P((int)); 23555163Sshinint getaddrinfo __P((const char *, const char *, 23655163Sshin const struct addrinfo *, struct addrinfo **)); 23772510Sumeint getnameinfo __P((const struct sockaddr *, socklen_t, char *, 23855163Sshin size_t, char *, size_t, int)); 23955163Sshinvoid freeaddrinfo __P((struct addrinfo *)); 24055163Sshinchar *gai_strerror __P((int)); 2411539Srgrimesvoid setservent __P((int)); 24217902Speter 24317902Speter/* 24417902Speter * PRIVATE functions specific to the FreeBSD implementation 24517902Speter */ 24617902Speter 24717902Speter/* DO NOT USE THESE, THEY ARE SUBJECT TO CHANGE AND ARE NOT PORTABLE!!! */ 24817902Spetervoid _sethosthtent __P((int)); 24917902Spetervoid _endhosthtent __P((void)); 25017902Spetervoid _sethostdnsent __P((int)); 25117902Spetervoid _endhostdnsent __P((void)); 25217902Spetervoid _setnethtent __P((int)); 25317902Spetervoid _endnethtent __P((void)); 25417902Spetervoid _setnetdnsent __P((int)); 25517902Spetervoid _endnetdnsent __P((void)); 25617902Speterstruct hostent * _gethostbynisname __P((const char *, int)); 25717902Speterstruct hostent * _gethostbynisaddr __P((const char *, int, int)); 25817902Spetervoid _map_v4v6_address __P((const char *src, char *dst)); 25917902Spetervoid _map_v4v6_hostent __P((struct hostent *hp, char **bp, int *len)); 2601539Srgrimes__END_DECLS 2611539Srgrimes 2621539Srgrimes#endif /* !_NETDB_H_ */ 263