netdb.h revision 1.44 1 /* $NetBSD: netdb.h,v 1.44 2004/08/17 02:29:56 ginsbach Exp $ */
2
3 /*
4 * Copyright (c) 1980, 1983, 1988, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 * -
31 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
32 *
33 * Permission to use, copy, modify, and distribute this software for any
34 * purpose with or without fee is hereby granted, provided that the above
35 * copyright notice and this permission notice appear in all copies, and that
36 * the name of Digital Equipment Corporation not be used in advertising or
37 * publicity pertaining to distribution of the document or software without
38 * specific, written prior permission.
39 *
40 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
41 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
42 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
43 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
44 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
45 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
46 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
47 * SOFTWARE.
48 * -
49 * Portions Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
50 * All rights reserved.
51 *
52 * Redistribution and use in source and binary forms, with or without
53 * modification, are permitted provided that the following conditions
54 * are met:
55 * 1. Redistributions of source code must retain the above copyright
56 * notice, this list of conditions and the following disclaimer.
57 * 2. Redistributions in binary form must reproduce the above copyright
58 * notice, this list of conditions and the following disclaimer in the
59 * documentation and/or other materials provided with the distribution.
60 * 3. All advertising materials mentioning features or use of this software
61 * must display the following acknowledgement:
62 * This product includes software developed by WIDE Project and
63 * its contributors.
64 * 4. Neither the name of the project nor the names of its contributors
65 * may be used to endorse or promote products derived from this software
66 * without specific prior written permission.
67 *
68 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
69 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
70 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
71 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
72 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
73 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
74 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
75 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
76 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
77 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
78 * SUCH DAMAGE.
79 * -
80 * --Copyright--
81 */
82
83 /*
84 * @(#)netdb.h 8.1 (Berkeley) 6/2/93
85 * Id: netdb.h,v 1.12.2.1.4.4 2004/03/16 02:19:19 marka Exp
86 */
87
88 #ifndef _NETDB_H_
89 #define _NETDB_H_
90
91 #include <machine/ansi.h>
92 #include <machine/endian_machdep.h>
93 #include <sys/ansi.h>
94 #include <sys/cdefs.h>
95 #include <sys/featuretest.h>
96 #include <inttypes.h>
97 /*
98 * Data types
99 */
100 #ifndef socklen_t
101 typedef __socklen_t socklen_t;
102 #define socklen_t __socklen_t
103 #endif
104
105 #ifdef _BSD_SIZE_T_
106 typedef _BSD_SIZE_T_ size_t;
107 #undef _BSD_SIZE_T_
108 #endif
109
110 #if defined(_NETBSD_SOURCE)
111 #ifndef _PATH_HEQUIV
112 #define _PATH_HEQUIV "/etc/hosts.equiv"
113 #endif
114 #ifndef _PATH_HOSTS
115 #define _PATH_HOSTS "/etc/hosts"
116 #endif
117 #ifndef _PATH_NETWORKS
118 #define _PATH_NETWORKS "/etc/networks"
119 #endif
120 #ifndef _PATH_PROTOCOLS
121 #define _PATH_PROTOCOLS "/etc/protocols"
122 #endif
123 #ifndef _PATH_SERVICES
124 #define _PATH_SERVICES "/etc/services"
125 #endif
126 #endif
127
128 __BEGIN_DECLS
129 extern int h_errno;
130 __END_DECLS
131
132 /*
133 * Structures returned by network data base library. All addresses are
134 * supplied in host order, and returned in network order (suitable for
135 * use in system calls).
136 */
137 struct hostent {
138 char *h_name; /* official name of host */
139 char **h_aliases; /* alias list */
140 int h_addrtype; /* host address type */
141 int h_length; /* length of address */
142 char **h_addr_list; /* list of addresses from name server */
143 #define h_addr h_addr_list[0] /* address, for backward compatiblity */
144 };
145
146 /*
147 * Assumption here is that a network number
148 * fits in an unsigned long -- probably a poor one.
149 */
150 struct netent {
151 char *n_name; /* official name of net */
152 char **n_aliases; /* alias list */
153 int n_addrtype; /* net address type */
154 #if (defined(__sparc__) && defined(_LP64)) || \
155 (defined(__sh__) && defined(_LP64) && (_BYTE_ORDER == _BIG_ENDIAN))
156 int __n_pad0; /* ABI compatibility */
157 #endif
158 uint32_t n_net; /* network # */
159 #if defined(__alpha__) || (defined(__i386__) && defined(_LP64)) || \
160 (defined(__sh__) && defined(_LP64) && (_BYTE_ORDER == _LITTLE_ENDIAN))
161 int __n_pad0; /* ABI compatibility */
162 #endif
163 };
164
165 struct servent {
166 char *s_name; /* official service name */
167 char **s_aliases; /* alias list */
168 int s_port; /* port # */
169 char *s_proto; /* protocol to use */
170 };
171
172 struct protoent {
173 char *p_name; /* official protocol name */
174 char **p_aliases; /* alias list */
175 int p_proto; /* protocol # */
176 };
177
178 /*
179 * Note: ai_addrlen used to be a size_t, per RFC 2553.
180 * In XNS5.2, and subsequently in POSIX-2001 and
181 * draft-ietf-ipngwg-rfc2553bis-02.txt it was changed to a socklen_t.
182 * To accomodate for this while preserving binary compatibility with the
183 * old interface, we prepend or append 32 bits of padding, depending on
184 * the (LP64) architecture's endianness.
185 *
186 * This should be deleted the next time the libc major number is
187 * incremented.
188 */
189 #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \
190 defined(_NETBSD_SOURCE)
191 struct addrinfo {
192 int ai_flags; /* AI_xxx */
193 int ai_family; /* PF_xxx */
194 int ai_socktype; /* SOCK_xxx */
195 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
196 #if defined(__sparc__) && defined(_LP64)
197 int __ai_pad0; /* ABI compatibility */
198 #endif
199 socklen_t ai_addrlen; /* length of ai_addr */
200 #if defined(__alpha__) || (defined(__i386__) && defined(_LP64))
201 int __ai_pad0; /* ABI compatbility */
202 #endif
203 char *ai_canonname; /* canonical name for hostname */
204 struct sockaddr *ai_addr; /* binary address */
205 struct addrinfo *ai_next; /* next structure in linked list */
206 };
207 #endif
208
209 /*
210 * Error return codes from gethostbyname() and gethostbyaddr()
211 * (left in extern int h_errno).
212 */
213
214 #if defined(_NETBSD_SOURCE)
215 #define NETDB_INTERNAL -1 /* see errno */
216 #define NETDB_SUCCESS 0 /* no problem */
217 #endif
218 #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */
219 #define TRY_AGAIN 2 /* Non-Authoritive Host not found, or SERVERFAIL */
220 #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
221 #define NO_DATA 4 /* Valid name, no data record of requested type */
222 #if defined(_NETBSD_SOURCE)
223 #define NO_ADDRESS NO_DATA /* no address, look for MX record */
224 #endif
225
226 /*
227 * Error return codes from getaddrinfo()
228 */
229 #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \
230 defined(_NETBSD_SOURCE)
231 #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */
232 #define EAI_AGAIN 2 /* temporary failure in name resolution */
233 #define EAI_BADFLAGS 3 /* invalid value for ai_flags */
234 #define EAI_FAIL 4 /* non-recoverable failure in name resolution */
235 #define EAI_FAMILY 5 /* ai_family not supported */
236 #define EAI_MEMORY 6 /* memory allocation failure */
237 #define EAI_NODATA 7 /* no address associated with hostname */
238 #define EAI_NONAME 8 /* hostname nor servname provided, or not known */
239 #define EAI_SERVICE 9 /* servname not supported for ai_socktype */
240 #define EAI_SOCKTYPE 10 /* ai_socktype not supported */
241 #define EAI_SYSTEM 11 /* system error returned in errno */
242 #define EAI_BADHINTS 12
243 #define EAI_PROTOCOL 13
244 #define EAI_MAX 14
245 #endif /* _POSIX_C_SOURCE >= 200112 || _XOPEN_SOURCE >= 520 || _NETBSD_SOURCE */
246
247 /*
248 * Flag values for getaddrinfo()
249 */
250 #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \
251 defined(_NETBSD_SOURCE)
252 #define AI_PASSIVE 0x00000001 /* get address to use bind() */
253 #define AI_CANONNAME 0x00000002 /* fill ai_canonname */
254 #define AI_NUMERICHOST 0x00000004 /* prevent host name resolution */
255 #define AI_NUMERICSERV 0x00000008 /* prevent service name resolution */
256 /* valid flags for addrinfo (not a standard def, apps should not use it) */
257 #define AI_MASK \
258 (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV)
259
260 #if 0
261 /*
262 * Flag values for getipnodebyname()
263 */
264 #define AI_V4MAPPED 0x00000008
265 #define AI_ALL 0x00000010
266 #define AI_ADDRCONFIG 0x00000020
267 #define AI_DEFAULT (AI_V4MAPPED|AI_ADDRCONFIG)
268 #endif
269 #endif
270
271 #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \
272 defined(_NETBSD_SOURCE)
273 /*
274 * Constants for getnameinfo()
275 */
276 #if defined(_NETBSD_SOURCE)
277 #define NI_MAXHOST 1025
278 #define NI_MAXSERV 32
279 #endif
280
281 /*
282 * Flag values for getnameinfo()
283 */
284 #define NI_NOFQDN 0x00000001
285 #define NI_NUMERICHOST 0x00000002
286 #define NI_NAMEREQD 0x00000004
287 #define NI_NUMERICSERV 0x00000008
288 #define NI_DGRAM 0x00000010
289 #if defined(_NETBSD_SOURCE)
290 #define NI_WITHSCOPEID 0x00000020
291 #endif
292 #define NI_NUMERICSCOPE 0x00000040
293
294 /*
295 * Scope delimit character
296 */
297 #if defined(_NETBSD_SOURCE)
298 #define SCOPE_DELIMITER '%'
299 #endif
300 #endif /* (_POSIX_C_SOURCE - 0) >= 200112L || ... */
301
302 __BEGIN_DECLS
303 void endhostent __P((void));
304 void endnetent __P((void));
305 void endprotoent __P((void));
306 void endservent __P((void));
307 #if (_XOPEN_SOURCE - 0) >= 520 && (_XOPEN_SOURCE - 0) < 600 || \
308 defined(_NETBSD_SOURCE)
309 #if 0 /* we do not ship this */
310 void freehostent __P((struct hostent *));
311 #endif
312 #endif
313 struct hostent *gethostbyaddr __P((const char *, socklen_t, int));
314 struct hostent *gethostbyname __P((const char *));
315 #if defined(_NETBSD_SOURCE)
316 struct hostent *gethostbyname2 __P((const char *, int));
317 #endif
318 struct hostent *gethostent __P((const char *, int));
319 #if (_XOPEN_SOURCE - 0) >= 520 && (_XOPEN_SOURCE - 0) < 600 || \
320 defined(_NETBSD_SOURCE)
321 #if 0 /* we do not ship these */
322 struct hostent *getipnodebyaddr __P((const void *, size_t, int, int *));
323 struct hostent *getipnodebyname __P((const char *, int, int, int *));
324 #endif
325 #endif
326 struct netent *getnetbyaddr __P((uint32_t, int));
327 struct netent *getnetbyname __P((const char *));
328 struct netent *getnetent __P((void));
329 struct protoent *getprotobyname __P((const char *));
330 struct protoent *getprotobynumber __P((int));
331 struct protoent *getprotoent __P((void));
332 struct servent *getservbyname __P((const char *, const char *));
333 struct servent *getservbyport __P((int, const char *));
334 struct servent *getservent __P((void));
335 #if defined(_NETBSD_SOURCE)
336 void herror __P((const char *));
337 const char *hstrerror __P((int));
338 #endif
339 void sethostent __P((int));
340 #if defined(_NETBSD_SOURCE)
341 /* void sethostfile __P((const char *)); */
342 #endif
343 void setnetent __P((int));
344 void setprotoent __P((int));
345 #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \
346 defined(_NETBSD_SOURCE)
347 void setservent __P((int));
348 int getaddrinfo __P((const char *, const char *,
349 const struct addrinfo *, struct addrinfo **));
350 int getnameinfo __P((const struct sockaddr *, socklen_t, char *,
351 socklen_t, char *, socklen_t, int));
352 void freeaddrinfo __P((struct addrinfo *));
353 const char *gai_strerror __P((int));
354 #endif
355 void setservent __P((int));
356
357 #if defined(_NETBSD_SOURCE) && defined(_LIBC)
358
359 struct protoent_data {
360 FILE *fp;
361 struct protoent proto;
362 char **aliases;
363 size_t maxaliases;
364 int stayopen;
365 char *line;
366 void *dummy;
367 };
368
369 struct protoent *getprotoent_r __P((struct protoent *, struct protoent_data *));
370 struct protoent *getprotobyname_r __P((const char *,
371 struct protoent *, struct protoent_data *));
372 struct protoent *getprotobynumber_r __P((int,
373 struct protoent *, struct protoent_data *));
374 void setprotoent_r __P((int, struct protoent_data *));
375 void endprotoent_r __P((struct protoent_data *));
376
377 struct servent_data {
378 FILE *fp;
379 struct servent serv;
380 char **aliases;
381 size_t maxaliases;
382 int stayopen;
383 char *line;
384 void *dummy;
385 };
386
387 struct servent *getservent_r __P((struct servent *, struct servent_data *));
388 struct servent *getservbyname_r __P((const char *, const char *,
389 struct servent *, struct servent_data *));
390 struct servent *getservbyport_r __P((int, const char *,
391 struct servent *, struct servent_data *));
392 void setservent_r __P((int, struct servent_data *));
393 void endservent_r __P((struct servent_data *));
394
395 #endif /* _NETBSD_SOURCE && _LIBC */
396 __END_DECLS
397
398 #endif /* !_NETDB_H_ */
399