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