netdb.h revision 157779
1224102Sphilip/*- 2224102Sphilip * Copyright (c) 1980, 1983, 1988, 1993 3224102Sphilip * The Regents of the University of California. All rights reserved. 4224102Sphilip * 5224102Sphilip * Redistribution and use in source and binary forms, with or without 6242471Sphilip * modification, are permitted provided that the following conditions 7242471Sphilip * are met: 8224102Sphilip * 1. Redistributions of source code must retain the above copyright 9224102Sphilip * notice, this list of conditions and the following disclaimer. 10242471Sphilip * 2. Redistributions in binary form must reproduce the above copyright 11224102Sphilip * notice, this list of conditions and the following disclaimer in the 12224102Sphilip * documentation and/or other materials provided with the distribution. 13224102Sphilip * 3. All advertising materials mentioning features or use of this software 14224102Sphilip * must display the following acknowledgement: 15224102Sphilip * This product includes software developed by the University of 16224102Sphilip * California, Berkeley and its contributors. 17224102Sphilip * 4. Neither the name of the University nor the names of its contributors 18224102Sphilip * may be used to endorse or promote products derived from this software 19224102Sphilip * without specific prior written permission. 20224102Sphilip * 21224102Sphilip * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22224102Sphilip * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23224102Sphilip * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24224102Sphilip * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25224102Sphilip * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26224102Sphilip * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27224102Sphilip * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28224102Sphilip * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29224102Sphilip * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30224102Sphilip * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31224102Sphilip * SUCH DAMAGE. 32224102Sphilip * 33224102Sphilip * - 34224102Sphilip * Portions Copyright (c) 1993 by Digital Equipment Corporation. 35224102Sphilip * 36224102Sphilip * Permission to use, copy, modify, and distribute this software for any 37224102Sphilip * purpose with or without fee is hereby granted, provided that the above 38224102Sphilip * copyright notice and this permission notice appear in all copies, and that 39224102Sphilip * the name of Digital Equipment Corporation not be used in advertising or 40224102Sphilip * publicity pertaining to distribution of the document or software without 41224102Sphilip * specific, written prior permission. 42224102Sphilip * 43224102Sphilip * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL 44224102Sphilip * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 45224102Sphilip * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT 46224102Sphilip * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 47224102Sphilip * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 48224102Sphilip * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 49224102Sphilip * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 50224102Sphilip * SOFTWARE. 51224102Sphilip * - 52224102Sphilip * --Copyright-- 53224102Sphilip */ 54224102Sphilip 55224102Sphilip/* 56224102Sphilip * @(#)netdb.h 8.1 (Berkeley) 6/2/93 57224102Sphilip * From: Id: netdb.h,v 8.9 1996/11/19 08:39:29 vixie Exp $ 58224102Sphilip * $FreeBSD: head/include/netdb.h 157779 2006-04-15 16:20:27Z ume $ 59224102Sphilip */ 60224102Sphilip 61224102Sphilip#ifndef _NETDB_H_ 62224102Sphilip#define _NETDB_H_ 63224102Sphilip 64224102Sphilip#include <sys/cdefs.h> 65224102Sphilip#include <sys/_types.h> 66224102Sphilip 67224102Sphilip#ifndef _SIZE_T_DECLARED 68224102Sphiliptypedef __size_t size_t; 69224102Sphilip#define _SIZE_T_DECLARED 70224102Sphilip#endif 71224102Sphilip 72224102Sphilip#ifndef _SOCKLEN_T_DECLARED 73224102Sphiliptypedef __socklen_t socklen_t; 74224102Sphilip#define _SOCKLEN_T_DECLARED 75224102Sphilip#endif 76224102Sphilip 77224102Sphilip#ifndef _UINT32_T_DECLARED 78224102Sphiliptypedef __uint32_t uint32_t; 79242471Sphilip#define _UINT32_T_DECLARED 80224102Sphilip#endif 81224102Sphilip 82224102Sphilip#ifndef _PATH_HEQUIV 83224102Sphilip# define _PATH_HEQUIV "/etc/hosts.equiv" 84224102Sphilip#endif 85224102Sphilip#define _PATH_HOSTS "/etc/hosts" 86224102Sphilip#define _PATH_NETWORKS "/etc/networks" 87224102Sphilip#define _PATH_PROTOCOLS "/etc/protocols" 88224102Sphilip#define _PATH_SERVICES "/etc/services" 89224102Sphilip 90224102Sphilip#define h_errno (*__h_errno()) 91224102Sphilip 92224102Sphilip/* 93224102Sphilip * Structures returned by network data base library. All addresses are 94224102Sphilip * supplied in host order, and returned in network order (suitable for 95224102Sphilip * use in system calls). 96224102Sphilip */ 97242471Sphilipstruct hostent { 98224102Sphilip char *h_name; /* official name of host */ 99224102Sphilip char **h_aliases; /* alias list */ 100224102Sphilip int h_addrtype; /* host address type */ 101224102Sphilip int h_length; /* length of address */ 102224102Sphilip char **h_addr_list; /* list of addresses from name server */ 103224102Sphilip#define h_addr h_addr_list[0] /* address, for backward compatibility */ 104224102Sphilip}; 105224102Sphilip 106224102Sphilipstruct netent { 107224102Sphilip char *n_name; /* official name of net */ 108224102Sphilip char **n_aliases; /* alias list */ 109224102Sphilip int n_addrtype; /* net address type */ 110224102Sphilip uint32_t n_net; /* network # */ 111224102Sphilip}; 112224102Sphilip 113224102Sphilipstruct servent { 114224102Sphilip char *s_name; /* official service name */ 115224102Sphilip char **s_aliases; /* alias list */ 116224102Sphilip int s_port; /* port # */ 117224102Sphilip char *s_proto; /* protocol to use */ 118224102Sphilip}; 119224102Sphilip 120224102Sphilipstruct protoent { 121224102Sphilip char *p_name; /* official protocol name */ 122224102Sphilip char **p_aliases; /* alias list */ 123224102Sphilip int p_proto; /* protocol # */ 124224102Sphilip}; 125224102Sphilip 126242471Sphilipstruct addrinfo { 127242471Sphilip int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */ 128224102Sphilip int ai_family; /* PF_xxx */ 129224102Sphilip int ai_socktype; /* SOCK_xxx */ 130224102Sphilip int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ 131224102Sphilip socklen_t ai_addrlen; /* length of ai_addr */ 132224102Sphilip char *ai_canonname; /* canonical name for hostname */ 133224102Sphilip struct sockaddr *ai_addr; /* binary address */ 134224102Sphilip struct addrinfo *ai_next; /* next structure in linked list */ 135224102Sphilip}; 136224102Sphilip 137224102Sphilip/* 138224102Sphilip * Error return codes from gethostbyname() and gethostbyaddr() 139224102Sphilip * (left in h_errno). 140224102Sphilip */ 141224102Sphilip 142224102Sphilip#define NETDB_INTERNAL -1 /* see errno */ 143224102Sphilip#define NETDB_SUCCESS 0 /* no problem */ 144224102Sphilip#define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */ 145224102Sphilip#define TRY_AGAIN 2 /* Non-Authoritative Host not found, or SERVERFAIL */ 146224102Sphilip#define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ 147224102Sphilip#define NO_DATA 4 /* Valid name, no data record of requested type */ 148224102Sphilip#define NO_ADDRESS NO_DATA /* no address, look for MX record */ 149224102Sphilip 150224102Sphilip/* 151224102Sphilip * Error return codes from getaddrinfo() 152224102Sphilip */ 153224102Sphilip#if 0 154224102Sphilip/* obsoleted */ 155224102Sphilip#define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ 156224102Sphilip#endif 157224102Sphilip#define EAI_AGAIN 2 /* temporary failure in name resolution */ 158224102Sphilip#define EAI_BADFLAGS 3 /* invalid value for ai_flags */ 159224102Sphilip#define EAI_FAIL 4 /* non-recoverable failure in name resolution */ 160224102Sphilip#define EAI_FAMILY 5 /* ai_family not supported */ 161224102Sphilip#define EAI_MEMORY 6 /* memory allocation failure */ 162224102Sphilip#if 0 163224102Sphilip/* obsoleted */ 164224102Sphilip#define EAI_NODATA 7 /* no address associated with hostname */ 165224102Sphilip#endif 166224102Sphilip#define EAI_NONAME 8 /* hostname nor servname provided, or not known */ 167224102Sphilip#define EAI_SERVICE 9 /* servname not supported for ai_socktype */ 168224102Sphilip#define EAI_SOCKTYPE 10 /* ai_socktype not supported */ 169224102Sphilip#define EAI_SYSTEM 11 /* system error returned in errno */ 170224102Sphilip#define EAI_BADHINTS 12 171224102Sphilip#define EAI_PROTOCOL 13 172224102Sphilip#define EAI_MAX 14 173224102Sphilip 174224102Sphilip/* 175224102Sphilip * Flag values for getaddrinfo() 176224102Sphilip */ 177224102Sphilip#define AI_PASSIVE 0x00000001 /* get address to use bind() */ 178224102Sphilip#define AI_CANONNAME 0x00000002 /* fill ai_canonname */ 179224102Sphilip#define AI_NUMERICHOST 0x00000004 /* prevent host name resolution */ 180224102Sphilip#define AI_NUMERICSERV 0x00000008 /* prevent service name resolution */ 181224102Sphilip/* valid flags for addrinfo (not a standard def, apps should not use it) */ 182224102Sphilip#define AI_MASK \ 183224102Sphilip (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | \ 184224102Sphilip AI_ADDRCONFIG) 185224102Sphilip 186224102Sphilip#define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */ 187224102Sphilip#define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */ 188224102Sphilip#define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */ 189224102Sphilip#define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */ 190224102Sphilip/* special recommended flags for getipnodebyname */ 191224102Sphilip#define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG) 192224102Sphilip 193224102Sphilip/* 194224102Sphilip * Constants for getnameinfo() 195224102Sphilip */ 196224102Sphilip#define NI_MAXHOST 1025 197224102Sphilip#define NI_MAXSERV 32 198224102Sphilip 199224102Sphilip/* 200224102Sphilip * Flag values for getnameinfo() 201224102Sphilip */ 202224102Sphilip#define NI_NOFQDN 0x00000001 203224102Sphilip#define NI_NUMERICHOST 0x00000002 204224102Sphilip#define NI_NAMEREQD 0x00000004 205224102Sphilip#define NI_NUMERICSERV 0x00000008 206242471Sphilip#define NI_DGRAM 0x00000010 207224102Sphilip#if 0 /* obsolete */ 208224102Sphilip#define NI_WITHSCOPEID 0x00000020 209224102Sphilip#endif 210224102Sphilip 211224102Sphilip/* 212224102Sphilip * Scope delimit character 213224102Sphilip */ 214224102Sphilip#define SCOPE_DELIMITER '%' 215224102Sphilip 216224102Sphilip__BEGIN_DECLS 217224102Sphilipvoid endhostent(void); 218224102Sphilipvoid endnetent(void); 219224102Sphilipvoid endnetgrent(void); 220224102Sphilipvoid endprotoent(void); 221224102Sphilipvoid endservent(void); 222224102Sphilipvoid freehostent(struct hostent *); 223224102Sphilipstruct hostent *gethostbyaddr(const char *, int, int); 224224102Sphilipint gethostbyaddr_r(const char *, int, int, struct hostent *, 225224102Sphilip char *, size_t, struct hostent **, int *); 226224102Sphilipstruct hostent *gethostbyname(const char *); 227224102Sphilipint gethostbyname_r(const char *, struct hostent *, char *, size_t, 228224102Sphilip struct hostent **, int *); 229224102Sphilipstruct hostent *gethostbyname2(const char *, int); 230224102Sphilipint gethostbyname2_r(const char *, int, struct hostent *, char *, 231224102Sphilip size_t, struct hostent **, int *); 232224102Sphilipstruct hostent *gethostent(void); 233224102Sphilipint gethostent_r(struct hostent *, char *, size_t, 234224102Sphilip struct hostent **, int *); 235224102Sphilipstruct hostent *getipnodebyaddr(const void *, size_t, int, int *); 236224102Sphilipstruct hostent *getipnodebyname(const char *, int, int, int *); 237224102Sphilipstruct netent *getnetbyaddr(uint32_t, int); 238224102Sphilipint getnetbyaddr_r(uint32_t, int, struct netent *, char *, size_t, 239224102Sphilip struct netent**, int *); 240224102Sphilipstruct netent *getnetbyname(const char *); 241224102Sphilipint getnetbyname_r(const char *, struct netent *, char *, size_t, 242224102Sphilip struct netent **, int *); 243224102Sphilipstruct netent *getnetent(void); 244224102Sphilipint getnetent_r(struct netent *, char *, size_t, struct netent **, 245224102Sphilip int *); 246224102Sphilipint getnetgrent(char **, char **, char **); 247224102Sphilipstruct protoent *getprotobyname(const char *); 248224102Sphilipint getprotobyname_r(const char *, struct protoent *, char *, 249224102Sphilip size_t, struct protoent **); 250224102Sphilipstruct protoent *getprotobynumber(int); 251224102Sphilipint getprotobynumber_r(int, struct protoent *, char *, size_t, 252224102Sphilip struct protoent **); 253224102Sphilipstruct protoent *getprotoent(void); 254224102Sphilipint getprotoent_r(struct protoent *, char *, size_t, 255224102Sphilip struct protoent **); 256224102Sphilipstruct servent *getservbyname(const char *, const char *); 257224102Sphilipint getservbyname_r(const char *, const char *, struct servent *, 258224102Sphilip char *, size_t, struct servent **); 259224102Sphilipstruct servent *getservbyport(int, const char *); 260224102Sphilipint getservbyport_r(int, const char *, struct servent *, char *, 261224102Sphilip size_t, struct servent **); 262224102Sphilipstruct servent *getservent(void); 263224102Sphilipint getservent_r(struct servent *, char *, size_t, 264224102Sphilip struct servent **); 265224102Sphilipvoid herror(const char *); 266224102Sphilip__const char *hstrerror(int); 267224102Sphilipint innetgr(const char *, const char *, const char *, const char *); 268224102Sphilipvoid sethostent(int); 269224102Sphilip/* void sethostfile(const char *); */ 270224102Sphilipvoid setnetent(int); 271224102Sphilipvoid setprotoent(int); 272224102Sphilipint getaddrinfo(const char *, const char *, 273224102Sphilip const struct addrinfo *, struct addrinfo **); 274224102Sphilipint getnameinfo(const struct sockaddr *, socklen_t, char *, 275224102Sphilip size_t, char *, size_t, int); 276224102Sphilipvoid freeaddrinfo(struct addrinfo *); 277224102Sphilipconst char *gai_strerror(int); 278224102Sphilipvoid setnetgrent(const char *); 279224102Sphilipvoid setservent(int); 280224102Sphilip 281224102Sphilip/* 282224102Sphilip * PRIVATE functions specific to the FreeBSD implementation 283224102Sphilip */ 284224102Sphilip 285224102Sphilip/* DO NOT USE THESE, THEY ARE SUBJECT TO CHANGE AND ARE NOT PORTABLE!!! */ 286224102Sphilipint * __h_errno(void); 287224102Sphilip__END_DECLS 288224102Sphilip 289224102Sphilip#endif /* !_NETDB_H_ */ 290224102Sphilip