netdb.h revision 80153
160812Sps/*- 260786Sps * Copyright (c) 1980, 1983, 1988, 1993 3170259Sdelphij * The Regents of the University of California. All rights reserved. 460786Sps * 560786Sps * Redistribution and use in source and binary forms, with or without 660786Sps * modification, are permitted provided that the following conditions 760786Sps * are met: 860786Sps * 1. Redistributions of source code must retain the above copyright 960786Sps * notice, this list of conditions and the following disclaimer. 1060786Sps * 2. Redistributions in binary form must reproduce the above copyright 1160786Sps * notice, this list of conditions and the following disclaimer in the 1260786Sps * documentation and/or other materials provided with the distribution. 1360786Sps * 3. All advertising materials mentioning features or use of this software 1460786Sps * must display the following acknowledgement: 1560786Sps * This product includes software developed by the University of 1660786Sps * California, Berkeley and its contributors. 1760786Sps * 4. Neither the name of the University nor the names of its contributors 1860786Sps * may be used to endorse or promote products derived from this software 1960786Sps * without specific prior written permission. 2060786Sps * 2160786Sps * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2260786Sps * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2360786Sps * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2460786Sps * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2560786Sps * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2660786Sps * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2760786Sps * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2860786Sps * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2960786Sps * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3060786Sps * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3160786Sps * SUCH DAMAGE. 3260786Sps * 3360786Sps * - 3460786Sps * Portions Copyright (c) 1993 by Digital Equipment Corporation. 3560786Sps * 3660786Sps * Permission to use, copy, modify, and distribute this software for any 3760786Sps * purpose with or without fee is hereby granted, provided that the above 3860786Sps * copyright notice and this permission notice appear in all copies, and that 3960786Sps * the name of Digital Equipment Corporation not be used in advertising or 4060786Sps * publicity pertaining to distribution of the document or software without 4160786Sps * specific, written prior permission. 42161478Sdelphij * 43161478Sdelphij * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL 44161478Sdelphij * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 45161478Sdelphij * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT 4660786Sps * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 4760786Sps * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 4860786Sps * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 4960786Sps * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 5060786Sps * SOFTWARE. 5160786Sps * - 5260786Sps * --Copyright-- 5360786Sps */ 5460786Sps 5560786Sps/* 5660786Sps * @(#)netdb.h 8.1 (Berkeley) 6/2/93 5760786Sps * From: Id: netdb.h,v 8.9 1996/11/19 08:39:29 vixie Exp $ 5860786Sps * $FreeBSD: head/include/netdb.h 80153 2001-07-22 18:10:08Z mike $ 5960786Sps */ 6060786Sps 6160786Sps#ifndef _NETDB_H_ 6260786Sps#define _NETDB_H_ 6360786Sps 6460786Sps#include <machine/ansi.h> 6560786Sps#include <sys/cdefs.h> 6660786Sps 6760786Sps#ifdef _BSD_SIZE_T_ 6889022Spstypedef _BSD_SIZE_T_ size_t; 6960786Sps#undef _BSD_SIZE_T_ 7060786Sps#endif 7160786Sps 7260786Sps#ifndef _PATH_HEQUIV 7360786Sps# define _PATH_HEQUIV "/etc/hosts.equiv" 7460786Sps#endif 7560786Sps#define _PATH_HOSTS "/etc/hosts" 7660786Sps#define _PATH_NETWORKS "/etc/networks" 7760786Sps#define _PATH_PROTOCOLS "/etc/protocols" 7860786Sps#define _PATH_SERVICES "/etc/services" 7960786Sps 8060786Spsextern int h_errno; 8160786Sps 8260786Sps/* 8360786Sps * Structures returned by network data base library. All addresses are 8460786Sps * supplied in host order, and returned in network order (suitable for 8560786Sps * use in system calls). 8660786Sps */ 8760786Spsstruct hostent { 8860786Sps char *h_name; /* official name of host */ 8960786Sps char **h_aliases; /* alias list */ 9060786Sps int h_addrtype; /* host address type */ 9189022Sps int h_length; /* length of address */ 9260786Sps char **h_addr_list; /* list of addresses from name server */ 9360786Sps#define h_addr h_addr_list[0] /* address, for backward compatibility */ 9460786Sps}; 9560786Sps 9660786Sps/* 9760786Sps * Assumption here is that a network number 9860786Sps * fits in an unsigned long -- probably a poor one. 9960786Sps */ 10060786Spsstruct netent { 10160786Sps char *n_name; /* official name of net */ 10260786Sps char **n_aliases; /* alias list */ 10360786Sps int n_addrtype; /* net address type */ 10460786Sps unsigned long n_net; /* network # */ 10560786Sps}; 10660786Sps 10760786Spsstruct servent { 10860786Sps char *s_name; /* official service name */ 10960786Sps char **s_aliases; /* alias list */ 11060786Sps int s_port; /* port # */ 11160786Sps char *s_proto; /* protocol to use */ 11260786Sps}; 11360786Sps 11460786Spsstruct protoent { 11560786Sps char *p_name; /* official protocol name */ 11660786Sps char **p_aliases; /* alias list */ 11760786Sps int p_proto; /* protocol # */ 11860786Sps}; 11960786Sps 12060786Spsstruct addrinfo { 12160786Sps int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */ 12260786Sps int ai_family; /* PF_xxx */ 12360786Sps int ai_socktype; /* SOCK_xxx */ 12460786Sps int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ 12560786Sps size_t ai_addrlen; /* length of ai_addr */ 12660786Sps char *ai_canonname; /* canonical name for hostname */ 12760786Sps struct sockaddr *ai_addr; /* binary address */ 12860786Sps struct addrinfo *ai_next; /* next structure in linked list */ 12960786Sps}; 13060786Sps 13160786Sps/* 13260786Sps * Error return codes from gethostbyname() and gethostbyaddr() 13360786Sps * (left in extern int h_errno). 13460786Sps */ 13560786Sps 13660786Sps#define NETDB_INTERNAL -1 /* see errno */ 13760786Sps#define NETDB_SUCCESS 0 /* no problem */ 13860786Sps#define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */ 13960786Sps#define TRY_AGAIN 2 /* Non-Authoritative Host not found, or SERVERFAIL */ 14060786Sps#define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ 14160786Sps#define NO_DATA 4 /* Valid name, no data record of requested type */ 14260786Sps#define NO_ADDRESS NO_DATA /* no address, look for MX record */ 14360786Sps 14460786Sps/* 14560786Sps * Error return codes from getaddrinfo() 14660786Sps */ 14760786Sps#define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ 14860786Sps#define EAI_AGAIN 2 /* temporary failure in name resolution */ 14960786Sps#define EAI_BADFLAGS 3 /* invalid value for ai_flags */ 15060786Sps#define EAI_FAIL 4 /* non-recoverable failure in name resolution */ 15160786Sps#define EAI_FAMILY 5 /* ai_family not supported */ 15260786Sps#define EAI_MEMORY 6 /* memory allocation failure */ 15360786Sps#define EAI_NODATA 7 /* no address associated with hostname */ 15460786Sps#define EAI_NONAME 8 /* hostname nor servname provided, or not known */ 15560786Sps#define EAI_SERVICE 9 /* servname not supported for ai_socktype */ 15660786Sps#define EAI_SOCKTYPE 10 /* ai_socktype not supported */ 15760786Sps#define EAI_SYSTEM 11 /* system error returned in errno */ 15860786Sps#define EAI_BADHINTS 12 15960786Sps#define EAI_PROTOCOL 13 16060786Sps#define EAI_MAX 14 16160786Sps 16260786Sps/* 16360786Sps * Flag values for getaddrinfo() 16460786Sps */ 16560786Sps#define AI_PASSIVE 0x00000001 /* get address to use bind() */ 16660786Sps#define AI_CANONNAME 0x00000002 /* fill ai_canonname */ 167170259Sdelphij#define AI_NUMERICHOST 0x00000004 /* prevent name resolution */ 16860786Sps/* valid flags for addrinfo */ 16960786Sps#define AI_MASK \ 17060786Sps (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_ADDRCONFIG) 17160786Sps 17260786Sps#define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */ 17360786Sps#define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */ 17460786Sps#define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */ 17560786Sps#define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */ 17660786Sps/* special recommended flags for getipnodebyname */ 17760786Sps#define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG) 17860786Sps 17960786Sps/* 18060786Sps * Constants for getnameinfo() 18160786Sps */ 18260786Sps#define NI_MAXHOST 1025 18360786Sps#define NI_MAXSERV 32 18460786Sps 18560786Sps/* 18660786Sps * Flag values for getnameinfo() 18760786Sps */ 18860786Sps#define NI_NOFQDN 0x00000001 18960786Sps#define NI_NUMERICHOST 0x00000002 19060786Sps#define NI_NAMEREQD 0x00000004 19160786Sps#define NI_NUMERICSERV 0x00000008 192161478Sdelphij#define NI_DGRAM 0x00000010 193161478Sdelphij#define NI_WITHSCOPEID 0x00000020 194161478Sdelphij 19560786Sps/* 19660786Sps * Scope delimit character 19760786Sps */ 19860786Sps#define SCOPE_DELIMITER '%' 19960786Sps 20060786Sps/* 20160786Sps * data types - basically forward decl for getnameinfo() 20260786Sps */ 20360786Sps#ifdef _BSD_SOCKLEN_T_ 20460786Spstypedef _BSD_SOCKLEN_T_ socklen_t; 20560786Sps#undef _BSD_SOCKLEN_T_ 20660786Sps#endif 207161478Sdelphij 20860786Sps__BEGIN_DECLS 20960786Spsvoid endhostent __P((void)); 21060786Spsvoid endnetent __P((void)); 21160786Spsvoid endnetgrent __P((void)); 21260786Spsvoid endprotoent __P((void)); 21360786Spsvoid endservent __P((void)); 21460786Spsvoid freehostent __P((struct hostent *)); 21560786Spsstruct hostent *gethostbyaddr __P((const char *, int, int)); 21660786Spsstruct hostent *gethostbyname __P((const char *)); 21760786Spsstruct hostent *gethostbyname2 __P((const char *, int)); 21860786Spsstruct hostent *gethostent __P((void)); 21960786Spsstruct hostent *getipnodebyaddr __P((const void *, size_t, int, int *)); 22060786Spsstruct hostent *getipnodebyname __P((const char *, int, int, int *)); 22160786Spsstruct netent *getnetbyaddr __P((unsigned long, int)); 22260786Spsstruct netent *getnetbyname __P((const char *)); 22360786Spsstruct netent *getnetent __P((void)); 22460786Spsint getnetgrent __P((char **, char **, char **)); 22560786Spsstruct protoent *getprotobyname __P((const char *)); 22660786Spsstruct protoent *getprotobynumber __P((int)); 22760786Spsstruct protoent *getprotoent __P((void)); 22860786Spsstruct servent *getservbyname __P((const char *, const char *)); 22960786Spsstruct servent *getservbyport __P((int, const char *)); 23060786Spsstruct servent *getservent __P((void)); 23160812Spsvoid herror __P((const char *)); 232170259Sdelphij__const char *hstrerror __P((int)); 23389022Spsint innetgr __P((const char *, const char *, const char *, 23460786Sps const char *)); 23560786Spsvoid sethostent __P((int)); 23660786Sps/* void sethostfile __P((const char *)); */ 237128348Stjrvoid setnetent __P((int)); 238161478Sdelphijvoid setprotoent __P((int)); 239170259Sdelphijint getaddrinfo __P((const char *, const char *, 24060786Sps const struct addrinfo *, struct addrinfo **)); 24160786Spsint getnameinfo __P((const struct sockaddr *, socklen_t, char *, 24260786Sps size_t, char *, size_t, int)); 24360786Spsvoid freeaddrinfo __P((struct addrinfo *)); 24460786Spschar *gai_strerror __P((int)); 24560786Spsvoid setnetgrent __P((const char *)); 24660786Spsvoid setservent __P((int)); 24760786Sps 24860786Sps/* 24960786Sps * PRIVATE functions specific to the FreeBSD implementation 25060786Sps */ 25160786Sps 25260786Sps/* DO NOT USE THESE, THEY ARE SUBJECT TO CHANGE AND ARE NOT PORTABLE!!! */ 25360786Spsvoid _sethosthtent __P((int)); 25460786Spsvoid _endhosthtent __P((void)); 25560786Spsvoid _sethostdnsent __P((int)); 25660786Spsvoid _endhostdnsent __P((void)); 25760786Spsvoid _setnethtent __P((int)); 25860786Spsvoid _endnethtent __P((void)); 25960786Spsvoid _setnetdnsent __P((int)); 26060786Spsvoid _endnetdnsent __P((void)); 26160786Spsstruct hostent * _gethostbynisname __P((const char *, int)); 26260786Spsstruct hostent * _gethostbynisaddr __P((const char *, int, int)); 26360786Spsvoid _map_v4v6_address __P((const char *, char *)); 26460786Spsvoid _map_v4v6_hostent __P((struct hostent *, char **, int *)); 26560786Sps__END_DECLS 26660786Sps 267161478Sdelphij#endif /* !_NETDB_H_ */ 26860786Sps