Libinfo-221.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 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
57 *
58 * Permission to use, copy, modify, and distribute this software for any
59 * purpose with or without fee is hereby granted, provided that the above
60 * copyright notice and this permission notice appear in all copies, and that
61 * the name of Digital Equipment Corporation not be used in advertising or
62 * publicity pertaining to distribution of the document or software without
63 * specific, written prior permission.
64 *
65 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
66 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
67 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
68 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
69 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
70 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
71 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
72 * SOFTWARE.
73 * -
74 * --Copyright--
75 */
76
77 /*
78 * @(#)netdb.h 8.1 (Berkeley) 6/2/93
79 */
80
81 #ifndef _NETDB_H_
82 #define _NETDB_H_
83
84 #include <stdint.h>
85 #include <_types.h>
86 #include <netinet/in.h> /* IPPORT_RESERVED */
87
88 #ifndef _SIZE_T
89 #define _SIZE_T
90 typedef __darwin_size_t size_t;
91 #endif
92
93 #ifndef _SOCKLEN_T
94 #define _SOCKLEN_T
95 typedef __darwin_socklen_t socklen_t;
96 #endif
97
98 #define _PATH_HEQUIV "/etc/hosts.equiv"
99 #define _PATH_HOSTS "/etc/hosts"
100 #define _PATH_NETWORKS "/etc/networks"
101 #define _PATH_PROTOCOLS "/etc/protocols"
102 #define _PATH_SERVICES "/etc/services"
103
104 extern int h_errno;
105
106 #ifndef IPPORT_RESERVED
107 #define IPPORT_RESERVED __DARWIN_IPPORT_RESERVED
108 #endif
109
110 /*
111 * Structures returned by network data base library. All addresses are
112 * supplied in host order, and returned in network order (suitable for
113 * use in system calls).
114 */
115 struct hostent {
116 char *h_name; /* official name of host */
117 char **h_aliases; /* alias list */
118 int h_addrtype; /* host address type */
119 int h_length; /* length of address */
120 char **h_addr_list; /* list of addresses from name server */
121 #ifndef _POSIX_C_SOURCE
122 #define h_addr h_addr_list[0] /* address, for backward compatiblity */
123 #endif /* !_POSIX_C_SOURCE */
124 };
125
126 /*
127 * Assumption here is that a network number
128 * fits in an unsigned long -- probably a poor one.
129 */
130 struct netent {
131 char *n_name; /* official name of net */
132 char **n_aliases; /* alias list */
133 int n_addrtype; /* net address type */
134 uint32_t n_net; /* network # */
135 };
136
137 struct servent {
138 char *s_name; /* official service name */
139 char **s_aliases; /* alias list */
140 int s_port; /* port # */
141 char *s_proto; /* protocol to use */
142 };
143
144 struct protoent {
145 char *p_name; /* official protocol name */
146 char **p_aliases; /* alias list */
147 int p_proto; /* protocol # */
148 };
149
150 struct addrinfo {
151 int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
152 int ai_family; /* PF_xxx */
153 int ai_socktype; /* SOCK_xxx */
154 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
155 socklen_t ai_addrlen; /* length of ai_addr */
156 char *ai_canonname; /* canonical name for hostname */
157 struct sockaddr *ai_addr; /* binary address */
158 struct addrinfo *ai_next; /* next structure in linked list */
159 };
160
161 #ifndef _POSIX_C_SOURCE
162 struct rpcent {
163 char *r_name; /* name of server for this rpc program */
164 char **r_aliases; /* alias list */
165 int r_number; /* rpc program number */
166 };
167 #endif /* !_POSIX_C_SOURCE */
168
169 /*
170 * Error return codes from gethostbyname() and gethostbyaddr()
171 * (left in extern int h_errno).
172 */
173 #ifndef _POSIX_C_SOURCE
174 #define NETDB_INTERNAL -1 /* see errno */
175 #define NETDB_SUCCESS 0 /* no problem */
176 #endif /* !_POSIX_C_SOURCE */
177 #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */
178 #define TRY_AGAIN 2 /* Non-Authoritative Host not found, or SERVERFAIL */
179 #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
180 #define NO_DATA 4 /* Valid name, no data record of requested type */
181 #ifndef _POSIX_C_SOURCE
182 #define NO_ADDRESS NO_DATA /* no address, look for MX record */
183 #endif /* !_POSIX_C_SOURCE */
184 /*
185 * Error return codes from getaddrinfo()
186 */
187 #ifndef _POSIX_C_SOURCE
188 #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */
189 #endif /* !_POSIX_C_SOURCE */
190 #define EAI_AGAIN 2 /* temporary failure in name resolution */
191 #define EAI_BADFLAGS 3 /* invalid value for ai_flags */
192 #define EAI_FAIL 4 /* non-recoverable failure in name resolution */
193 #define EAI_FAMILY 5 /* ai_family not supported */
194 #define EAI_MEMORY 6 /* memory allocation failure */
195 #ifndef _POSIX_C_SOURCE
196 #define EAI_NODATA 7 /* no address associated with hostname */
197 #endif /* !_POSIX_C_SOURCE */
198 #define EAI_NONAME 8 /* hostname nor servname provided, or not known */
199 #define EAI_SERVICE 9 /* servname not supported for ai_socktype */
200 #define EAI_SOCKTYPE 10 /* ai_socktype not supported */
201 #define EAI_SYSTEM 11 /* system error returned in errno */
202 #ifndef _POSIX_C_SOURCE
203 #define EAI_BADHINTS 12
204 #define EAI_PROTOCOL 13
205 #define EAI_MAX 14
206 #else /* _POSIX_C_SOURCE */
207 #define EAI_OVERFLOW 14 /* An argument buffer overflowed */
208 #endif /* !_POSIX_C_SOURCE */
209
210 /*
211 * Flag values for getaddrinfo()
212 */
213 #define AI_PASSIVE 0x00000001 /* get address to use bind() */
214 #define AI_CANONNAME 0x00000002 /* fill ai_canonname */
215 #define AI_NUMERICHOST 0x00000004 /* prevent name resolution */
216 /* valid flags for addrinfo */
217 #ifndef _POSIX_C_SOURCE
218 #define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST)
219 #endif /* !_POSIX_C_SOURCE */
220 #define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */
221 #ifndef _POSIX_C_SOURCE
222 #define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */
223 #endif /* !_POSIX_C_SOURCE */
224 #define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */
225 #define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */
226 /* special recommended flags for getipnodebyname */
227 #ifndef _POSIX_C_SOURCE
228 #define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG)
229 #endif /* !_POSIX_C_SOURCE */
230
231 /*
232 * Constants for getnameinfo()
233 */
234 #ifndef _POSIX_C_SOURCE
235 #define NI_MAXHOST 1025
236 #define NI_MAXSERV 32
237 #endif /* !_POSIX_C_SOURCE */
238 /*
239 * Flag values for getnameinfo()
240 */
241 #define NI_NOFQDN 0x00000001
242 #define NI_NUMERICHOST 0x00000002
243 #define NI_NAMEREQD 0x00000004
244 #define NI_NUMERICSERV 0x00000008
245 #define NI_DGRAM 0x00000010
246 #ifndef _POSIX_C_SOURCE
247 #define NI_WITHSCOPEID 0x00000020
248
249 /*
250 * Scope delimit character
251 */
252 #define SCOPE_DELIMITER '%'
253 #endif /* !_POSIX_C_SOURCE */
254
255 __BEGIN_DECLS
256 void endhostent(void);
257 void endnetent(void);
258 void endprotoent(void);
259 void endservent(void);
260
261 void freeaddrinfo(struct addrinfo *);
262 const char *gai_strerror(int);
263 int getaddrinfo(const char * __restrict, const char * __restrict,
264 const struct addrinfo * __restrict,
265 struct addrinfo ** __restrict);
266 struct hostent *gethostbyaddr(const void *, socklen_t, int);
267 struct hostent *gethostbyname(const char *);
268 struct hostent *gethostent(void);
269 int getnameinfo(const struct sockaddr * __restrict, socklen_t,
270 char * __restrict, socklen_t, char * __restrict,
271 socklen_t, int);
272 struct netent *getnetbyaddr(uint32_t, int);
273 struct netent *getnetbyname(const char *);
274 struct netent *getnetent(void);
275 struct protoent *getprotobyname(const char *);
276 struct protoent *getprotobynumber(int);
277 struct protoent *getprotoent(void);
278 struct servent *getservbyname(const char *, const char *);
279 struct servent *getservbyport(int, const char *);
280 struct servent *getservent(void);
281 void sethostent(int);
282 /* void sethostfile(const char *); */
283 void setnetent(int);
284 void setprotoent(int);
285 void setservent(int);
286 #ifndef _POSIX_C_SOURCE
287 void freehostent(struct hostent *);
288 struct hostent *gethostbyname2(const char *, int);
289 struct hostent *getipnodebyaddr(const void *, size_t, int, int *);
290 struct hostent *getipnodebyname(const char *, int, int, int *);
291 struct rpcent *getrpcbyname(const char *name);
292 struct rpcent *getrpcbynumber(long number);
293 struct rpcent *getrpcent(void);
294 void setrpcent(int stayopen);
295 void endrpcent(void);
296 void herror(const char *);
297 const char *hstrerror(int);
298 int innetgr(const char *, const char *, const char *, const char *);
299 #endif /* !_POSIX_C_SOURCE */
300 __END_DECLS
301
302 #endif /* !_NETDB_H_ */