Merge from vendor branch NTPD:
[dragonfly.git] / contrib / bind-9.2.4rc7 / lib / bind / include / netdb.h
1 /*
2  * ++Copyright++ 1980, 1983, 1988, 1993
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. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *      This product includes software developed by the University of
18  *      California, Berkeley and its contributors.
19  * 4. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  * -
35  * Portions Copyright (c) 1993 by Digital Equipment Corporation.
36  *
37  * Permission to use, copy, modify, and distribute this software for any
38  * purpose with or without fee is hereby granted, provided that the above
39  * copyright notice and this permission notice appear in all copies, and that
40  * the name of Digital Equipment Corporation not be used in advertising or
41  * publicity pertaining to distribution of the document or software without
42  * specific, written prior permission.
43  *
44  * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
45  * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
46  * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
47  * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
48  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
49  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
50  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
51  * SOFTWARE.
52  * -
53  * Portions Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
54  * All rights reserved.
55  * 
56  * Redistribution and use in source and binary forms, with or without
57  * modification, are permitted provided that the following conditions
58  * are met:
59  * 1. Redistributions of source code must retain the above copyright
60  *    notice, this list of conditions and the following disclaimer.
61  * 2. Redistributions in binary form must reproduce the above copyright
62  *    notice, this list of conditions and the following disclaimer in the
63  *    documentation and/or other materials provided with the distribution.
64  * 3. All advertising materials mentioning features or use of this software
65  *    must display the following acknowledgement:
66  *    This product includes software developed by WIDE Project and
67  *    its contributors.
68  * 4. Neither the name of the project nor the names of its contributors
69  *    may be used to endorse or promote products derived from this software
70  *    without specific prior written permission.
71  * 
72  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
73  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
74  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
75  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
76  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
77  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
78  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
79  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
80  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
81  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
82  * SUCH DAMAGE.
83  * -
84  * --Copyright--
85  */
86
87 /*
88  *      @(#)netdb.h     8.1 (Berkeley) 6/2/93
89  *      $Id: netdb.h,v 1.12.2.5 2004/03/16 02:25:06 marka Exp $
90  */
91
92 #ifndef _NETDB_H_
93 #define _NETDB_H_
94
95 #include <sys/param.h>
96 #include <sys/types.h>
97 #if (!defined(BSD)) || (BSD < 199306)
98 # include <sys/bitypes.h>
99 #endif
100 #include <sys/cdefs.h>
101 #include <sys/socket.h>
102 #include <netinet/in.h>
103 #include <stdio.h>
104
105 #ifndef _PATH_HEQUIV
106 #define _PATH_HEQUIV    "/etc/hosts.equiv"
107 #endif
108 #ifndef _PATH_HOSTS
109 #define _PATH_HOSTS     "/etc/hosts"
110 #endif
111 #ifndef _PATH_NETWORKS
112 #define _PATH_NETWORKS  "/etc/networks"
113 #endif
114 #ifndef _PATH_PROTOCOLS
115 #define _PATH_PROTOCOLS "/etc/protocols"
116 #endif
117 #ifndef _PATH_SERVICES
118 #define _PATH_SERVICES  "/etc/services"
119 #endif
120
121 #if (__GLIBC__ > 2 || __GLIBC__ == 2 &&  __GLIBC_MINOR__ >= 3)
122 #define __h_errno __h_errno_location
123 #endif
124 __BEGIN_DECLS
125 extern int * __h_errno __P((void));
126 __END_DECLS
127 #if defined(_REENTRANT) || \
128     (__GLIBC__ > 2 || __GLIBC__ == 2 &&  __GLIBC_MINOR__ >= 3)
129 #define h_errno (*__h_errno())
130 #else
131 extern int h_errno;
132 #endif
133
134 /*
135  * Structures returned by network data base library.  All addresses are
136  * supplied in host order, and returned in network order (suitable for
137  * use in system calls).
138  */
139 struct  hostent {
140         char    *h_name;        /* official name of host */
141         char    **h_aliases;    /* alias list */
142         int     h_addrtype;     /* host address type */
143         int     h_length;       /* length of address */
144         char    **h_addr_list;  /* list of addresses from name server */
145 #define h_addr  h_addr_list[0]  /* address, for backward compatiblity */
146 };
147
148 /*
149  * Assumption here is that a network number
150  * fits in an unsigned long -- probably a poor one.
151  */
152 struct  netent {
153         char            *n_name;        /* official name of net */
154         char            **n_aliases;    /* alias list */
155         int             n_addrtype;     /* net address type */
156         unsigned long   n_net;          /* network # */
157 };
158
159 struct  servent {
160         char    *s_name;        /* official service name */
161         char    **s_aliases;    /* alias list */
162         int     s_port;         /* port # */
163         char    *s_proto;       /* protocol to use */
164 };
165
166 struct  protoent {
167         char    *p_name;        /* official protocol name */
168         char    **p_aliases;    /* alias list */
169         int     p_proto;        /* protocol # */
170 };
171
172 struct  addrinfo {
173         int             ai_flags;       /* AI_PASSIVE, AI_CANONNAME */
174         int             ai_family;      /* PF_xxx */
175         int             ai_socktype;    /* SOCK_xxx */
176         int             ai_protocol;    /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
177 #if defined(sun) && defined(_SOCKLEN_T)
178 #ifdef __sparc9
179         int             _ai_pad;
180 #endif
181         socklen_t       ai_addrlen;
182 #else
183         size_t          ai_addrlen;     /* length of ai_addr */
184 #endif
185 #ifdef __linux
186         struct sockaddr *ai_addr;       /* binary address */
187         char            *ai_canonname;  /* canonical name for hostname */
188 #else
189         char            *ai_canonname;  /* canonical name for hostname */
190         struct sockaddr *ai_addr;       /* binary address */
191 #endif
192         struct addrinfo *ai_next;       /* next structure in linked list */
193 };
194
195 /*
196  * Error return codes from gethostbyname() and gethostbyaddr()
197  * (left in extern int h_errno).
198  */
199
200 #define NETDB_INTERNAL  -1      /* see errno */
201 #define NETDB_SUCCESS   0       /* no problem */
202 #define HOST_NOT_FOUND  1 /* Authoritative Answer Host not found */
203 #define TRY_AGAIN       2 /* Non-Authoritive Host not found, or SERVERFAIL */
204 #define NO_RECOVERY     3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
205 #define NO_DATA         4 /* Valid name, no data record of requested type */
206 #define NO_ADDRESS      NO_DATA         /* no address, look for MX record */
207
208 /*
209  * Error return codes from getaddrinfo()
210  */
211 #define EAI_ADDRFAMILY   1      /* address family for hostname not supported */
212 #define EAI_AGAIN        2      /* temporary failure in name resolution */
213 #define EAI_BADFLAGS     3      /* invalid value for ai_flags */
214 #define EAI_FAIL         4      /* non-recoverable failure in name resolution */
215 #define EAI_FAMILY       5      /* ai_family not supported */
216 #define EAI_MEMORY       6      /* memory allocation failure */
217 #define EAI_NODATA       7      /* no address associated with hostname */
218 #define EAI_NONAME       8      /* hostname nor servname provided, or not known */
219 #define EAI_SERVICE      9      /* servname not supported for ai_socktype */
220 #define EAI_SOCKTYPE    10      /* ai_socktype not supported */
221 #define EAI_SYSTEM      11      /* system error returned in errno */
222 #define EAI_BADHINTS    12
223 #define EAI_PROTOCOL    13
224 #define EAI_MAX         14
225
226 /*
227  * Flag values for getaddrinfo()
228  */
229 #define AI_PASSIVE      0x00000001
230 #define AI_CANONNAME    0x00000002
231 #define AI_NUMERICHOST  0x00000004
232 #define AI_MASK         0x00000007
233
234 /*
235  * Flag values for getipnodebyname()
236  */
237 #define AI_V4MAPPED     0x00000008
238 #define AI_ALL          0x00000010
239 #define AI_ADDRCONFIG   0x00000020
240 #define AI_DEFAULT      (AI_V4MAPPED|AI_ADDRCONFIG)
241
242 /*
243  * Constants for getnameinfo()
244  */
245 #define NI_MAXHOST      1025
246 #define NI_MAXSERV      32
247
248 /*
249  * Flag values for getnameinfo()
250  */
251 #define NI_NOFQDN       0x00000001
252 #define NI_NUMERICHOST  0x00000002
253 #define NI_NAMEREQD     0x00000004
254 #define NI_NUMERICSERV  0x00000008
255 #define NI_DGRAM        0x00000010
256 #define NI_WITHSCOPEID  0x00000020
257 #define NI_NUMERICSCOPE 0x00000040
258
259 /*
260  * Scope delimit character
261  */
262 #define SCOPE_DELIMITER '%'
263
264
265 #ifdef _REENTRANT
266 #if defined (__hpux) || defined(__osf__) || defined(_AIX)
267 #define _MAXALIASES     35
268 #define _MAXLINELEN     1024
269 #define _MAXADDRS       35
270 #define _HOSTBUFSIZE    (BUFSIZ + 1)
271
272 struct hostent_data {
273         struct in_addr  host_addr;
274         char            *h_addr_ptrs[_MAXADDRS + 1];
275         char            hostaddr[_MAXADDRS];
276         char            hostbuf[_HOSTBUFSIZE];
277         char            *host_aliases[_MAXALIASES];
278         char            *host_addrs[2];
279         FILE            *hostf;
280 #ifdef __osf__
281         int             svc_gethostflag;
282         int             svc_gethostbind;
283 #endif
284 #ifdef __hpux
285         short           _nsw_src;
286         short           _flags;
287         char            *current;
288         int             currentlen;
289 #endif
290 };
291
292 struct  netent_data {
293         FILE    *net_fp;
294 #ifdef __osf__
295         char    line[_MAXLINELEN];
296 #endif
297 #ifdef __hpux
298         char    line[_MAXLINELEN+1];
299 #endif
300         char    *net_aliases[_MAXALIASES];
301 #ifdef __osf__
302         int     _net_stayopen;
303         int     svc_getnetflag;
304 #endif
305 #ifdef __hpux
306         short   _nsw_src;
307         short   _flags;
308         char    *current;
309         int     currentlen;
310 #endif
311 };
312
313 struct  protoent_data {
314         FILE    *proto_fp;
315 #ifdef __osf__
316         char    line[1024];
317 #endif
318 #ifdef __hpux
319         char    line[_MAXLINELEN+1];
320 #endif
321         char    *proto_aliases[_MAXALIASES];
322 #ifdef __osf__
323         int     _proto_stayopen;
324         int     svc_getprotoflag;
325 #endif
326 #ifdef __hpux
327         short   _nsw_src;
328         short   _flags;
329         char    *current;
330         int     currentlen;
331 #endif
332 };
333
334 struct  servent_data {
335         FILE    *serv_fp;
336 #ifdef __osf__
337         char    line[_MAXLINELEN];
338 #endif
339 #ifdef __hpux
340         char    line[_MAXLINELEN+1];
341 #endif
342         char    *serv_aliases[_MAXALIASES];
343 #ifdef __osf__
344         int     _serv_stayopen;
345         int     svc_getservflag;
346 #endif
347 #ifdef __hpux
348         short   _nsw_src;
349         short   _flags;
350         char    *current;
351         int     currentlen;
352 #endif
353 };
354 #endif
355 #endif
356 __BEGIN_DECLS
357 void            endhostent __P((void));
358 void            endnetent __P((void));
359 void            endprotoent __P((void));
360 void            endservent __P((void));
361 void            freehostent __P((struct hostent *));
362 struct hostent  *gethostbyaddr __P((const char *, int, int));
363 struct hostent  *gethostbyname __P((const char *));
364 struct hostent  *gethostbyname2 __P((const char *, int));
365 struct hostent  *gethostent __P((void));
366 struct hostent  *getipnodebyaddr __P((const void *, size_t, int, int *));
367 struct hostent  *getipnodebyname __P((const char *, int, int, int *));
368 struct netent   *getnetbyaddr __P((unsigned long, int));
369 struct netent   *getnetbyname __P((const char *));
370 struct netent   *getnetent __P((void));
371 struct protoent *getprotobyname __P((const char *));
372 struct protoent *getprotobynumber __P((int));
373 struct protoent *getprotoent __P((void));
374 struct servent  *getservbyname __P((const char *, const char *));
375 struct servent  *getservbyport __P((int, const char *));
376 struct servent  *getservent __P((void));
377 void            herror __P((const char *));
378 const char      *hstrerror __P((int));
379 void            sethostent __P((int));
380 /* void         sethostfile __P((const char *)); */
381 void            setnetent __P((int));
382 void            setprotoent __P((int));
383 void            setservent __P((int));
384 int             getaddrinfo __P((const char *, const char *,
385                                  const struct addrinfo *, struct addrinfo **));
386 int             getnameinfo __P((const struct sockaddr *, size_t, char *,
387                                  size_t, char *, size_t, int));
388 void            freeaddrinfo __P((struct addrinfo *));
389 const char      *gai_strerror __P((int));
390 struct hostent  *getipnodebyname __P((const char *, int, int, int *));
391 struct hostent  *getipnodebyaddr __P((const void *, size_t, int, int *));
392 void            freehostent __P((struct hostent *));
393 #ifdef __GLIBC__
394 int             getnetgrent __P((/* const */ char **, /* const */ char **,
395                                  /* const */ char **));
396 void            setnetgrent __P((const char *));
397 void            endnetgrent __P((void));
398 int             innetgr __P((const char *, const char *, const char *,
399                              const char *));
400 #endif
401
402 #ifdef _REENTRANT
403 #if defined(__hpux) || defined(__osf__) || defined(_AIX)
404 int             gethostbyaddr_r __P((const char *, int, int, struct hostent *,
405                                         struct hostent_data *));
406 int             gethostbyname_r __P((const char *, struct hostent *, 
407                                         struct hostent_data *));
408 int             gethostent_r __P((struct hostent *, struct hostent_data *));
409 #if defined(_AIX)
410 void            sethostent_r __P((int, struct hostent_data *));
411 #else
412 int             sethostent_r __P((int, struct hostent_data *));
413 #endif 
414 #if defined(__hpux)
415 int             endhostent_r __P((struct hostent_data *));
416 #else
417 void            endhostent_r __P((struct hostent_data *));
418 #endif
419
420 #if defined(__hpux) || defined(__osf__)
421 int             getnetbyaddr_r __P((int, int,
422                                 struct netent *, struct netent_data *));
423 #else
424 int             getnetbyaddr_r __P((long, int,
425                                 struct netent *, struct netent_data *));
426 #endif
427 int             getnetbyname_r __P((const char *,
428                                 struct netent *, struct netent_data *));
429 int             getnetent_r __P((struct netent *, struct netent_data *));
430 int             setnetent_r __P((int, struct netent_data *));
431 #ifdef __hpux
432 int             endnetent_r __P((struct netent_data *buffer));
433 #else
434 void            endnetent_r __P((struct netent_data *buffer));
435 #endif
436
437 int             getprotobyname_r __P((const char *,
438                                 struct protoent *, struct protoent_data *));
439 int             getprotobynumber_r __P((int,
440                                 struct protoent *, struct protoent_data *));
441 int             getprotoent_r __P((struct protoent *, struct protoent_data *));
442 int             setprotoent_r __P((int, struct protoent_data *));
443 #ifdef __hpux
444 int             endprotoent_r __P((struct protoent_data *));
445 #else
446 void            endprotoent_r __P((struct protoent_data *));
447 #endif
448
449 int             getservbyname_r __P((const char *, const char *,
450                                 struct servent *, struct servent_data *));
451 int             getservbyport_r __P((int, const char *,
452                                 struct servent *, struct servent_data *));
453 int             getservent_r __P((struct servent *, struct servent_data *));
454 int             setservent_r __P((int, struct servent_data *));
455 #ifdef __hpux
456 int             endservent_r __P((struct servent_data *));
457 #else
458 void            endservent_r __P((struct servent_data *));
459 #endif
460 #else
461  /* defined(sun) || defined(bsdi) */
462 #ifdef __GLIBC__
463 int gethostbyaddr_r __P((const char *, int, int, struct hostent *,
464                          char *, size_t, struct hostent **, int *));
465 int gethostbyname_r __P((const char *, struct hostent *,
466                         char *, size_t, struct hostent **, int *));
467 int gethostent_r __P((struct hostent *, char *, size_t,
468                          struct hostent **, int *));
469 #else
470 struct hostent  *gethostbyaddr_r __P((const char *, int, int, struct hostent *,
471                                         char *, int, int *));
472 struct hostent  *gethostbyname_r __P((const char *, struct hostent *,
473                                         char *, int, int *));
474 struct hostent  *gethostent_r __P((struct hostent *, char *, int, int *));
475 #endif
476 void            sethostent_r __P((int));
477 void            endhostent_r __P((void));
478
479 #ifdef __GLIBC__
480 int getnetbyname_r __P((const char *, struct netent *,
481                         char *, size_t, struct netent **, int*));
482 int getnetbyaddr_r __P((unsigned long int, int, struct netent *,
483                         char *, size_t, struct netent **, int*));
484 int getnetent_r __P((struct netent *, char *, size_t, struct netent **, int*));
485 #else
486 struct netent   *getnetbyname_r __P((const char *, struct netent *,
487                                         char *, int));
488 struct netent   *getnetbyaddr_r __P((long, int, struct netent *,
489                                         char *, int));
490 struct netent   *getnetent_r __P((struct netent *, char *, int));
491 #endif
492 void            setnetent_r __P((int));
493 void            endnetent_r __P((void));
494
495 #ifdef __GLIBC__
496 int getprotobyname_r __P((const char *, struct protoent *, char *,
497                           size_t, struct protoent **));
498 int getprotobynumber_r __P((int, struct protoent *, char *, size_t,
499                             struct protoent **));
500 int getprotoent_r __P((struct protoent *, char *, size_t, struct protoent **));
501 #else
502 struct protoent *getprotobyname_r __P((const char *,
503                                 struct protoent *, char *, int));
504 struct protoent *getprotobynumber_r __P((int,
505                                 struct protoent *, char *, int));
506 struct protoent *getprotoent_r __P((struct protoent *, char *, int));
507 #endif
508 void            setprotoent_r __P((int));
509 void            endprotoent_r __P((void));
510
511 #ifdef __GLIBC__
512 int getservbyname_r __P((const char *name, const char *,
513                          struct servent *, char *, size_t, struct servent **));
514 int getservbyport_r __P((int port, const char *,
515                          struct servent *, char *, size_t, struct servent **));
516 int getservent_r __P((struct servent *, char *, size_t, struct servent **));
517 #else
518 struct servent  *getservbyname_r __P((const char *name, const char *,
519                                         struct servent *, char *, int));
520 struct servent  *getservbyport_r __P((int port, const char *,
521                                         struct servent *, char *, int));
522 struct servent  *getservent_r __P((struct servent *, char *, int));
523 #endif
524 void            setservent_r __P((int));
525 void            endservent_r __P((void));
526
527 #ifdef __GLIBC__
528 int             getnetgrent_r __P((char **, char **, char **, char *, size_t));
529 #endif
530
531 #endif
532 #endif
533 __END_DECLS
534
535 /* This is nec'y to make this include file properly replace the sun version. */
536 #ifdef sun
537 #ifdef __GNU_LIBRARY__
538 #include <rpc/netdb.h>
539 #else
540 struct rpcent {
541         char    *r_name;        /* name of server for this rpc program */
542         char    **r_aliases;    /* alias list */
543         int     r_number;       /* rpc program number */
544 };
545 struct rpcent   *getrpcbyname(), *getrpcbynumber(), *getrpcent();
546 #endif /* __GNU_LIBRARY__ */
547 #endif /* sun */
548
549 #endif /* !_NETDB_H_ */