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.5 2004/03/16 02:25:06 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];
295 char line[_MAXLINELEN];
298 char line[_MAXLINELEN+1];
300 char *net_aliases[_MAXALIASES];
313 struct protoent_data {
319 char line[_MAXLINELEN+1];
321 char *proto_aliases[_MAXALIASES];
324 int svc_getprotoflag;
334 struct servent_data {
337 char line[_MAXLINELEN];
340 char line[_MAXLINELEN+1];
342 char *serv_aliases[_MAXALIASES];
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 *));
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 *,
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 *));
410 void sethostent_r __P((int, struct hostent_data *));
412 int sethostent_r __P((int, struct hostent_data *));
415 int endhostent_r __P((struct hostent_data *));
417 void endhostent_r __P((struct hostent_data *));
420 #if defined(__hpux) || defined(__osf__)
421 int getnetbyaddr_r __P((int, int,
422 struct netent *, struct netent_data *));
424 int getnetbyaddr_r __P((long, int,
425 struct netent *, struct netent_data *));
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 *));
432 int endnetent_r __P((struct netent_data *buffer));
434 void endnetent_r __P((struct netent_data *buffer));
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 *));
444 int endprotoent_r __P((struct protoent_data *));
446 void endprotoent_r __P((struct protoent_data *));
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 *));
456 int endservent_r __P((struct servent_data *));
458 void endservent_r __P((struct servent_data *));
461 /* defined(sun) || defined(bsdi) */
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 *));
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 *));
476 void sethostent_r __P((int));
477 void endhostent_r __P((void));
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*));
486 struct netent *getnetbyname_r __P((const char *, struct netent *,
488 struct netent *getnetbyaddr_r __P((long, int, struct netent *,
490 struct netent *getnetent_r __P((struct netent *, char *, int));
492 void setnetent_r __P((int));
493 void endnetent_r __P((void));
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 **));
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));
508 void setprotoent_r __P((int));
509 void endprotoent_r __P((void));
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 **));
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));
524 void setservent_r __P((int));
525 void endservent_r __P((void));
528 int getnetgrent_r __P((char **, char **, char **, char *, size_t));
535 /* This is nec'y to make this include file properly replace the sun version. */
537 #ifdef __GNU_LIBRARY__
538 #include <rpc/netdb.h>
541 char *r_name; /* name of server for this rpc program */
542 char **r_aliases; /* alias list */
543 int r_number; /* rpc program number */
545 struct rpcent *getrpcbyname(), *getrpcbynumber(), *getrpcent();
546 #endif /* __GNU_LIBRARY__ */
549 #endif /* !_NETDB_H_ */