1 /*- 2 * Copyright (c) 1980, 1983, 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 4. Neither the name of the University nor the names of its contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * - 30 * Portions Copyright (c) 1993 by Digital Equipment Corporation. 31 * 32 * Permission to use, copy, modify, and distribute this software for any 33 * purpose with or without fee is hereby granted, provided that the above 34 * copyright notice and this permission notice appear in all copies, and that 35 * the name of Digital Equipment Corporation not be used in advertising or 36 * publicity pertaining to distribution of the document or software without 37 * specific, written prior permission. 38 * 39 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL 40 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 41 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT 42 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 43 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 44 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 45 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 46 * SOFTWARE. 47 * - 48 * --Copyright-- 49 */ 50 51 /* 52 * @(#)netdb.h 8.1 (Berkeley) 6/2/93 53 * From: Id: netdb.h,v 8.9 1996/11/19 08:39:29 vixie Exp $ 54 * $FreeBSD: src/include/netdb.h,v 1.23 2002/03/23 17:24:53 imp Exp $ 55 */ 56 57 #ifndef _NETDB_H_ 58 #define _NETDB_H_ 59 60 #include <sys/cdefs.h> 61 #include <sys/types.h> 62 #include <machine/ansi.h> 63 #include <stdio.h> 64 65 #ifndef __socklen_t_defined 66 typedef unsigned int socklen_t; 67 #define __socklen_t_defined 1 68 #endif 69 70 #ifdef _BSD_SOCKLEN_T_ 71 typedef _BSD_SOCKLEN_T_ socklen_t; 72 #undef _BSD_SOCKLEN_T_ 73 #endif 74 75 #ifndef _PATH_HEQUIV 76 # define _PATH_HEQUIV "/etc/hosts.equiv" 77 #endif 78 #define _PATH_HOSTS "/etc/hosts" 79 #define _PATH_NETWORKS "/etc/networks" 80 #define _PATH_PROTOCOLS "/etc/protocols" 81 #define _PATH_SERVICES "/etc/services" 82 #define _PATH_NSSWITCH_CONF "/etc/nsswitch.conf" 83 84 __BEGIN_DECLS 85 extern int *__h_errno_location(void); 86 __END_DECLS 87 88 #define h_errno (*(__h_errno_location())) 89 90 #define MAXALIASES 35 91 /* For now, only support one return address. */ 92 #define MAXADDRS 2 93 /* 94 * Structures returned by network data base library. All addresses are 95 * supplied in host order, and returned in network order (suitable for 96 * use in system calls). 97 */ 98 struct hostent { 99 char *h_name; /* official name of host */ 100 char **h_aliases; /* alias list */ 101 int h_addrtype; /* host address type */ 102 int h_length; /* length of address */ 103 char **h_addr_list; /* list of addresses from name server */ 104 char *h_addr; /* address, for backward compatibility */ 105 /* private data, for re-entrancy */ 106 char *__host_addrs[MAXADDRS]; 107 char *__host_aliases[MAXALIASES]; 108 unsigned int __host_addr[4]; 109 }; 110 111 /* 112 * Assumption here is that a network number 113 * fits in an unsigned long -- probably a poor one. 114 */ 115 struct netent { 116 char *n_name; /* official name of net */ 117 char **n_aliases; /* alias list */ 118 int n_addrtype; /* net address type */ 119 unsigned long n_net; /* network # */ 120 }; 121 122 struct servent { 123 char *s_name; /* official service name */ 124 char **s_aliases; /* alias list */ 125 int s_port; /* port # */ 126 char *s_proto; /* protocol to use */ 127 }; 128 129 struct protoent { 130 char *p_name; /* official protocol name */ 131 char **p_aliases; /* alias list */ 132 int p_proto; /* protocol # */ 133 }; 134 135 struct addrinfo { 136 int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */ 137 int ai_family; /* PF_xxx */ 138 int ai_socktype; /* SOCK_xxx */ 139 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ 140 size_t ai_addrlen; /* length of ai_addr */ 141 char *ai_canonname; /* canonical name for hostname */ 142 struct sockaddr *ai_addr; /* binary address */ 143 struct addrinfo *ai_next; /* next structure in linked list */ 144 }; 145 146 /* 147 * Error return codes from gethostbyname() and gethostbyaddr() 148 * (left in extern int h_errno). 149 */ 150 151 #define NETDB_INTERNAL -1 /* see errno */ 152 #define NETDB_SUCCESS 0 /* no problem */ 153 #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */ 154 #define TRY_AGAIN 2 /* Non-Authoritative Host not found, or SERVERFAIL */ 155 #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ 156 #define NO_DATA 4 /* Valid name, no data record of requested type */ 157 #define NO_ADDRESS NO_DATA /* no address, look for MX record */ 158 159 /* 160 * Error return codes from getaddrinfo() 161 */ 162 /* Error values for `getaddrinfo' function. */ 163 # define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */ 164 # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */ 165 # define EAI_AGAIN -3 /* Temporary failure in name resolution. */ 166 # define EAI_FAIL -4 /* Non-recoverable failure in name res. */ 167 # define EAI_NODATA -5 /* No address associated with NAME. */ 168 # define EAI_FAMILY -6 /* `ai_family' not supported. */ 169 # define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */ 170 # define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */ 171 # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */ 172 # define EAI_MEMORY -10 /* Memory allocation failure. */ 173 # define EAI_SYSTEM -11 /* System error returned in `errno'. */ 174 # define EAI_OVERFLOW -12 /* Argument buffer overflow. */ 175 # ifdef __USE_GNU 176 # define EAI_INPROGRESS -100 /* Processing request in progress. */ 177 # define EAI_CANCELED -101 /* Request canceled. */ 178 # define EAI_NOTCANCELED -102 /* Request not canceled. */ 179 # define EAI_ALLDONE -103 /* All requests done. */ 180 # define EAI_INTR -104 /* Interrupted by a signal. */ 181 # define EAI_IDN_ENCODE -105 /* IDN encoding failed. */ 182 # endif 183 184 /* 185 * Flag values for getaddrinfo() 186 */ 187 #define AI_PASSIVE 0x00000001 /* get address to use bind() */ 188 #define AI_CANONNAME 0x00000002 /* fill ai_canonname */ 189 #define AI_NUMERICHOST 0x00000004 /* prevent name resolution */ 190 #define AI_NUMERICSERV 0x00000008 /* don't use name resolution. */ 191 /* valid flags for addrinfo */ 192 #define AI_MASK \ 193 (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_ADDRCONFIG) 194 195 #define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */ 196 #define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */ 197 #define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */ 198 #define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */ 199 /* special recommended flags for getipnodebyname */ 200 #define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG) 201 202 /* 203 * Constants for getnameinfo() 204 */ 205 #define NI_MAXHOST 1025 206 #define NI_MAXSERV 32 207 208 /* 209 * Flag values for getnameinfo() 210 */ 211 #define NI_NOFQDN 0x00000001 212 #define NI_NUMERICHOST 0x00000002 213 #define NI_NAMEREQD 0x00000004 214 #define NI_NUMERICSERV 0x00000008 215 #define NI_DGRAM 0x00000010 216 #define NI_WITHSCOPEID 0x00000020 217 218 /* 219 * Scope delimit character 220 */ 221 #define SCOPE_DELIMITER '%' 222 223 __BEGIN_DECLS 224 void endhostent(void); 225 void endhostent_r(FILE **, int *); 226 void endnetent(void); 227 void endnetgrent(void); 228 void endprotoent(void); 229 void endservent(void); 230 void freehostent(struct hostent *); 231 struct hostent *gethostbyaddr(const void *, socklen_t, int); 232 struct hostent *gethostbyname(const char *); 233 struct hostent *gethostbyname2(const char *, int); 234 struct hostent *gethostent(void); 235 int gethostent_r(struct hostent *, char *, int, int *, FILE **); 236 struct hostent *getipnodebyaddr(const void *, size_t, int, int *); 237 struct hostent *getipnodebyname(const char *, int, int, int *); 238 struct netent *getnetbyaddr(uint32_t, int); 239 struct netent *getnetbyname(const char *); 240 struct netent *getnetent(void); 241 int getnetgrent(char **, char **, char **); 242 struct protoent *getprotobyname(const char *); 243 struct protoent *getprotobynumber(int); 244 struct protoent *getprotoent(void); 245 struct servent *getservbyname(const char *, const char *); 246 struct servent *getservbyport(int, const char *); 247 struct servent *getservent(void); 248 void herror(const char *); 249 __const char *hstrerror(int); 250 int innetgr(const char *, const char *, const char *, const char *); 251 void sethostent(int); 252 void sethostent_r(int, FILE **, int *); 253 /* void sethostfile(const char *); */ 254 void setnetent(int); 255 void setprotoent(int); 256 int getaddrinfo(const char *__restrict, const char *__restrict, 257 const struct addrinfo *__restrict, 258 struct addrinfo **__restrict); 259 int getnameinfo(const struct sockaddr *__restrict, socklen_t, 260 char *__restrict, socklen_t, char *__restrict, 261 socklen_t, unsigned int); 262 void freeaddrinfo(struct addrinfo *); 263 char *gai_strerror(int); 264 int setnetgrent(const char *); 265 void setservent(int); 266 267 /* 268 * PRIVATE functions specific to the FreeBSD implementation 269 */ 270 271 /* DO NOT USE THESE, THEY ARE SUBJECT TO CHANGE AND ARE NOT PORTABLE!!! */ 272 void _sethosthtent(int); 273 void _sethosthtent_r(int, FILE **, int *); 274 void _endhosthtent(void); 275 void _endhosthtent_r(FILE **, int *); 276 void _sethostdnsent(int); 277 void _endhostdnsent(void); 278 void _setnethtent(int); 279 void _endnethtent(void); 280 void _setnetdnsent(int); 281 void _endnetdnsent(void); 282 struct hostent * _gethostbynisname(const char *, int); 283 struct hostent * _gethostbynisaddr(const char *, int, int); 284 void _map_v4v6_address(const char *, char *); 285 void _map_v4v6_hostent(struct hostent *, char **, int *); 286 __END_DECLS 287 288 #endif /* !_NETDB_H_ */ 289