netdb.h revision 55163
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 55163 1999-12-28 02:37:14Z shin $ 5936888Speter */ 6036888Speter 611539Srgrimes#ifndef _NETDB_H_ 621539Srgrimes#define _NETDB_H_ 631539Srgrimes 6421055Speter#include <sys/cdefs.h> 6555163Sshin#include <sys/types.h> 6621055Speter 6736888Speter#ifndef _PATH_HEQUIV 6836888Speter# define _PATH_HEQUIV "/etc/hosts.equiv" 6936888Speter#endif 701539Srgrimes#define _PATH_HOSTS "/etc/hosts" 711539Srgrimes#define _PATH_NETWORKS "/etc/networks" 721539Srgrimes#define _PATH_PROTOCOLS "/etc/protocols" 731539Srgrimes#define _PATH_SERVICES "/etc/services" 741539Srgrimes 7510132Speterextern int h_errno; 7610132Speter 771539Srgrimes/* 781539Srgrimes * Structures returned by network data base library. All addresses are 791539Srgrimes * supplied in host order, and returned in network order (suitable for 801539Srgrimes * use in system calls). 811539Srgrimes */ 821539Srgrimesstruct hostent { 831539Srgrimes char *h_name; /* official name of host */ 841539Srgrimes char **h_aliases; /* alias list */ 851539Srgrimes int h_addrtype; /* host address type */ 861539Srgrimes int h_length; /* length of address */ 871539Srgrimes char **h_addr_list; /* list of addresses from name server */ 8813771Smpp#define h_addr h_addr_list[0] /* address, for backward compatibility */ 891539Srgrimes}; 901539Srgrimes 911539Srgrimes/* 921539Srgrimes * Assumption here is that a network number 931539Srgrimes * fits in an unsigned long -- probably a poor one. 941539Srgrimes */ 951539Srgrimesstruct netent { 961539Srgrimes char *n_name; /* official name of net */ 971539Srgrimes char **n_aliases; /* alias list */ 981539Srgrimes int n_addrtype; /* net address type */ 991539Srgrimes unsigned long n_net; /* network # */ 1001539Srgrimes}; 1011539Srgrimes 1021539Srgrimesstruct servent { 1031539Srgrimes char *s_name; /* official service name */ 1041539Srgrimes char **s_aliases; /* alias list */ 1051539Srgrimes int s_port; /* port # */ 1061539Srgrimes char *s_proto; /* protocol to use */ 1071539Srgrimes}; 1081539Srgrimes 1091539Srgrimesstruct protoent { 1101539Srgrimes char *p_name; /* official protocol name */ 1111539Srgrimes char **p_aliases; /* alias list */ 1121539Srgrimes int p_proto; /* protocol # */ 1131539Srgrimes}; 1141539Srgrimes 11555163Sshinstruct addrinfo { 11655163Sshin int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */ 11755163Sshin int ai_family; /* PF_xxx */ 11855163Sshin int ai_socktype; /* SOCK_xxx */ 11955163Sshin int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ 12055163Sshin size_t ai_addrlen; /* length of ai_addr */ 12155163Sshin char *ai_canonname; /* canonical name for hostname */ 12255163Sshin struct sockaddr *ai_addr; /* binary address */ 12355163Sshin struct addrinfo *ai_next; /* next structure in linked list */ 12455163Sshin}; 12555163Sshin 1261539Srgrimes/* 1271539Srgrimes * Error return codes from gethostbyname() and gethostbyaddr() 1281539Srgrimes * (left in extern int h_errno). 1291539Srgrimes */ 1301539Srgrimes 13110132Speter#define NETDB_INTERNAL -1 /* see errno */ 13210132Speter#define NETDB_SUCCESS 0 /* no problem */ 1331539Srgrimes#define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */ 13413771Smpp#define TRY_AGAIN 2 /* Non-Authoritative Host not found, or SERVERFAIL */ 1351539Srgrimes#define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ 1361539Srgrimes#define NO_DATA 4 /* Valid name, no data record of requested type */ 1371539Srgrimes#define NO_ADDRESS NO_DATA /* no address, look for MX record */ 1381539Srgrimes 13955163Sshin/* 14055163Sshin * Error return codes from getaddrinfo() 14155163Sshin */ 14255163Sshin#define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ 14355163Sshin#define EAI_AGAIN 2 /* temporary failure in name resolution */ 14455163Sshin#define EAI_BADFLAGS 3 /* invalid value for ai_flags */ 14555163Sshin#define EAI_FAIL 4 /* non-recoverable failure in name resolution */ 14655163Sshin#define EAI_FAMILY 5 /* ai_family not supported */ 14755163Sshin#define EAI_MEMORY 6 /* memory allocation failure */ 14855163Sshin#define EAI_NODATA 7 /* no address associated with hostname */ 14955163Sshin#define EAI_NONAME 8 /* hostname nor servname provided, or not known */ 15055163Sshin#define EAI_SERVICE 9 /* servname not supported for ai_socktype */ 15155163Sshin#define EAI_SOCKTYPE 10 /* ai_socktype not supported */ 15255163Sshin#define EAI_SYSTEM 11 /* system error returned in errno */ 15355163Sshin#define EAI_BADHINTS 12 15455163Sshin#define EAI_PROTOCOL 13 15555163Sshin#define EAI_RESNULL 14 15655163Sshin#define EAI_MAX 15 15755163Sshin 15855163Sshin/* 15955163Sshin * Flag values for getaddrinfo() 16055163Sshin */ 16155163Sshin#define AI_PASSIVE 0x00000001 /* get address to use bind() */ 16255163Sshin#define AI_CANONNAME 0x00000002 /* fill ai_canonname */ 16355163Sshin#define AI_NUMERICHOST 0x00000004 /* prevent name resolution */ 16455163Sshin/* valid flags for addrinfo */ 16555163Sshin#define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST) 16655163Sshin 16755163Sshin#define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */ 16855163Sshin#define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */ 16955163Sshin#define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */ 17055163Sshin#define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */ 17155163Sshin/* special recommended flags for getipnodebyname */ 17255163Sshin#define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG) 17355163Sshin 17455163Sshin/* 17555163Sshin * Constants for getnameinfo() 17655163Sshin */ 17755163Sshin#define NI_MAXHOST 1025 17855163Sshin#define NI_MAXSERV 32 17955163Sshin 18055163Sshin/* 18155163Sshin * Flag values for getnameinfo() 18255163Sshin */ 18355163Sshin#define NI_NOFQDN 0x00000001 18455163Sshin#define NI_NUMERICHOST 0x00000002 18555163Sshin#define NI_NAMEREQD 0x00000004 18655163Sshin#define NI_NUMERICSERV 0x00000008 18755163Sshin#define NI_DGRAM 0x00000010 18855163Sshin#define NI_WITHSCOPEID 0x00000020 18955163Sshin 19055163Sshin/* 19155163Sshin * Scope delimit character 19255163Sshin */ 19355163Sshin#define SCOPE_DELIMITER '@' 19455163Sshin 1951539Srgrimes__BEGIN_DECLS 1961539Srgrimesvoid endhostent __P((void)); 1971539Srgrimesvoid endnetent __P((void)); 1981539Srgrimesvoid endprotoent __P((void)); 1991539Srgrimesvoid endservent __P((void)); 20055163Sshinvoid freehostent __P((struct hostent *)); 2011539Srgrimesstruct hostent *gethostbyaddr __P((const char *, int, int)); 2021539Srgrimesstruct hostent *gethostbyname __P((const char *)); 20317902Speterstruct hostent *gethostbyname2 __P((const char *, int)); 2041539Srgrimesstruct hostent *gethostent __P((void)); 20555163Sshinstruct hostent *getipnodebyaddr __P((const void *, size_t, int, int *)); 20655163Sshinstruct hostent *getipnodebyname __P((const char *, int, int, int *)); 20721055Speterstruct netent *getnetbyaddr __P((unsigned long, int)); 2081539Srgrimesstruct netent *getnetbyname __P((const char *)); 2091539Srgrimesstruct netent *getnetent __P((void)); 2101539Srgrimesstruct protoent *getprotobyname __P((const char *)); 2111539Srgrimesstruct protoent *getprotobynumber __P((int)); 2121539Srgrimesstruct protoent *getprotoent __P((void)); 2131539Srgrimesstruct servent *getservbyname __P((const char *, const char *)); 2141539Srgrimesstruct servent *getservbyport __P((int, const char *)); 2151539Srgrimesstruct servent *getservent __P((void)); 2161539Srgrimesvoid herror __P((const char *)); 21728271Ssteve__const char *hstrerror __P((int)); 2181539Srgrimesvoid sethostent __P((int)); 2191539Srgrimes/* void sethostfile __P((const char *)); */ 2201539Srgrimesvoid setnetent __P((int)); 2211539Srgrimesvoid setprotoent __P((int)); 22255163Sshinint getaddrinfo __P((const char *, const char *, 22355163Sshin const struct addrinfo *, struct addrinfo **)); 22455163Sshinint getnameinfo __P((const struct sockaddr *, size_t, char *, 22555163Sshin size_t, char *, size_t, int)); 22655163Sshinvoid freeaddrinfo __P((struct addrinfo *)); 22755163Sshinchar *gai_strerror __P((int)); 2281539Srgrimesvoid setservent __P((int)); 22917902Speter 23017902Speter/* 23117902Speter * PRIVATE functions specific to the FreeBSD implementation 23217902Speter */ 23317902Speter 23417902Speter/* DO NOT USE THESE, THEY ARE SUBJECT TO CHANGE AND ARE NOT PORTABLE!!! */ 23517902Spetervoid _sethosthtent __P((int)); 23617902Spetervoid _endhosthtent __P((void)); 23717902Spetervoid _sethostdnsent __P((int)); 23817902Spetervoid _endhostdnsent __P((void)); 23917902Spetervoid _setnethtent __P((int)); 24017902Spetervoid _endnethtent __P((void)); 24117902Spetervoid _setnetdnsent __P((int)); 24217902Spetervoid _endnetdnsent __P((void)); 24317902Speterstruct hostent * _gethostbyhtname __P((const char *, int)); 24417902Speterstruct hostent * _gethostbydnsname __P((const char *, int)); 24517902Speterstruct hostent * _gethostbynisname __P((const char *, int)); 24617902Speterstruct hostent * _gethostbyhtaddr __P((const char *, int, int)); 24717902Speterstruct hostent * _gethostbydnsaddr __P((const char *, int, int)); 24817902Speterstruct hostent * _gethostbynisaddr __P((const char *, int, int)); 24917902Speterstruct netent * _getnetbyhtname __P((const char *)); 25017902Speterstruct netent * _getnetbydnsname __P((const char *)); 25117902Speterstruct netent * _getnetbynisname __P((const char *)); 25217902Speterstruct netent * _getnetbyhtaddr __P((unsigned long, int)); 25317902Speterstruct netent * _getnetbydnsaddr __P((unsigned long, int)); 25417902Speterstruct netent * _getnetbynisaddr __P((unsigned long, int)); 25517902Spetervoid _map_v4v6_address __P((const char *src, char *dst)); 25617902Spetervoid _map_v4v6_hostent __P((struct hostent *hp, char **bp, int *len)); 2571539Srgrimes__END_DECLS 2581539Srgrimes 2591539Srgrimes#endif /* !_NETDB_H_ */ 260