]>
git.saurik.com Git - apple/libinfo.git/blob - lookup.subproj/netdb.h
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
87 #include <sys/_types/_size_t.h>
88 #include <sys/_types/_socklen_t.h>
91 #include <netinet/in.h> /* IPPORT_RESERVED */
94 # define _PATH_HEQUIV "/etc/hosts.equiv"
96 #define _PATH_HOSTS "/etc/hosts"
97 #define _PATH_NETWORKS "/etc/networks"
98 #define _PATH_PROTOCOLS "/etc/protocols"
99 #define _PATH_SERVICES "/etc/services"
103 #ifndef IPPORT_RESERVED
104 #define IPPORT_RESERVED __DARWIN_IPPORT_RESERVED
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).
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) */
124 * Assumption here is that a network number
125 * fits in an unsigned long -- probably a poor one.
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 # */
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 */
142 char *p_name
; /* official protocol name */
143 char **p_aliases
; /* alias list */
144 int p_proto
; /* protocol # */
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 */
158 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
160 char *r_name
; /* name of server for this rpc program */
161 char **r_aliases
; /* alias list */
162 int r_number
; /* rpc program number */
164 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
167 * Error return codes from gethostbyname() and gethostbyaddr()
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) */
182 * Error return codes from getaddrinfo()
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)
206 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
209 * Flag values for getaddrinfo()
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)
218 (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | \
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 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
234 * Constants for getnameinfo()
236 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
237 #define NI_MAXHOST 1025
238 #define NI_MAXSERV 32
239 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
241 * Flag values for getnameinfo()
243 #define NI_NOFQDN 0x00000001
244 #define NI_NUMERICHOST 0x00000002
245 #define NI_NAMEREQD 0x00000004
246 #define NI_NUMERICSERV 0x00000008
247 #define NI_DGRAM 0x00000010
248 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
249 #define NI_WITHSCOPEID 0x00000020
252 * Scope delimit character
254 #define SCOPE_DELIMITER '%'
255 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
259 void endhostent(void);
260 void endnetent(void);
261 void endprotoent(void);
262 void endservent(void);
264 void freeaddrinfo(struct addrinfo
*);
265 const char *gai_strerror(int);
266 int getaddrinfo(const char * __restrict
, const char * __restrict
,
267 const struct addrinfo
* __restrict
,
268 struct addrinfo
** __restrict
);
269 struct hostent
*gethostbyaddr(const void *, socklen_t
, int);
270 struct hostent
*gethostbyname(const char *);
271 struct hostent
*gethostent(void);
272 int getnameinfo(const struct sockaddr
* __restrict
, socklen_t
,
273 char * __restrict
, socklen_t
, char * __restrict
,
275 struct netent
*getnetbyaddr(uint32_t, int);
276 struct netent
*getnetbyname(const char *);
277 struct netent
*getnetent(void);
278 struct protoent
*getprotobyname(const char *);
279 struct protoent
*getprotobynumber(int);
280 struct protoent
*getprotoent(void);
281 struct servent
*getservbyname(const char *, const char *);
282 struct servent
*getservbyport(int, const char *);
283 struct servent
*getservent(void);
284 void sethostent(int);
285 /* void sethostfile(const char *); */
287 void setprotoent(int);
288 void setservent(int);
290 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
291 void freehostent(struct hostent
*);
292 struct hostent
*gethostbyname2(const char *, int);
293 struct hostent
*getipnodebyaddr(const void *, size_t, int, int *);
294 struct hostent
*getipnodebyname(const char *, int, int, int *);
295 struct rpcent
*getrpcbyname(const char *name
);
297 struct rpcent
*getrpcbynumber(int number
);
299 struct rpcent
*getrpcbynumber(long number
);
301 struct rpcent
*getrpcent(void);
302 void setrpcent(int stayopen
);
303 void endrpcent(void);
304 void herror(const char *);
305 const char *hstrerror(int);
306 int innetgr(const char *, const char *, const char *, const char *);
307 int getnetgrent(char **, char **, char **);
308 void endnetgrent(void);
309 void setnetgrent(const char *);
310 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
314 #endif /* !_NETDB_H_ */