2 * ++Copyright++ 1980, 1983, 1988, 1993
4 * Copyright (c) 1980, 1983, 1988, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
35 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
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.
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
53 * Portions Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
54 * All rights reserved.
56 * Redistribution and use in source and binary forms, with or without
57 * modification, are permitted provided that the following conditions
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
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.
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
88 * @(#)netdb.h 8.1 (Berkeley) 6/2/93
89 * $Id: netdb.h,v 1.12.2.1.4.9 2006/10/02 01:20:30 marka Exp $
95 #include <sys/param.h>
96 #include <sys/types.h>
97 #if (!defined(BSD)) || (BSD < 199306)
98 # include <sys/bitypes.h>
100 #include <sys/cdefs.h>
101 #include <sys/socket.h>
102 #include <netinet/in.h>
106 #define _PATH_HEQUIV "/etc/hosts.equiv"
109 #define _PATH_HOSTS "/etc/hosts"
111 #ifndef _PATH_NETWORKS
112 #define _PATH_NETWORKS "/etc/networks"
114 #ifndef _PATH_PROTOCOLS
115 #define _PATH_PROTOCOLS "/etc/protocols"
117 #ifndef _PATH_SERVICES
118 #define _PATH_SERVICES "/etc/services"
121 #if (__GLIBC__ > 2 || __GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)
122 #define __h_errno __h_errno_location
125 extern int * __h_errno __P((void));
127 #if defined(_REENTRANT) || \
128 (__GLIBC__ > 2 || __GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)
129 #define h_errno (*__h_errno())
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).
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 */
149 * Assumption here is that a network number
150 * fits in an unsigned long -- probably a poor one.
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 # */
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 */
167 char *p_name; /* official protocol name */
168 char **p_aliases; /* alias list */
169 int p_proto; /* protocol # */
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)
181 socklen_t ai_addrlen;
183 size_t ai_addrlen; /* length of ai_addr */
186 struct sockaddr *ai_addr; /* binary address */
187 char *ai_canonname; /* canonical name for hostname */
189 char *ai_canonname; /* canonical name for hostname */
190 struct sockaddr *ai_addr; /* binary address */
192 struct addrinfo *ai_next; /* next structure in linked list */
196 * Error return codes from gethostbyname() and gethostbyaddr()
197 * (left in extern int h_errno).
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 */
209 * Error return codes from getaddrinfo()
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
227 * Flag values for getaddrinfo()
229 #define AI_PASSIVE 0x00000001
230 #define AI_CANONNAME 0x00000002
231 #define AI_NUMERICHOST 0x00000004
232 #define AI_MASK 0x00000007
235 * Flag values for getipnodebyname()
237 #define AI_V4MAPPED 0x00000008
238 #define AI_ALL 0x00000010
239 #define AI_ADDRCONFIG 0x00000020
240 #define AI_DEFAULT (AI_V4MAPPED|AI_ADDRCONFIG)
243 * Constants for getnameinfo()
245 #define NI_MAXHOST 1025
246 #define NI_MAXSERV 32
249 * Flag values for getnameinfo()
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
260 * Scope delimit character
262 #define SCOPE_DELIMITER '%'
266 #if defined (__hpux) || defined(__osf__) || defined(_AIX)
267 #define _MAXALIASES 35
268 #define _MAXLINELEN 1024
270 #define _HOSTBUFSIZE (BUFSIZ + 1)
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];
294 #if defined(__osf__) || defined(_AIX)
295 char line[_MAXLINELEN];
298 char line[_MAXLINELEN+1];
300 char *net_aliases[_MAXALIASES];
315 void *_net_reserv1; /* reserved for future use */
316 void *_net_reserv2; /* reserved for future use */
320 struct protoent_data {
324 char line[_MAXLINELEN];
330 char line[_MAXLINELEN+1];
332 char *proto_aliases[_MAXALIASES];
335 int svc_getprotoflag;
346 void *_proto_reserv1; /* reserved for future use */
347 void *_proto_reserv2; /* reserved for future use */
351 struct servent_data {
353 #if defined(__osf__) || defined(_AIX)
354 char line[_MAXLINELEN];
357 char line[_MAXLINELEN+1];
359 char *serv_aliases[_MAXALIASES];
374 void *_serv_reserv1; /* reserved for future use */
375 void *_serv_reserv2; /* reserved for future use */
381 void endhostent __P((void));
382 void endnetent __P((void));
383 void endprotoent __P((void));
384 void endservent __P((void));
385 void freehostent __P((struct hostent *));
386 struct hostent *gethostbyaddr __P((const char *, int, int));
387 struct hostent *gethostbyname __P((const char *));
388 struct hostent *gethostbyname2 __P((const char *, int));
389 struct hostent *gethostent __P((void));
390 struct hostent *getipnodebyaddr __P((const void *, size_t, int, int *));
391 struct hostent *getipnodebyname __P((const char *, int, int, int *));
392 struct netent *getnetbyaddr __P((unsigned long, int));
393 struct netent *getnetbyname __P((const char *));
394 struct netent *getnetent __P((void));
395 struct protoent *getprotobyname __P((const char *));
396 struct protoent *getprotobynumber __P((int));
397 struct protoent *getprotoent __P((void));
398 struct servent *getservbyname __P((const char *, const char *));
399 struct servent *getservbyport __P((int, const char *));
400 struct servent *getservent __P((void));
401 void herror __P((const char *));
402 const char *hstrerror __P((int));
403 void sethostent __P((int));
404 /* void sethostfile __P((const char *)); */
405 void setnetent __P((int));
406 void setprotoent __P((int));
407 void setservent __P((int));
408 int getaddrinfo __P((const char *, const char *,
409 const struct addrinfo *, struct addrinfo **));
410 int getnameinfo __P((const struct sockaddr *, size_t, char *,
411 size_t, char *, size_t, int));
412 void freeaddrinfo __P((struct addrinfo *));
413 const char *gai_strerror __P((int));
414 struct hostent *getipnodebyname __P((const char *, int, int, int *));
415 struct hostent *getipnodebyaddr __P((const void *, size_t, int, int *));
416 void freehostent __P((struct hostent *));
418 int getnetgrent __P((/* const */ char **, /* const */ char **,
419 /* const */ char **));
420 void setnetgrent __P((const char *));
421 void endnetgrent __P((void));
422 int innetgr __P((const char *, const char *, const char *,
427 #if defined(__hpux) || defined(__osf__) || defined(_AIX)
428 int gethostbyaddr_r __P((const char *, int, int, struct hostent *,
429 struct hostent_data *));
430 int gethostbyname_r __P((const char *, struct hostent *,
431 struct hostent_data *));
432 int gethostent_r __P((struct hostent *, struct hostent_data *));
434 void sethostent_r __P((int, struct hostent_data *));
436 int sethostent_r __P((int, struct hostent_data *));
439 int endhostent_r __P((struct hostent_data *));
441 void endhostent_r __P((struct hostent_data *));
444 #if defined(__hpux) || defined(__osf__)
445 int getnetbyaddr_r __P((int, int,
446 struct netent *, struct netent_data *));
448 int getnetbyaddr_r __P((long, int,
449 struct netent *, struct netent_data *));
451 int getnetbyname_r __P((const char *,
452 struct netent *, struct netent_data *));
453 int getnetent_r __P((struct netent *, struct netent_data *));
454 int setnetent_r __P((int, struct netent_data *));
456 int endnetent_r __P((struct netent_data *buffer));
458 void endnetent_r __P((struct netent_data *buffer));
461 int getprotobyname_r __P((const char *,
462 struct protoent *, struct protoent_data *));
463 int getprotobynumber_r __P((int,
464 struct protoent *, struct protoent_data *));
465 int getprotoent_r __P((struct protoent *, struct protoent_data *));
466 int setprotoent_r __P((int, struct protoent_data *));
468 int endprotoent_r __P((struct protoent_data *));
470 void endprotoent_r __P((struct protoent_data *));
473 int getservbyname_r __P((const char *, const char *,
474 struct servent *, struct servent_data *));
475 int getservbyport_r __P((int, const char *,
476 struct servent *, struct servent_data *));
477 int getservent_r __P((struct servent *, struct servent_data *));
478 int setservent_r __P((int, struct servent_data *));
480 int endservent_r __P((struct servent_data *));
482 void endservent_r __P((struct servent_data *));
485 int setnetgrent_r __P((const char *, void **));
486 void endnetgrent_r __P((void **));
488 * Note: AIX's netdb.h declares innetgr_r() as:
489 * int innetgr_r(char *, char *, char *, char *, struct innetgr_data *);
491 int innetgr_r __P((const char *, const char *, const char *,
495 /* defined(sun) || defined(bsdi) */
496 #if defined(__GLIBC__) || defined(__FreeBSD__) && (__FreeBSD_version + 0 >= 601103)
497 int gethostbyaddr_r __P((const char *, int, int, struct hostent *,
498 char *, size_t, struct hostent **, int *));
499 int gethostbyname_r __P((const char *, struct hostent *,
500 char *, size_t, struct hostent **, int *));
501 int gethostent_r __P((struct hostent *, char *, size_t,
502 struct hostent **, int *));
504 struct hostent *gethostbyaddr_r __P((const char *, int, int, struct hostent *,
505 char *, int, int *));
506 struct hostent *gethostbyname_r __P((const char *, struct hostent *,
507 char *, int, int *));
508 struct hostent *gethostent_r __P((struct hostent *, char *, int, int *));
510 void sethostent_r __P((int));
511 void endhostent_r __P((void));
513 #if defined(__GLIBC__) || defined(__FreeBSD__) && (__FreeBSD_version + 0 >= 601103)
514 int getnetbyname_r __P((const char *, struct netent *,
515 char *, size_t, struct netent **, int*));
516 int getnetbyaddr_r __P((unsigned long int, int, struct netent *,
517 char *, size_t, struct netent **, int*));
518 int getnetent_r __P((struct netent *, char *, size_t, struct netent **, int*));
520 struct netent *getnetbyname_r __P((const char *, struct netent *,
522 struct netent *getnetbyaddr_r __P((long, int, struct netent *,
524 struct netent *getnetent_r __P((struct netent *, char *, int));
526 void setnetent_r __P((int));
527 void endnetent_r __P((void));
529 #if defined(__GLIBC__) || defined(__FreeBSD__) && (__FreeBSD_version + 0 >= 601103)
530 int getprotobyname_r __P((const char *, struct protoent *, char *,
531 size_t, struct protoent **));
532 int getprotobynumber_r __P((int, struct protoent *, char *, size_t,
533 struct protoent **));
534 int getprotoent_r __P((struct protoent *, char *, size_t, struct protoent **));
536 struct protoent *getprotobyname_r __P((const char *,
537 struct protoent *, char *, int));
538 struct protoent *getprotobynumber_r __P((int,
539 struct protoent *, char *, int));
540 struct protoent *getprotoent_r __P((struct protoent *, char *, int));
542 void setprotoent_r __P((int));
543 void endprotoent_r __P((void));
545 #if defined(__GLIBC__) || defined(__FreeBSD__) && (__FreeBSD_version + 0 >= 601103)
546 int getservbyname_r __P((const char *name, const char *,
547 struct servent *, char *, size_t, struct servent **));
548 int getservbyport_r __P((int port, const char *,
549 struct servent *, char *, size_t, struct servent **));
550 int getservent_r __P((struct servent *, char *, size_t, struct servent **));
552 struct servent *getservbyname_r __P((const char *name, const char *,
553 struct servent *, char *, int));
554 struct servent *getservbyport_r __P((int port, const char *,
555 struct servent *, char *, int));
556 struct servent *getservent_r __P((struct servent *, char *, int));
558 void setservent_r __P((int));
559 void endservent_r __P((void));
562 int getnetgrent_r __P((char **, char **, char **, char *, size_t));
569 /* This is nec'y to make this include file properly replace the sun version. */
571 #ifdef __GNU_LIBRARY__
572 #include <rpc/netdb.h>
575 char *r_name; /* name of server for this rpc program */
576 char **r_aliases; /* alias list */
577 int r_number; /* rpc program number */
579 struct rpcent *getrpcbyname(), *getrpcbynumber(), *getrpcent();
580 #endif /* __GNU_LIBRARY__ */
583 #endif /* !_NETDB_H_ */