2 * Copyright (c) 2000-2009 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
24 * ++Copyright++ 1980, 1983, 1988, 1993
26 * Copyright (c) 1980, 1983, 1988, 1993
27 * The Regents of the University of California. All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
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.
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
58 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
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.
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
80 * @(#)netdb.h 8.1 (Berkeley) 6/2/93
88 #include <netinet/in.h> /* IPPORT_RESERVED */
92 typedef __darwin_size_t
size_t;
97 typedef __darwin_socklen_t socklen_t
;
101 # define _PATH_HEQUIV "/etc/hosts.equiv"
103 #define _PATH_HOSTS "/etc/hosts"
104 #define _PATH_NETWORKS "/etc/networks"
105 #define _PATH_PROTOCOLS "/etc/protocols"
106 #define _PATH_SERVICES "/etc/services"
110 #ifndef IPPORT_RESERVED
111 #define IPPORT_RESERVED __DARWIN_IPPORT_RESERVED
115 * Structures returned by network data base library. All addresses are
116 * supplied in host order, and returned in network order (suitable for
117 * use in system calls).
120 char *h_name
; /* official name of host */
121 char **h_aliases
; /* alias list */
122 int h_addrtype
; /* host address type */
123 int h_length
; /* length of address */
124 char **h_addr_list
; /* list of addresses from name server */
125 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
126 #define h_addr h_addr_list[0] /* address, for backward compatibility */
127 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
131 * Assumption here is that a network number
132 * fits in an unsigned long -- probably a poor one.
135 char *n_name
; /* official name of net */
136 char **n_aliases
; /* alias list */
137 int n_addrtype
; /* net address type */
138 uint32_t n_net
; /* network # */
142 char *s_name
; /* official service name */
143 char **s_aliases
; /* alias list */
144 int s_port
; /* port # */
145 char *s_proto
; /* protocol to use */
149 char *p_name
; /* official protocol name */
150 char **p_aliases
; /* alias list */
151 int p_proto
; /* protocol # */
155 int ai_flags
; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
156 int ai_family
; /* PF_xxx */
157 int ai_socktype
; /* SOCK_xxx */
158 int ai_protocol
; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
159 socklen_t ai_addrlen
; /* length of ai_addr */
160 char *ai_canonname
; /* canonical name for hostname */
161 struct sockaddr
*ai_addr
; /* binary address */
162 struct addrinfo
*ai_next
; /* next structure in linked list */
165 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
167 char *r_name
; /* name of server for this rpc program */
168 char **r_aliases
; /* alias list */
169 int r_number
; /* rpc program number */
171 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
174 * Error return codes from gethostbyname() and gethostbyaddr()
177 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
178 #define NETDB_INTERNAL -1 /* see errno */
179 #define NETDB_SUCCESS 0 /* no problem */
180 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
181 #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */
182 #define TRY_AGAIN 2 /* Non-Authoritative Host not found, or SERVERFAIL */
183 #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
184 #define NO_DATA 4 /* Valid name, no data record of requested type */
185 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
186 #define NO_ADDRESS NO_DATA /* no address, look for MX record */
187 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
189 * Error return codes from getaddrinfo()
191 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
192 #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */
193 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
194 #define EAI_AGAIN 2 /* temporary failure in name resolution */
195 #define EAI_BADFLAGS 3 /* invalid value for ai_flags */
196 #define EAI_FAIL 4 /* non-recoverable failure in name resolution */
197 #define EAI_FAMILY 5 /* ai_family not supported */
198 #define EAI_MEMORY 6 /* memory allocation failure */
199 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
200 #define EAI_NODATA 7 /* no address associated with hostname */
201 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
202 #define EAI_NONAME 8 /* hostname nor servname provided, or not known */
203 #define EAI_SERVICE 9 /* servname not supported for ai_socktype */
204 #define EAI_SOCKTYPE 10 /* ai_socktype not supported */
205 #define EAI_SYSTEM 11 /* system error returned in errno */
206 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
207 #define EAI_BADHINTS 12 /* invalid value for hints */
208 #define EAI_PROTOCOL 13 /* resolved protocol is unknown */
209 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
210 #define EAI_OVERFLOW 14 /* argument buffer overflow */
211 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
213 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
216 * Flag values for getaddrinfo()
218 #define AI_PASSIVE 0x00000001 /* get address to use bind() */
219 #define AI_CANONNAME 0x00000002 /* fill ai_canonname */
220 #define AI_NUMERICHOST 0x00000004 /* prevent host name resolution */
221 #define AI_NUMERICSERV 0x00001000 /* prevent service name resolution */
222 /* valid flags for addrinfo (not a standard def, apps should not use it) */
223 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
225 (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | \
228 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
229 #define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */
230 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
231 #define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */
232 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
233 #define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */
234 #define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */
235 /* special recommended flags for getipnodebyname */
236 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
237 #define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG)
238 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
241 * Constants for getnameinfo()
243 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
244 #define NI_MAXHOST 1025
245 #define NI_MAXSERV 32
246 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
248 * Flag values for getnameinfo()
250 #define NI_NOFQDN 0x00000001
251 #define NI_NUMERICHOST 0x00000002
252 #define NI_NAMEREQD 0x00000004
253 #define NI_NUMERICSERV 0x00000008
254 #define NI_DGRAM 0x00000010
255 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
256 #define NI_WITHSCOPEID 0x00000020
259 * Scope delimit character
261 #define SCOPE_DELIMITER '%'
262 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
266 void endhostent(void);
267 void endnetent(void);
268 void endprotoent(void);
269 void endservent(void);
271 void freeaddrinfo(struct addrinfo
*);
272 const char *gai_strerror(int);
273 int getaddrinfo(const char * __restrict
, const char * __restrict
,
274 const struct addrinfo
* __restrict
,
275 struct addrinfo
** __restrict
);
276 struct hostent
*gethostbyaddr(const void *, socklen_t
, int);
277 struct hostent
*gethostbyname(const char *);
278 struct hostent
*gethostent(void);
279 int getnameinfo(const struct sockaddr
* __restrict
, socklen_t
,
280 char * __restrict
, socklen_t
, char * __restrict
,
282 struct netent
*getnetbyaddr(uint32_t, int);
283 struct netent
*getnetbyname(const char *);
284 struct netent
*getnetent(void);
285 struct protoent
*getprotobyname(const char *);
286 struct protoent
*getprotobynumber(int);
287 struct protoent
*getprotoent(void);
288 struct servent
*getservbyname(const char *, const char *);
289 struct servent
*getservbyport(int, const char *);
290 struct servent
*getservent(void);
291 void sethostent(int);
292 /* void sethostfile(const char *); */
294 void setprotoent(int);
295 void setservent(int);
297 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
298 void freehostent(struct hostent
*);
299 struct hostent
*gethostbyname2(const char *, int);
300 struct hostent
*getipnodebyaddr(const void *, size_t, int, int *);
301 struct hostent
*getipnodebyname(const char *, int, int, int *);
302 struct rpcent
*getrpcbyname(const char *name
);
304 struct rpcent
*getrpcbynumber(int number
);
306 struct rpcent
*getrpcbynumber(long number
);
308 struct rpcent
*getrpcent(void);
309 void setrpcent(int stayopen
);
310 void endrpcent(void);
311 void herror(const char *);
312 const char *hstrerror(int);
313 int innetgr(const char *, const char *, const char *, const char *);
314 int getnetgrent(char **, char **, char **);
315 void endnetgrent(void);
316 void setnetgrent(const char *);
317 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
321 #endif /* !_NETDB_H_ */