| 1 | /* |
| 2 | * Copyright (c) 2000-2009 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * @APPLE_LICENSE_HEADER_START@ |
| 5 | * |
| 6 | * This file contains Original Code and/or Modifications of Original Code |
| 7 | * as defined in and that are subject to the Apple Public Source License |
| 8 | * Version 2.0 (the 'License'). You may not use this file except in |
| 9 | * compliance with the License. Please obtain a copy of the License at |
| 10 | * http://www.opensource.apple.com/apsl/ and read it before using this |
| 11 | * file. |
| 12 | * |
| 13 | * The Original Code and all software distributed under the License are |
| 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
| 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
| 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
| 18 | * Please see the License for the specific language governing rights and |
| 19 | * limitations under the License. |
| 20 | * |
| 21 | * @APPLE_LICENSE_HEADER_END@ |
| 22 | */ |
| 23 | /* |
| 24 | * ++Copyright++ 1980, 1983, 1988, 1993 |
| 25 | * - |
| 26 | * Copyright (c) 1980, 1983, 1988, 1993 |
| 27 | *	The Regents of the University of California. All rights reserved. |
| 28 | * |
| 29 | * Redistribution and use in source and binary forms, with or without |
| 30 | * modification, are permitted provided that the following conditions |
| 31 | * are met: |
| 32 | * 1. Redistributions of source code must retain the above copyright |
| 33 | * notice, this list of conditions and the following disclaimer. |
| 34 | * 2. Redistributions in binary form must reproduce the above copyright |
| 35 | * notice, this list of conditions and the following disclaimer in the |
| 36 | * documentation and/or other materials provided with the distribution. |
| 37 | * 3. All advertising materials mentioning features or use of this software |
| 38 | * must display the following acknowledgement: |
| 39 | *	This product includes software developed by the University of |
| 40 | *	California, Berkeley and its contributors. |
| 41 | * 4. Neither the name of the University nor the names of its contributors |
| 42 | * may be used to endorse or promote products derived from this software |
| 43 | * without specific prior written permission. |
| 44 | * |
| 45 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 46 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 47 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 48 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 49 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 50 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 51 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 52 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 53 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 54 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 55 | * SUCH DAMAGE. |
| 56 | * |
| 57 | * - |
| 58 | * Portions Copyright (c) 1993 by Digital Equipment Corporation. |
| 59 | * |
| 60 | * Permission to use, copy, modify, and distribute this software for any |
| 61 | * purpose with or without fee is hereby granted, provided that the above |
| 62 | * copyright notice and this permission notice appear in all copies, and that |
| 63 | * the name of Digital Equipment Corporation not be used in advertising or |
| 64 | * publicity pertaining to distribution of the document or software without |
| 65 | * specific, written prior permission. |
| 66 | * |
| 67 | * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL |
| 68 | * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES |
| 69 | * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT |
| 70 | * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 71 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 72 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS |
| 73 | * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS |
| 74 | * SOFTWARE. |
| 75 | * - |
| 76 | * --Copyright-- |
| 77 | */ |
| 78 | |
| 79 | /* |
| 80 | * @(#)netdb.h	8.1 (Berkeley) 6/2/93 |
| 81 | */ |
| 82 | |
| 83 | #ifndef _NETDB_H_ |
| 84 | #define _NETDB_H_ |
| 85 | |
| 86 | #include <_types.h> |
| 87 | #include <sys/_types/_size_t.h> |
| 88 | #include <sys/_types/_socklen_t.h> |
| 89 | |
| 90 | #include <stdint.h> |
| 91 | #include <netinet/in.h>		/* IPPORT_RESERVED */ |
| 92 | |
| 93 | #ifndef _PATH_HEQUIV |
| 94 | # define	_PATH_HEQUIV	"/etc/hosts.equiv" |
| 95 | #endif |
| 96 | #define	_PATH_HOSTS	"/etc/hosts" |
| 97 | #define	_PATH_NETWORKS	"/etc/networks" |
| 98 | #define	_PATH_PROTOCOLS	"/etc/protocols" |
| 99 | #define	_PATH_SERVICES	"/etc/services" |
| 100 | |
| 101 | extern int h_errno; |
| 102 | |
| 103 | #ifndef IPPORT_RESERVED |
| 104 | #define	IPPORT_RESERVED		__DARWIN_IPPORT_RESERVED |
| 105 | #endif |
| 106 | |
| 107 | /* |
| 108 | * Structures returned by network data base library. All addresses are |
| 109 | * supplied in host order, and returned in network order (suitable for |
| 110 | * use in system calls). |
| 111 | */ |
| 112 | struct hostent { |
| 113 | 	char	*h_name;	/* official name of host */ |
| 114 | 	char	**h_aliases;	/* alias list */ |
| 115 | 	int	h_addrtype;	/* host address type */ |
| 116 | 	int	h_length;	/* length of address */ |
| 117 | 	char	**h_addr_list;	/* list of addresses from name server */ |
| 118 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
| 119 | #define	h_addr	h_addr_list[0]	/* address, for backward compatibility */ |
| 120 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
| 121 | }; |
| 122 | |
| 123 | /* |
| 124 | * Assumption here is that a network number |
| 125 | * fits in an unsigned long -- probably a poor one. |
| 126 | */ |
| 127 | struct netent { |
| 128 | 	char		*n_name;	/* official name of net */ |
| 129 | 	char		**n_aliases;	/* alias list */ |
| 130 | 	int		n_addrtype;	/* net address type */ |
| 131 | 	uint32_t	n_net;		/* network # */ |
| 132 | }; |
| 133 | |
| 134 | struct servent { |
| 135 | 	char	*s_name;	/* official service name */ |
| 136 | 	char	**s_aliases;	/* alias list */ |
| 137 | 	int	s_port;		/* port # */ |
| 138 | 	char	*s_proto;	/* protocol to use */ |
| 139 | }; |
| 140 | |
| 141 | struct protoent { |
| 142 | 	char	*p_name;	/* official protocol name */ |
| 143 | 	char	**p_aliases;	/* alias list */ |
| 144 | 	int	p_proto;	/* protocol # */ |
| 145 | }; |
| 146 | |
| 147 | struct addrinfo { |
| 148 | 	int	ai_flags;	/* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */ |
| 149 | 	int	ai_family;	/* PF_xxx */ |
| 150 | 	int	ai_socktype;	/* SOCK_xxx */ |
| 151 | 	int	ai_protocol;	/* 0 or IPPROTO_xxx for IPv4 and IPv6 */ |
| 152 | 	socklen_t ai_addrlen;	/* length of ai_addr */ |
| 153 | 	char	*ai_canonname;	/* canonical name for hostname */ |
| 154 | 	struct	sockaddr *ai_addr;	/* binary address */ |
| 155 | 	struct	addrinfo *ai_next;	/* next structure in linked list */ |
| 156 | }; |
| 157 | |
| 158 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
| 159 | struct rpcent { |
| 160 | char *r_name; /* name of server for this rpc program */ |
| 161 | char **r_aliases; /* alias list */ |
| 162 | int r_number; /* rpc program number */ |
| 163 | }; |
| 164 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
| 165 | |
| 166 | /* |
| 167 | * Error return codes from gethostbyname() and gethostbyaddr() |
| 168 | * (left in h_errno). |
| 169 | */ |
| 170 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
| 171 | #define	NETDB_INTERNAL	-1	/* see errno */ |
| 172 | #define	NETDB_SUCCESS	0	/* no problem */ |
| 173 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
| 174 | #define	HOST_NOT_FOUND	1 /* Authoritative Answer Host not found */ |
| 175 | #define	TRY_AGAIN	2 /* Non-Authoritative Host not found, or SERVERFAIL */ |
| 176 | #define	NO_RECOVERY	3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ |
| 177 | #define	NO_DATA		4 /* Valid name, no data record of requested type */ |
| 178 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
| 179 | #define	NO_ADDRESS	NO_DATA		/* no address, look for MX record */ |
| 180 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
| 181 | /* |
| 182 | * Error return codes from getaddrinfo() |
| 183 | */ |
| 184 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
| 185 | #define	EAI_ADDRFAMILY	 1	/* address family for hostname not supported */ |
| 186 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
| 187 | #define	EAI_AGAIN	 2	/* temporary failure in name resolution */ |
| 188 | #define	EAI_BADFLAGS	 3	/* invalid value for ai_flags */ |
| 189 | #define	EAI_FAIL	 4	/* non-recoverable failure in name resolution */ |
| 190 | #define	EAI_FAMILY	 5	/* ai_family not supported */ |
| 191 | #define	EAI_MEMORY	 6	/* memory allocation failure */ |
| 192 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
| 193 | #define	EAI_NODATA	 7	/* no address associated with hostname */ |
| 194 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
| 195 | #define	EAI_NONAME	 8	/* hostname nor servname provided, or not known */ |
| 196 | #define	EAI_SERVICE	 9	/* servname not supported for ai_socktype */ |
| 197 | #define	EAI_SOCKTYPE	10	/* ai_socktype not supported */ |
| 198 | #define	EAI_SYSTEM	11	/* system error returned in errno */ |
| 199 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
| 200 | #define	EAI_BADHINTS	12	/* invalid value for hints */ |
| 201 | #define	EAI_PROTOCOL	13	/* resolved protocol is unknown */ |
| 202 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
| 203 | #define	EAI_OVERFLOW	14	/* argument buffer overflow */ |
| 204 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
| 205 | #define	EAI_MAX		15 |
| 206 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
| 207 | |
| 208 | /* |
| 209 | * Flag values for getaddrinfo() |
| 210 | */ |
| 211 | #define	AI_PASSIVE	0x00000001 /* get address to use bind() */ |
| 212 | #define	AI_CANONNAME	0x00000002 /* fill ai_canonname */ |
| 213 | #define	AI_NUMERICHOST	0x00000004 /* prevent host name resolution */ |
| 214 | #define	AI_NUMERICSERV	0x00001000 /* prevent service name resolution */ |
| 215 | /* valid flags for addrinfo (not a standard def, apps should not use it) */ |
| 216 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
| 217 | #define AI_MASK \ |
| 218 | (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | \ |
| 219 | AI_ADDRCONFIG) |
| 220 | |
| 221 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
| 222 | #define	AI_ALL		0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */ |
| 223 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
| 224 | #define	AI_V4MAPPED_CFG	0x00000200 /* accept IPv4-mapped if kernel supports */ |
| 225 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
| 226 | #define	AI_ADDRCONFIG	0x00000400 /* only if any address is assigned */ |
| 227 | #define	AI_V4MAPPED	0x00000800 /* accept IPv4-mapped IPv6 address */ |
| 228 | /* special recommended flags for getipnodebyname */ |
| 229 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
| 230 | #define	AI_DEFAULT	(AI_V4MAPPED_CFG | AI_ADDRCONFIG) |
| 231 | /* If the hints pointer is null or ai_flags is zero, getaddrinfo() automatically defaults to the AI_DEFAULT behavior. |
| 232 | * To override this default behavior, thereby causing unusable addresses to be included in the results, pass any nonzero |
| 233 | * value for ai_flags, by setting any desired flag values, or by setting AI_UNUSABLE if no other flags are desired. */ |
| 234 | #define	AI_UNUSABLE	0x10000000 /* return addresses even if unusable (i.e. opposite of AI_DEFAULT) */ |
| 235 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
| 236 | |
| 237 | /* |
| 238 | * Constants for getnameinfo() |
| 239 | */ |
| 240 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
| 241 | #define	NI_MAXHOST	1025 |
| 242 | #define	NI_MAXSERV	32 |
| 243 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
| 244 | /* |
| 245 | * Flag values for getnameinfo() |
| 246 | */ |
| 247 | #define	NI_NOFQDN	0x00000001 |
| 248 | #define	NI_NUMERICHOST	0x00000002 |
| 249 | #define	NI_NAMEREQD	0x00000004 |
| 250 | #define	NI_NUMERICSERV	0x00000008 |
| 251 | #define	NI_NUMERICSCOPE 0x00000100 |
| 252 | #define	NI_DGRAM	0x00000010 |
| 253 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
| 254 | #define NI_WITHSCOPEID	0x00000020 |
| 255 | |
| 256 | /* |
| 257 | * Scope delimit character |
| 258 | */ |
| 259 | #define	SCOPE_DELIMITER	'%' |
| 260 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
| 261 | |
| 262 | __BEGIN_DECLS |
| 263 | |
| 264 | void		endhostent(void); |
| 265 | void		endnetent(void); |
| 266 | void		endprotoent(void); |
| 267 | void		endservent(void); |
| 268 | |
| 269 | void		freeaddrinfo(struct addrinfo *); |
| 270 | const char	*gai_strerror(int); |
| 271 | int		getaddrinfo(const char * __restrict, const char * __restrict, |
| 272 | 			 const struct addrinfo * __restrict, |
| 273 | 			 struct addrinfo ** __restrict); |
| 274 | struct hostent	*gethostbyaddr(const void *, socklen_t, int); |
| 275 | struct hostent	*gethostbyname(const char *); |
| 276 | struct hostent	*gethostent(void); |
| 277 | int getnameinfo(const struct sockaddr * __restrict, socklen_t, |
| 278 | 			 char * __restrict, socklen_t, char * __restrict, |
| 279 | 			 socklen_t, int); |
| 280 | struct netent	*getnetbyaddr(uint32_t, int); |
| 281 | struct netent	*getnetbyname(const char *); |
| 282 | struct netent	*getnetent(void); |
| 283 | struct protoent	*getprotobyname(const char *); |
| 284 | struct protoent	*getprotobynumber(int); |
| 285 | struct protoent	*getprotoent(void); |
| 286 | struct servent	*getservbyname(const char *, const char *); |
| 287 | struct servent	*getservbyport(int, const char *); |
| 288 | struct servent	*getservent(void); |
| 289 | void		sethostent(int); |
| 290 | /* void		sethostfile(const char *); */ |
| 291 | void		setnetent(int); |
| 292 | void		setprotoent(int); |
| 293 | void		setservent(int); |
| 294 | |
| 295 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
| 296 | void		freehostent(struct hostent *); |
| 297 | struct hostent	*gethostbyname2(const char *, int); |
| 298 | struct hostent	*getipnodebyaddr(const void *, size_t, int, int *); |
| 299 | struct hostent	*getipnodebyname(const char *, int, int, int *); |
| 300 | struct rpcent	*getrpcbyname(const char *name); |
| 301 | #ifdef __LP64__ |
| 302 | struct rpcent	*getrpcbynumber(int number); |
| 303 | #else |
| 304 | struct rpcent	*getrpcbynumber(long number); |
| 305 | #endif |
| 306 | struct rpcent	*getrpcent(void); |
| 307 | void		setrpcent(int stayopen); |
| 308 | void		endrpcent(void); |
| 309 | void		herror(const char *); |
| 310 | const char	*hstrerror(int); |
| 311 | int			innetgr(const char *, const char *, const char *, const char *); |
| 312 | int			getnetgrent(char **, char **, char **); |
| 313 | void		endnetgrent(void); |
| 314 | void		setnetgrent(const char *); |
| 315 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
| 316 | |
| 317 | __END_DECLS |
| 318 | |
| 319 | #endif /* !_NETDB_H_ */ |