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.15.18.7 2008/02/28 05:49:37 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 */
208 * Error return codes from getaddrinfo()
210 #define EAI_ADDRFAMILY 1 /*%< address family for hostname not supported */
211 #define EAI_AGAIN 2 /*%< temporary failure in name resolution */
212 #define EAI_BADFLAGS 3 /*%< invalid value for ai_flags */
213 #define EAI_FAIL 4 /*%< non-recoverable failure in name resolution */
214 #define EAI_FAMILY 5 /*%< ai_family not supported */
215 #define EAI_MEMORY 6 /*%< memory allocation failure */
216 #define EAI_NODATA 7 /*%< no address associated with hostname */
217 #define EAI_NONAME 8 /*%< hostname nor servname provided, or not known */
218 #define EAI_SERVICE 9 /*%< servname not supported for ai_socktype */
219 #define EAI_SOCKTYPE 10 /*%< ai_socktype not supported */
220 #define EAI_SYSTEM 11 /*%< system error returned in errno */
221 #define EAI_BADHINTS 12
222 #define EAI_PROTOCOL 13
226 * Flag values for getaddrinfo()
228 #define AI_PASSIVE 0x00000001
229 #define AI_CANONNAME 0x00000002
230 #define AI_NUMERICHOST 0x00000004
231 #define AI_MASK 0x00000007
234 * Flag values for getipnodebyname()
236 #define AI_V4MAPPED 0x00000008
237 #define AI_ALL 0x00000010
238 #define AI_ADDRCONFIG 0x00000020
239 #define AI_DEFAULT (AI_V4MAPPED|AI_ADDRCONFIG)
242 * Constants for getnameinfo()
244 #define NI_MAXHOST 1025
245 #define NI_MAXSERV 32
248 * Flag values for getnameinfo()
250 #define NI_NOFQDN 0x00000001
251 #define NI_NUMERICHOST 0x00000002
252 #define NI_NAMEREQD 0x00000004
253 #define NI_NUMERICSERV 0x00000008
254 #define NI_DGRAM 0x00000010
255 #define NI_WITHSCOPEID 0x00000020
256 #define NI_NUMERICSCOPE 0x00000040
259 * Scope delimit character
261 #define SCOPE_DELIMITER '%'
265 #if defined (__hpux) || defined(__osf__) || defined(_AIX)
266 #define _MAXALIASES 35
267 #define _MAXLINELEN 1024
269 #define _HOSTBUFSIZE (BUFSIZ + 1)
271 struct hostent_data {
272 struct in_addr host_addr;
273 char *h_addr_ptrs[_MAXADDRS + 1];
274 char hostaddr[_MAXADDRS];
275 char hostbuf[_HOSTBUFSIZE];
276 char *host_aliases[_MAXALIASES];
293 #if defined(__osf__) || defined(_AIX)
294 char line[_MAXLINELEN];
297 char line[_MAXLINELEN+1];
299 char *net_aliases[_MAXALIASES];
314 void *_net_reserv1; /* reserved for future use */
315 void *_net_reserv2; /* reserved for future use */
319 struct protoent_data {
323 char line[_MAXLINELEN];
329 char line[_MAXLINELEN+1];
331 char *proto_aliases[_MAXALIASES];
334 int svc_getprotoflag;
345 void *_proto_reserv1; /* reserved for future use */
346 void *_proto_reserv2; /* reserved for future use */
350 struct servent_data {
352 #if defined(__osf__) || defined(_AIX)
353 char line[_MAXLINELEN];
356 char line[_MAXLINELEN+1];
358 char *serv_aliases[_MAXALIASES];
373 void *_serv_reserv1; /* reserved for future use */
374 void *_serv_reserv2; /* reserved for future use */
380 void endhostent __P((void));
381 void endnetent __P((void));
382 void endprotoent __P((void));
383 void endservent __P((void));
384 void freehostent __P((struct hostent *));
385 struct hostent *gethostbyaddr __P((const char *, int, int));
386 struct hostent *gethostbyname __P((const char *));
387 struct hostent *gethostbyname2 __P((const char *, int));
388 struct hostent *gethostent __P((void));
389 struct hostent *getipnodebyaddr __P((const void *, size_t, int, int *));
390 struct hostent *getipnodebyname __P((const char *, int, int, int *));
391 struct netent *getnetbyaddr __P((unsigned long, int));
392 struct netent *getnetbyname __P((const char *));
393 struct netent *getnetent __P((void));
394 struct protoent *getprotobyname __P((const char *));
395 struct protoent *getprotobynumber __P((int));
396 struct protoent *getprotoent __P((void));
397 struct servent *getservbyname __P((const char *, const char *));
398 struct servent *getservbyport __P((int, const char *));
399 struct servent *getservent __P((void));
400 void herror __P((const char *));
401 const char *hstrerror __P((int));
402 void sethostent __P((int));
403 /* void sethostfile __P((const char *)); */
404 void setnetent __P((int));
405 void setprotoent __P((int));
406 void setservent __P((int));
407 int getaddrinfo __P((const char *, const char *,
408 const struct addrinfo *, struct addrinfo **));
409 int getnameinfo __P((const struct sockaddr *, size_t, char *,
410 size_t, char *, size_t, int));
411 void freeaddrinfo __P((struct addrinfo *));
412 const char *gai_strerror __P((int));
413 struct hostent *getipnodebyname __P((const char *, int, int, int *));
414 struct hostent *getipnodebyaddr __P((const void *, size_t, int, int *));
415 void freehostent __P((struct hostent *));
417 int getnetgrent __P((/* const */ char **, /* const */ char **,
418 /* const */ char **));
419 void setnetgrent __P((const char *));
420 void endnetgrent __P((void));
421 int innetgr __P((const char *, const char *, const char *,
426 #if defined(__hpux) || defined(__osf__) || defined(_AIX)
427 int gethostbyaddr_r __P((const char *, int, int, struct hostent *,
428 struct hostent_data *));
429 int gethostbyname_r __P((const char *, struct hostent *,
430 struct hostent_data *));
431 int gethostent_r __P((struct hostent *, struct hostent_data *));
433 void sethostent_r __P((int, struct hostent_data *));
435 int sethostent_r __P((int, struct hostent_data *));
438 int endhostent_r __P((struct hostent_data *));
440 void endhostent_r __P((struct hostent_data *));
443 #if defined(__hpux) || defined(__osf__)
444 int getnetbyaddr_r __P((int, int,
445 struct netent *, struct netent_data *));
447 int getnetbyaddr_r __P((long, int,
448 struct netent *, struct netent_data *));
450 int getnetbyname_r __P((const char *,
451 struct netent *, struct netent_data *));
452 int getnetent_r __P((struct netent *, struct netent_data *));
453 int setnetent_r __P((int, struct netent_data *));
455 int endnetent_r __P((struct netent_data *buffer));
457 void endnetent_r __P((struct netent_data *buffer));
460 int getprotobyname_r __P((const char *,
461 struct protoent *, struct protoent_data *));
462 int getprotobynumber_r __P((int,
463 struct protoent *, struct protoent_data *));
464 int getprotoent_r __P((struct protoent *, struct protoent_data *));
465 int setprotoent_r __P((int, struct protoent_data *));
467 int endprotoent_r __P((struct protoent_data *));
469 void endprotoent_r __P((struct protoent_data *));
472 int getservbyname_r __P((const char *, const char *,
473 struct servent *, struct servent_data *));
474 int getservbyport_r __P((int, const char *,
475 struct servent *, struct servent_data *));
476 int getservent_r __P((struct servent *, struct servent_data *));
477 int setservent_r __P((int, struct servent_data *));
479 int endservent_r __P((struct servent_data *));
481 void endservent_r __P((struct servent_data *));
484 int setnetgrent_r __P((char *, void **));
485 void endnetgrent_r __P((void **));
487 * Note: AIX's netdb.h declares innetgr_r() as:
488 * int innetgr_r(char *, char *, char *, char *, struct innetgr_data *);
490 int innetgr_r __P((const char *, const char *, const char *,
494 /* defined(sun) || defined(bsdi) */
495 #if defined(__GLIBC__) || defined(__FreeBSD__) && (__FreeBSD_version + 0 >= 601103)
496 int gethostbyaddr_r __P((const char *, int, int, struct hostent *,
497 char *, size_t, struct hostent **, int *));
498 int gethostbyname_r __P((const char *, struct hostent *,
499 char *, size_t, struct hostent **, int *));
500 int gethostent_r __P((struct hostent *, char *, size_t,
501 struct hostent **, int *));
503 struct hostent *gethostbyaddr_r __P((const char *, int, int, struct hostent *,
504 char *, int, int *));
505 struct hostent *gethostbyname_r __P((const char *, struct hostent *,
506 char *, int, int *));
507 struct hostent *gethostent_r __P((struct hostent *, char *, int, int *));
509 void sethostent_r __P((int));
510 void endhostent_r __P((void));
512 #if defined(__GLIBC__) || defined(__FreeBSD__) && (__FreeBSD_version + 0 >= 601103)
513 int getnetbyname_r __P((const char *, struct netent *,
514 char *, size_t, struct netent **, int*));
515 int getnetbyaddr_r __P((unsigned long int, int, struct netent *,
516 char *, size_t, struct netent **, int*));
517 int getnetent_r __P((struct netent *, char *, size_t, struct netent **, int*));
519 struct netent *getnetbyname_r __P((const char *, struct netent *,
521 struct netent *getnetbyaddr_r __P((long, int, struct netent *,
523 struct netent *getnetent_r __P((struct netent *, char *, int));
525 void setnetent_r __P((int));
526 void endnetent_r __P((void));
528 #if defined(__GLIBC__) || defined(__FreeBSD__) && (__FreeBSD_version + 0 >= 601103)
529 int getprotobyname_r __P((const char *, struct protoent *, char *,
530 size_t, struct protoent **));
531 int getprotobynumber_r __P((int, struct protoent *, char *, size_t,
532 struct protoent **));
533 int getprotoent_r __P((struct protoent *, char *, size_t, struct protoent **));
535 struct protoent *getprotobyname_r __P((const char *,
536 struct protoent *, char *, int));
537 struct protoent *getprotobynumber_r __P((int,
538 struct protoent *, char *, int));
539 struct protoent *getprotoent_r __P((struct protoent *, char *, int));
541 void setprotoent_r __P((int));
542 void endprotoent_r __P((void));
544 #if defined(__GLIBC__) || defined(__FreeBSD__) && (__FreeBSD_version + 0 >= 601103)
545 int getservbyname_r __P((const char *name, const char *,
546 struct servent *, char *, size_t, struct servent **));
547 int getservbyport_r __P((int port, const char *,
548 struct servent *, char *, size_t, struct servent **));
549 int getservent_r __P((struct servent *, char *, size_t, struct servent **));
551 struct servent *getservbyname_r __P((const char *name, const char *,
552 struct servent *, char *, int));
553 struct servent *getservbyport_r __P((int port, const char *,
554 struct servent *, char *, int));
555 struct servent *getservent_r __P((struct servent *, char *, int));
557 void setservent_r __P((int));
558 void endservent_r __P((void));
561 int getnetgrent_r __P((char **, char **, char **, char *, size_t));
568 /* This is nec'y to make this include file properly replace the sun version. */
570 #ifdef __GNU_LIBRARY__
571 #include <rpc/netdb.h>
574 char *r_name; /*%< name of server for this rpc program */
575 char **r_aliases; /*%< alias list */
576 int r_number; /*%< rpc program number */
578 struct rpcent *getrpcbyname(), *getrpcbynumber(), *getrpcent();
579 #endif /* __GNU_LIBRARY__ */
581 #endif /* !_NETDB_H_ */