netdb.h revision 156960
1254721Semaste/*- 2254721Semaste * Copyright (c) 1980, 1983, 1988, 1993 3254721Semaste * The Regents of the University of California. All rights reserved. 4254721Semaste * 5254721Semaste * Redistribution and use in source and binary forms, with or without 6254721Semaste * modification, are permitted provided that the following conditions 7254721Semaste * are met: 8254721Semaste * 1. Redistributions of source code must retain the above copyright 9254721Semaste * notice, this list of conditions and the following disclaimer. 10254721Semaste * 2. Redistributions in binary form must reproduce the above copyright 11254721Semaste * notice, this list of conditions and the following disclaimer in the 12254721Semaste * documentation and/or other materials provided with the distribution. 13254721Semaste * 3. All advertising materials mentioning features or use of this software 14254721Semaste * must display the following acknowledgement: 15254721Semaste * This product includes software developed by the University of 16254721Semaste * California, Berkeley and its contributors. 17254721Semaste * 4. Neither the name of the University nor the names of its contributors 18254721Semaste * may be used to endorse or promote products derived from this software 19254721Semaste * without specific prior written permission. 20254721Semaste * 21254721Semaste * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22254721Semaste * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23254721Semaste * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24254721Semaste * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25254721Semaste * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26254721Semaste * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27254721Semaste * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28254721Semaste * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29254721Semaste * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30254721Semaste * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31254721Semaste * SUCH DAMAGE. 32254721Semaste * 33254721Semaste * - 34254721Semaste * Portions Copyright (c) 1993 by Digital Equipment Corporation. 35254721Semaste * 36254721Semaste * Permission to use, copy, modify, and distribute this software for any 37254721Semaste * purpose with or without fee is hereby granted, provided that the above 38254721Semaste * copyright notice and this permission notice appear in all copies, and that 39254721Semaste * the name of Digital Equipment Corporation not be used in advertising or 40254721Semaste * publicity pertaining to distribution of the document or software without 41254721Semaste * specific, written prior permission. 42254721Semaste * 43254721Semaste * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL 44254721Semaste * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 45254721Semaste * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT 46254721Semaste * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 47254721Semaste * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 48254721Semaste * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 49254721Semaste * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 50254721Semaste * SOFTWARE. 51254721Semaste * - 52254721Semaste * --Copyright-- 53254721Semaste */ 54254721Semaste 55254721Semaste/* 56254721Semaste * @(#)netdb.h 8.1 (Berkeley) 6/2/93 57254721Semaste * From: Id: netdb.h,v 8.9 1996/11/19 08:39:29 vixie Exp $ 58254721Semaste * $FreeBSD: head/include/netdb.h 156960 2006-03-21 16:11:11Z ume $ 59254721Semaste */ 60254721Semaste 61254721Semaste#ifndef _NETDB_H_ 62254721Semaste#define _NETDB_H_ 63254721Semaste 64254721Semaste#include <sys/cdefs.h> 65254721Semaste#include <sys/_types.h> 66254721Semaste 67254721Semaste#ifndef _SIZE_T_DECLARED 68254721Semastetypedef __size_t size_t; 69254721Semaste#define _SIZE_T_DECLARED 70254721Semaste#endif 71254721Semaste 72254721Semaste#ifndef _SOCKLEN_T_DECLARED 73254721Semastetypedef __socklen_t socklen_t; 74254721Semaste#define _SOCKLEN_T_DECLARED 75254721Semaste#endif 76254721Semaste 77254721Semaste#ifndef _UINT32_T_DECLARED 78254721Semastetypedef __uint32_t uint32_t; 79254721Semaste#define _UINT32_T_DECLARED 80254721Semaste#endif 81254721Semaste 82254721Semaste#ifndef _PATH_HEQUIV 83254721Semaste# define _PATH_HEQUIV "/etc/hosts.equiv" 84254721Semaste#endif 85254721Semaste#define _PATH_HOSTS "/etc/hosts" 86254721Semaste#define _PATH_NETWORKS "/etc/networks" 87254721Semaste#define _PATH_PROTOCOLS "/etc/protocols" 88254721Semaste#define _PATH_SERVICES "/etc/services" 89254721Semaste 90254721Semaste#define h_errno (*__h_errno()) 91254721Semaste 92254721Semaste/* 93254721Semaste * Structures returned by network data base library. All addresses are 94254721Semaste * supplied in host order, and returned in network order (suitable for 95254721Semaste * use in system calls). 96254721Semaste */ 97254721Semastestruct hostent { 98254721Semaste char *h_name; /* official name of host */ 99254721Semaste char **h_aliases; /* alias list */ 100254721Semaste int h_addrtype; /* host address type */ 101254721Semaste int h_length; /* length of address */ 102254721Semaste char **h_addr_list; /* list of addresses from name server */ 103254721Semaste#define h_addr h_addr_list[0] /* address, for backward compatibility */ 104254721Semaste}; 105254721Semaste 106254721Semastestruct netent { 107254721Semaste char *n_name; /* official name of net */ 108254721Semaste char **n_aliases; /* alias list */ 109254721Semaste int n_addrtype; /* net address type */ 110254721Semaste uint32_t n_net; /* network # */ 111254721Semaste}; 112254721Semaste 113254721Semastestruct servent { 114254721Semaste char *s_name; /* official service name */ 115254721Semaste char **s_aliases; /* alias list */ 116254721Semaste int s_port; /* port # */ 117254721Semaste char *s_proto; /* protocol to use */ 118254721Semaste}; 119254721Semaste 120254721Semastestruct protoent { 121254721Semaste char *p_name; /* official protocol name */ 122254721Semaste char **p_aliases; /* alias list */ 123254721Semaste int p_proto; /* protocol # */ 124254721Semaste}; 125254721Semaste 126254721Semastestruct addrinfo { 127254721Semaste int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */ 128254721Semaste int ai_family; /* PF_xxx */ 129254721Semaste int ai_socktype; /* SOCK_xxx */ 130254721Semaste int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ 131254721Semaste socklen_t ai_addrlen; /* length of ai_addr */ 132254721Semaste char *ai_canonname; /* canonical name for hostname */ 133254721Semaste struct sockaddr *ai_addr; /* binary address */ 134254721Semaste struct addrinfo *ai_next; /* next structure in linked list */ 135254721Semaste}; 136254721Semaste 137254721Semaste/* 138254721Semaste * Error return codes from gethostbyname() and gethostbyaddr() 139254721Semaste * (left in h_errno). 140254721Semaste */ 141254721Semaste 142254721Semaste#define NETDB_INTERNAL -1 /* see errno */ 143254721Semaste#define NETDB_SUCCESS 0 /* no problem */ 144254721Semaste#define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */ 145254721Semaste#define TRY_AGAIN 2 /* Non-Authoritative Host not found, or SERVERFAIL */ 146254721Semaste#define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ 147254721Semaste#define NO_DATA 4 /* Valid name, no data record of requested type */ 148254721Semaste#define NO_ADDRESS NO_DATA /* no address, look for MX record */ 149254721Semaste 150254721Semaste/* 151254721Semaste * Error return codes from getaddrinfo() 152254721Semaste */ 153254721Semaste#if 0 154254721Semaste/* obsoleted */ 155254721Semaste#define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ 156254721Semaste#endif 157254721Semaste#define EAI_AGAIN 2 /* temporary failure in name resolution */ 158254721Semaste#define EAI_BADFLAGS 3 /* invalid value for ai_flags */ 159254721Semaste#define EAI_FAIL 4 /* non-recoverable failure in name resolution */ 160254721Semaste#define EAI_FAMILY 5 /* ai_family not supported */ 161254721Semaste#define EAI_MEMORY 6 /* memory allocation failure */ 162254721Semaste#if 0 163254721Semaste/* obsoleted */ 164254721Semaste#define EAI_NODATA 7 /* no address associated with hostname */ 165254721Semaste#endif 166254721Semaste#define EAI_NONAME 8 /* hostname nor servname provided, or not known */ 167254721Semaste#define EAI_SERVICE 9 /* servname not supported for ai_socktype */ 168254721Semaste#define EAI_SOCKTYPE 10 /* ai_socktype not supported */ 169254721Semaste#define EAI_SYSTEM 11 /* system error returned in errno */ 170254721Semaste#define EAI_BADHINTS 12 171254721Semaste#define EAI_PROTOCOL 13 172254721Semaste#define EAI_MAX 14 173254721Semaste 174254721Semaste/* 175254721Semaste * Flag values for getaddrinfo() 176254721Semaste */ 177254721Semaste#define AI_PASSIVE 0x00000001 /* get address to use bind() */ 178254721Semaste#define AI_CANONNAME 0x00000002 /* fill ai_canonname */ 179254721Semaste#define AI_NUMERICHOST 0x00000004 /* prevent host name resolution */ 180254721Semaste#define AI_NUMERICSERV 0x00000008 /* prevent service name resolution */ 181254721Semaste/* valid flags for addrinfo (not a standard def, apps should not use it) */ 182254721Semaste#define AI_MASK \ 183254721Semaste (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | \ 184254721Semaste AI_ADDRCONFIG) 185254721Semaste 186254721Semaste#define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */ 187254721Semaste#define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */ 188254721Semaste#define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */ 189254721Semaste#define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */ 190254721Semaste/* special recommended flags for getipnodebyname */ 191254721Semaste#define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG) 192254721Semaste 193254721Semaste/* 194254721Semaste * Constants for getnameinfo() 195254721Semaste */ 196254721Semaste#define NI_MAXHOST 1025 197254721Semaste#define NI_MAXSERV 32 198254721Semaste 199254721Semaste/* 200254721Semaste * Flag values for getnameinfo() 201254721Semaste */ 202254721Semaste#define NI_NOFQDN 0x00000001 203254721Semaste#define NI_NUMERICHOST 0x00000002 204254721Semaste#define NI_NAMEREQD 0x00000004 205254721Semaste#define NI_NUMERICSERV 0x00000008 206254721Semaste#define NI_DGRAM 0x00000010 207254721Semaste#if 0 /* obsolete */ 208254721Semaste#define NI_WITHSCOPEID 0x00000020 209254721Semaste#endif 210254721Semaste 211254721Semaste/* 212254721Semaste * Scope delimit character 213254721Semaste */ 214254721Semaste#define SCOPE_DELIMITER '%' 215254721Semaste 216254721Semaste__BEGIN_DECLS 217254721Semastevoid endhostent(void); 218254721Semastevoid endnetent(void); 219254721Semastevoid endnetgrent(void); 220254721Semastevoid endprotoent(void); 221254721Semastevoid endservent(void); 222254721Semastevoid freehostent(struct hostent *); 223254721Semastestruct hostent *gethostbyaddr(const char *, int, int); 224254721Semastestruct hostent *gethostbyname(const char *); 225254721Semastestruct hostent *gethostbyname2(const char *, int); 226254721Semastestruct hostent *gethostent(void); 227254721Semastestruct hostent *getipnodebyaddr(const void *, size_t, int, int *); 228254721Semastestruct hostent *getipnodebyname(const char *, int, int, int *); 229254721Semastestruct netent *getnetbyaddr(uint32_t, int); 230254721Semastestruct netent *getnetbyname(const char *); 231254721Semastestruct netent *getnetent(void); 232254721Semasteint getnetgrent(char **, char **, char **); 233254721Semastestruct protoent *getprotobyname(const char *); 234254721Semastestruct protoent *getprotobynumber(int); 235254721Semastestruct protoent *getprotoent(void); 236254721Semastestruct servent *getservbyname(const char *, const char *); 237254721Semastestruct servent *getservbyport(int, const char *); 238254721Semastestruct servent *getservent(void); 239254721Semastevoid herror(const char *); 240254721Semaste__const char *hstrerror(int); 241254721Semasteint innetgr(const char *, const char *, const char *, const char *); 242254721Semastevoid sethostent(int); 243254721Semaste/* void sethostfile(const char *); */ 244254721Semastevoid setnetent(int); 245254721Semastevoid setprotoent(int); 246254721Semasteint getaddrinfo(const char *, const char *, 247254721Semaste const struct addrinfo *, struct addrinfo **); 248254721Semasteint getnameinfo(const struct sockaddr *, socklen_t, char *, 249254721Semaste size_t, char *, size_t, int); 250254721Semastevoid freeaddrinfo(struct addrinfo *); 251254721Semasteconst char *gai_strerror(int); 252254721Semastevoid setnetgrent(const char *); 253254721Semastevoid setservent(int); 254254721Semaste 255254721Semaste/* 256254721Semaste * PRIVATE functions specific to the FreeBSD implementation 257254721Semaste */ 258254721Semaste 259254721Semaste/* DO NOT USE THESE, THEY ARE SUBJECT TO CHANGE AND ARE NOT PORTABLE!!! */ 260254721Semasteint * __h_errno(void); 261254721Semaste__END_DECLS 262254721Semaste 263254721Semaste#endif /* !_NETDB_H_ */ 264254721Semaste