netdb.h revision 148308
136849Sdfr/*- 2121129Sdfr * Copyright (c) 1980, 1983, 1988, 1993 336849Sdfr * The Regents of the University of California. All rights reserved. 436849Sdfr * 536849Sdfr * Redistribution and use in source and binary forms, with or without 636849Sdfr * modification, are permitted provided that the following conditions 736849Sdfr * are met: 836849Sdfr * 1. Redistributions of source code must retain the above copyright 936849Sdfr * notice, this list of conditions and the following disclaimer. 1036849Sdfr * 2. Redistributions in binary form must reproduce the above copyright 1136849Sdfr * notice, this list of conditions and the following disclaimer in the 1236849Sdfr * documentation and/or other materials provided with the distribution. 1336849Sdfr * 3. All advertising materials mentioning features or use of this software 1436849Sdfr * must display the following acknowledgement: 1536849Sdfr * This product includes software developed by the University of 1636849Sdfr * California, Berkeley and its contributors. 1736849Sdfr * 4. Neither the name of the University nor the names of its contributors 1836849Sdfr * may be used to endorse or promote products derived from this software 1936849Sdfr * without specific prior written permission. 2036849Sdfr * 2136849Sdfr * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2236849Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2336849Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2436849Sdfr * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2536849Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2650477Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2736849Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2836849Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2936849Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3036849Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3136849Sdfr * SUCH DAMAGE. 32132354Sdfr * 33132354Sdfr * - 34132354Sdfr * Portions Copyright (c) 1993 by Digital Equipment Corporation. 3568522Smsmith * 36132354Sdfr * Permission to use, copy, modify, and distribute this software for any 37132354Sdfr * purpose with or without fee is hereby granted, provided that the above 38132354Sdfr * copyright notice and this permission notice appear in all copies, and that 39132354Sdfr * the name of Digital Equipment Corporation not be used in advertising or 4068522Smsmith * publicity pertaining to distribution of the document or software without 41132354Sdfr * specific, written prior permission. 4268522Smsmith * 43132354Sdfr * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL 4468522Smsmith * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 4568522Smsmith * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT 46132354Sdfr * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 47132354Sdfr * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 48103329Simp * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 49103329Simp * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 50132354Sdfr * SOFTWARE. 51132354Sdfr * - 52132354Sdfr * --Copyright-- 53132354Sdfr */ 54103329Simp 55103329Simp/* 56132354Sdfr * @(#)netdb.h 8.1 (Berkeley) 6/2/93 57132354Sdfr * From: Id: netdb.h,v 8.9 1996/11/19 08:39:29 vixie Exp $ 5868522Smsmith * $FreeBSD: head/include/netdb.h 148308 2005-07-22 18:21:28Z ume $ 5968522Smsmith */ 6075718Sobrien 6175718Sobrien#ifndef _NETDB_H_ 6268522Smsmith#define _NETDB_H_ 63132354Sdfr 64132354Sdfr#include <sys/cdefs.h> 65132354Sdfr#include <sys/_types.h> 66132354Sdfr 67132354Sdfr#ifndef _SIZE_T_DECLARED 68132354Sdfrtypedef __size_t size_t; 69132354Sdfr#define _SIZE_T_DECLARED 70132354Sdfr#endif 7175718Sobrien 7268522Smsmith#ifndef _SOCKLEN_T_DECLARED 7368522Smsmithtypedef __socklen_t socklen_t; 7455205Speter#define _SOCKLEN_T_DECLARED 7536849Sdfr#endif 7644515Sbde 7759093Sdfr#ifndef _UINT32_T_DECLARED 7844515Sbdetypedef __uint32_t uint32_t; 79132354Sdfr#define _UINT32_T_DECLARED 80121489Simp#endif 81121489Simp 82121489Simp#ifndef _PATH_HEQUIV 83121489Simp# define _PATH_HEQUIV "/etc/hosts.equiv" 84121489Simp#endif 85121489Simp#define _PATH_HOSTS "/etc/hosts" 86121489Simp#define _PATH_NETWORKS "/etc/networks" 87121489Simp#define _PATH_PROTOCOLS "/etc/protocols" 88121489Simp#define _PATH_SERVICES "/etc/services" 8936849Sdfr 9036849Sdfr#define h_errno (*__h_error()) 9136972Sdfr 92132354Sdfr/* 93132354Sdfr * Structures returned by network data base library. All addresses are 94132354Sdfr * supplied in host order, and returned in network order (suitable for 95132354Sdfr * use in system calls). 96132354Sdfr */ 97121129Sdfrstruct hostent { 98132354Sdfr char *h_name; /* official name of host */ 99132354Sdfr char **h_aliases; /* alias list */ 100132354Sdfr int h_addrtype; /* host address type */ 101132354Sdfr int h_length; /* length of address */ 102132354Sdfr char **h_addr_list; /* list of addresses from name server */ 103132354Sdfr#define h_addr h_addr_list[0] /* address, for backward compatibility */ 104132354Sdfr}; 105132354Sdfr 106132354Sdfrstruct netent { 107132354Sdfr char *n_name; /* official name of net */ 108132354Sdfr char **n_aliases; /* alias list */ 109132354Sdfr int n_addrtype; /* net address type */ 110132354Sdfr uint32_t n_net; /* network # */ 111132354Sdfr}; 112132354Sdfr 113132354Sdfrstruct servent { 114132354Sdfr char *s_name; /* official service name */ 115132354Sdfr char **s_aliases; /* alias list */ 116132354Sdfr int s_port; /* port # */ 117132354Sdfr char *s_proto; /* protocol to use */ 118132354Sdfr}; 11936972Sdfr 120132354Sdfrstruct protoent { 121132354Sdfr char *p_name; /* official protocol name */ 122132354Sdfr char **p_aliases; /* alias list */ 123132354Sdfr int p_proto; /* protocol # */ 124132354Sdfr}; 12559093Sdfr 12636849Sdfrstruct addrinfo { 127132354Sdfr int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */ 128132354Sdfr int ai_family; /* PF_xxx */ 129132354Sdfr int ai_socktype; /* SOCK_xxx */ 13036849Sdfr int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ 13136849Sdfr socklen_t ai_addrlen; /* length of ai_addr */ 132132354Sdfr char *ai_canonname; /* canonical name for hostname */ 133132354Sdfr struct sockaddr *ai_addr; /* binary address */ 134132354Sdfr struct addrinfo *ai_next; /* next structure in linked list */ 135132354Sdfr}; 13665557Sjasone 13765557Sjasone/* 13865557Sjasone * Error return codes from gethostbyname() and gethostbyaddr() 13965557Sjasone * (left in h_errno). 140132354Sdfr */ 14165557Sjasone 14265557Sjasone#define NETDB_INTERNAL -1 /* see errno */ 14341153Swollman#define NETDB_SUCCESS 0 /* no problem */ 14441153Swollman#define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */ 14541153Swollman#define TRY_AGAIN 2 /* Non-Authoritative Host not found, or SERVERFAIL */ 146132354Sdfr#define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ 14741153Swollman#define NO_DATA 4 /* Valid name, no data record of requested type */ 14841153Swollman#define NO_ADDRESS NO_DATA /* no address, look for MX record */ 14946743Sdfr 15075718Sobrien/* 15175718Sobrien * Error return codes from getaddrinfo() 15275718Sobrien */ 15375718Sobrien#if 0 15475718Sobrien/* obsoleted */ 15575718Sobrien#define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ 15678365Speter#endif 15775718Sobrien#define EAI_AGAIN 2 /* temporary failure in name resolution */ 15875718Sobrien#define EAI_BADFLAGS 3 /* invalid value for ai_flags */ 15975718Sobrien#define EAI_FAIL 4 /* non-recoverable failure in name resolution */ 16075718Sobrien#define EAI_FAMILY 5 /* ai_family not supported */ 16146743Sdfr#define EAI_MEMORY 6 /* memory allocation failure */ 16236849Sdfr#if 0 163119967Smarcel/* obsoleted */ 164119967Smarcel#define EAI_NODATA 7 /* no address associated with hostname */ 165119967Smarcel#endif 166119967Smarcel#define EAI_NONAME 8 /* hostname nor servname provided, or not known */ 167119967Smarcel#define EAI_SERVICE 9 /* servname not supported for ai_socktype */ 168119967Smarcel#define EAI_SOCKTYPE 10 /* ai_socktype not supported */ 169119967Smarcel#define EAI_SYSTEM 11 /* system error returned in errno */ 170119967Smarcel#define EAI_BADHINTS 12 171119967Smarcel#define EAI_PROTOCOL 13 172119967Smarcel#define EAI_MAX 14 173119967Smarcel 174119967Smarcel/* 17536972Sdfr * Flag values for getaddrinfo() 17636972Sdfr */ 177132354Sdfr#define AI_PASSIVE 0x00000001 /* get address to use bind() */ 178132354Sdfr#define AI_CANONNAME 0x00000002 /* fill ai_canonname */ 179132354Sdfr#define AI_NUMERICHOST 0x00000004 /* prevent host name resolution */ 180132354Sdfr#define AI_NUMERICSERV 0x00000008 /* prevent service name resolution */ 181121129Sdfr/* valid flags for addrinfo (not a standard def, apps should not use it) */ 182121129Sdfr#define AI_MASK \ 18336849Sdfr (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | \ 18475718Sobrien AI_ADDRCONFIG) 18536849Sdfr 18636849Sdfr#define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */ 18736849Sdfr#define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */ 18847397Sdfr#define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */ 18947397Sdfr#define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */ 19047397Sdfr/* special recommended flags for getipnodebyname */ 19147397Sdfr#define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG) 19247397Sdfr 193132354Sdfr/* 194132354Sdfr * Constants for getnameinfo() 195132354Sdfr */ 19647397Sdfr#define NI_MAXHOST 1025 197143785Simp#define NI_MAXSERV 32 198132354Sdfr 199132354Sdfr/* 200132354Sdfr * Flag values for getnameinfo() 201132354Sdfr */ 202132354Sdfr#define NI_NOFQDN 0x00000001 203132354Sdfr#define NI_NUMERICHOST 0x00000002 20447397Sdfr#define NI_NAMEREQD 0x00000004 205143785Simp#define NI_NUMERICSERV 0x00000008 20647397Sdfr#define NI_DGRAM 0x00000010 20747397Sdfr#if 0 /* obsolete */ 20847397Sdfr#define NI_WITHSCOPEID 0x00000020 209144926Simp#endif 210144926Simp 21147397Sdfr/* 21247397Sdfr * Scope delimit character 21393365Smdodd */ 21493365Smdodd#define SCOPE_DELIMITER '%' 21593365Smdodd 21647397Sdfr__BEGIN_DECLS 21747397Sdfrvoid endhostent(void); 21847397Sdfrvoid endnetent(void); 21947608Sdfrvoid endnetgrent(void); 22047397Sdfrvoid endprotoent(void); 22147397Sdfrvoid endservent(void); 22252174Sdfrvoid freehostent(struct hostent *); 22352174Sdfrstruct hostent *gethostbyaddr(const char *, int, int); 22447397Sdfrstruct hostent *gethostbyname(const char *); 22547397Sdfrstruct hostent *gethostbyname2(const char *, int); 22647397Sdfrstruct hostent *gethostent(void); 22752174Sdfrstruct hostent *getipnodebyaddr(const void *, size_t, int, int *); 22852174Sdfrstruct hostent *getipnodebyname(const char *, int, int, int *); 22947397Sdfrstruct netent *getnetbyaddr(uint32_t, int); 230144952Simpstruct netent *getnetbyname(const char *); 23188373Stmmstruct netent *getnetent(void); 23288373Stmmint getnetgrent(char **, char **, char **); 23388373Stmmstruct protoent *getprotobyname(const char *); 234103266Sjhbstruct protoent *getprotobynumber(int); 23588373Stmmstruct protoent *getprotoent(void); 23636849Sdfrstruct servent *getservbyname(const char *, const char *); 23736849Sdfrstruct servent *getservbyport(int, const char *); 23836972Sdfrstruct servent *getservent(void); 23936849Sdfrvoid herror(const char *); 24041153Swollman__const char *hstrerror(int); 24136849Sdfrint innetgr(const char *, const char *, const char *, const char *); 24236849Sdfrvoid sethostent(int); 24336849Sdfr/* void sethostfile(const char *); */ 24436849Sdfrvoid setnetent(int); 24536849Sdfrvoid setprotoent(int); 24641153Swollmanint getaddrinfo(const char *, const char *, 24741153Swollman const struct addrinfo *, struct addrinfo **); 24869294Smdoddint getnameinfo(const struct sockaddr *, socklen_t, char *, 24975718Sobrien size_t, char *, size_t, int); 25075718Sobrienvoid freeaddrinfo(struct addrinfo *); 25169294Smdoddconst char *gai_strerror(int); 25241153Swollmanvoid setnetgrent(const char *); 253100421Simpvoid setservent(int); 254119967Smarcel 255119967Smarcel/* 25641153Swollman * PRIVATE functions specific to the FreeBSD implementation 25741153Swollman */ 25841153Swollman 25945720Speter/* DO NOT USE THESE, THEY ARE SUBJECT TO CHANGE AND ARE NOT PORTABLE!!! */ 26069294Smdoddint * __h_error(void); 26169294Smdodd__END_DECLS 26249195Smdodd 26349195Smdodd#endif /* !_NETDB_H_ */ 26449195Smdodd