Update.
[glibc.git] / resolv / netdb.h
blobf8ae4f2a33c5b9a0b2cc43dff1680c78971f30fb
1 /* Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it
5 and/or modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be
10 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
11 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the Free Software Foundation, Inc., 59 Temple Place -
17 Suite 330, Boston, MA 02111-1307, USA. */
19 /* All data returned by the network data base library are supplied in
20 host order and returned in network order (suitable for use in
21 system calls). */
23 #ifndef _NETDB_H
24 #define _NETDB_H 1
26 #include <features.h>
28 /* This is necessary to make this include file properly replace the
29 Sun version. */
30 #include <rpc/netdb.h>
31 #include <sys/socket.h> /* need socklen_t */
32 #define __need_size_t
33 #include <stddef.h>
35 #ifndef __uint32_t_defined
36 typedef unsigned int uint32_t;
37 # define __uint32_t_defined
38 #endif
40 #include <bits/netdb.h>
42 /* Absolute file name for network data base files. */
43 #define _PATH_HEQUIV "/etc/hosts.equiv"
44 #define _PATH_HOSTS "/etc/hosts"
45 #define _PATH_NETWORKS "/etc/networks"
46 #define _PATH_NSSWITCH_CONF "/etc/nsswitch.conf"
47 #define _PATH_PROTOCOLS "/etc/protocols"
48 #define _PATH_SERVICES "/etc/services"
51 __BEGIN_DECLS
53 /* Error status for non-reentrant lookup functions. */
54 extern int h_errno;
56 /* Function to get address of global `h_errno' variable. */
57 extern int *__h_errno_location (void) __THROW __attribute__ ((__const__));
59 #ifdef _LIBC
60 # ifdef _LIBC_REENTRANT
61 static inline int
62 __set_h_errno (int __err)
64 return *__h_errno_location () = __err;
66 # else
67 # define __set_h_errno(x) (h_errno = (x))
68 # endif /* _LIBC_REENTRANT */
69 #endif /* _LIBC */
72 #if !defined _LIBC || defined _LIBC_REENTRANT
73 /* Use a macro to access always the thread specific `h_errno' variable. */
74 # define h_errno (*__h_errno_location ())
75 #endif
78 /* Possible values left in `h_errno'. */
79 #define NETDB_INTERNAL -1 /* See errno. */
80 #define NETDB_SUCCESS 0 /* No problem. */
81 #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found. */
82 #define TRY_AGAIN 2 /* Non-Authoritative Host not found,
83 or SERVERFAIL. */
84 #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED,
85 NOTIMP. */
86 #define NO_DATA 4 /* Valid name, no data record of requested
87 type. */
88 #define NO_ADDRESS NO_DATA /* No address, look for MX record. */
90 #ifdef __USE_GNU
91 /* Scope delimiter for getaddrinfo(), getnameinfo(). */
92 # define SCOPE_DELIMITER '%'
93 #endif
95 /* Print error indicated by `h_errno' variable on standard error. STR
96 if non-null is printed before the error string. */
97 extern void herror (__const char *__str) __THROW;
99 /* Return string associated with error ERR_NUM. */
100 extern __const char *hstrerror (int __err_num) __THROW;
104 /* Description of data base entry for a single host. */
105 struct hostent
107 char *h_name; /* Official name of host. */
108 char **h_aliases; /* Alias list. */
109 int h_addrtype; /* Host address type. */
110 socklen_t h_length; /* Length of address. */
111 char **h_addr_list; /* List of addresses from name server. */
112 #define h_addr h_addr_list[0] /* Address, for backward compatibility. */
115 /* Open host data base files and mark them as staying open even after
116 a later search if STAY_OPEN is non-zero. */
117 extern void sethostent (int __stay_open) __THROW;
119 /* Close host data base files and clear `stay open' flag. */
120 extern void endhostent (void) __THROW;
122 /* Get next entry from host data base file. Open data base if
123 necessary. */
124 extern struct hostent *gethostent (void) __THROW;
126 /* Return entry from host data base which address match ADDR with
127 length LEN and type TYPE. */
128 extern struct hostent *gethostbyaddr (__const void *__addr, __socklen_t __len,
129 int __type) __THROW;
131 /* Return entry from host data base for host with NAME. */
132 extern struct hostent *gethostbyname (__const char *__name) __THROW;
134 #ifdef __USE_MISC
135 /* Return entry from host data base for host with NAME. AF must be
136 set to the address type which is `AF_INET' for IPv4 or `AF_INET6'
137 for IPv6. */
138 extern struct hostent *gethostbyname2 (__const char *__name, int __af) __THROW;
139 #endif
141 #ifdef __USE_UNIX98
142 /* Return entry from host data base which address match ADDR with
143 length LEN and type TYPE in newly allocated buffer. */
144 extern struct hostent *getipnodebyaddr (__const void *__addr, socklen_t __len,
145 int __type, int *__error_num) __THROW;
147 /* Return entry from host data base for host with NAME and newly allocated
148 buffer. FLAGS is some combination of the following AI_* values. */
149 extern struct hostent *getipnodebyname (__const char *__name, int __type,
150 int __flags, int *__error_num) __THROW;
152 # define AI_V4MAPPED 1 /* IPv4-mapped addresses are acceptable. */
153 # define AI_ALL 2 /* Return both IPv4 and IPv6 addresses. */
154 # define AI_ADDRCONFIG 4 /* Use configuration of this host to choose
155 returned address type. */
156 # define AI_DEFAULT (AI_V4MAPPED | AI_ADDRCONFIG)
158 /* Free structure returned by previous `getipnodebyaddr' or `getipnodebyname'
159 call. */
160 extern void freehostent (struct hostent *__ptr) __THROW;
162 #endif
164 #ifdef __USE_MISC
165 /* Reentrant versions of the functions above. The additional
166 arguments specify a buffer of BUFLEN starting at BUF. The last
167 argument is a pointer to a variable which gets the value which
168 would be stored in the global variable `herrno' by the
169 non-reentrant functions. */
170 extern int gethostent_r (struct hostent *__restrict __result_buf,
171 char *__restrict __buf, size_t __buflen,
172 struct hostent **__restrict __result,
173 int *__restrict __h_errnop) __THROW;
175 extern int gethostbyaddr_r (__const void *__restrict __addr, __socklen_t __len,
176 int __type,
177 struct hostent *__restrict __result_buf,
178 char *__restrict __buf, size_t __buflen,
179 struct hostent **__restrict __result,
180 int *__restrict __h_errnop) __THROW;
182 extern int gethostbyname_r (__const char *__restrict __name,
183 struct hostent *__restrict __result_buf,
184 char *__restrict __buf, size_t __buflen,
185 struct hostent **__restrict __result,
186 int *__restrict __h_errnop) __THROW;
188 extern int gethostbyname2_r (__const char *__restrict __name, int __af,
189 struct hostent *__restrict __result_buf,
190 char *__restrict __buf, size_t __buflen,
191 struct hostent **__restrict __result,
192 int *__restrict __h_errnop) __THROW;
193 #endif /* misc */
196 /* Open network data base files and mark them as staying open even
197 after a later search if STAY_OPEN is non-zero. */
198 extern void setnetent (int __stay_open) __THROW;
200 /* Close network data base files and clear `stay open' flag. */
201 extern void endnetent (void) __THROW;
203 /* Get next entry from network data base file. Open data base if
204 necessary. */
205 extern struct netent *getnetent (void) __THROW;
207 /* Return entry from network data base which address match NET and
208 type TYPE. */
209 extern struct netent *getnetbyaddr (uint32_t __net, int __type)
210 __THROW;
212 /* Return entry from network data base for network with NAME. */
213 extern struct netent *getnetbyname (__const char *__name) __THROW;
215 #ifdef __USE_MISC
216 /* Reentrant versions of the functions above. The additional
217 arguments specify a buffer of BUFLEN starting at BUF. The last
218 argument is a pointer to a variable which gets the value which
219 would be stored in the global variable `herrno' by the
220 non-reentrant functions. */
221 extern int getnetent_r (struct netent *__restrict __result_buf,
222 char *__restrict __buf, size_t __buflen,
223 struct netent **__restrict __result,
224 int *__restrict __h_errnop) __THROW;
226 extern int getnetbyaddr_r (uint32_t __net, int __type,
227 struct netent *__restrict __result_buf,
228 char *__restrict __buf, size_t __buflen,
229 struct netent **__restrict __result,
230 int *__restrict __h_errnop) __THROW;
232 extern int getnetbyname_r (__const char *__restrict __name,
233 struct netent *__restrict __result_buf,
234 char *__restrict __buf, size_t __buflen,
235 struct netent **__restrict __result,
236 int *__restrict __h_errnop) __THROW;
237 #endif /* misc */
240 /* Description of data base entry for a single service. */
241 struct servent
243 char *s_name; /* Official service name. */
244 char **s_aliases; /* Alias list. */
245 int s_port; /* Port number. */
246 char *s_proto; /* Protocol to use. */
249 /* Open service data base files and mark them as staying open even
250 after a later search if STAY_OPEN is non-zero. */
251 extern void setservent (int __stay_open) __THROW;
253 /* Close service data base files and clear `stay open' flag. */
254 extern void endservent (void) __THROW;
256 /* Get next entry from service data base file. Open data base if
257 necessary. */
258 extern struct servent *getservent (void) __THROW;
260 /* Return entry from network data base for network with NAME and
261 protocol PROTO. */
262 extern struct servent *getservbyname (__const char *__name,
263 __const char *__proto) __THROW;
265 /* Return entry from service data base which matches port PORT and
266 protocol PROTO. */
267 extern struct servent *getservbyport (int __port, __const char *__proto)
268 __THROW;
271 #ifdef __USE_MISC
272 /* Reentrant versions of the functions above. The additional
273 arguments specify a buffer of BUFLEN starting at BUF. */
274 extern int getservent_r (struct servent *__restrict __result_buf,
275 char *__restrict __buf, size_t __buflen,
276 struct servent **__restrict __result) __THROW;
278 extern int getservbyname_r (__const char *__restrict __name,
279 __const char *__restrict __proto,
280 struct servent *__restrict __result_buf,
281 char *__restrict __buf, size_t __buflen,
282 struct servent **__restrict __result) __THROW;
284 extern int getservbyport_r (int __port, __const char *__restrict __proto,
285 struct servent *__restrict __result_buf,
286 char *__restrict __buf, size_t __buflen,
287 struct servent **__restrict __result) __THROW;
288 #endif /* misc */
291 /* Description of data base entry for a single service. */
292 struct protoent
294 char *p_name; /* Official protocol name. */
295 char **p_aliases; /* Alias list. */
296 int p_proto; /* Protocol number. */
299 /* Open protocol data base files and mark them as staying open even
300 after a later search if STAY_OPEN is non-zero. */
301 extern void setprotoent (int __stay_open) __THROW;
303 /* Close protocol data base files and clear `stay open' flag. */
304 extern void endprotoent (void) __THROW;
306 /* Get next entry from protocol data base file. Open data base if
307 necessary. */
308 extern struct protoent *getprotoent (void) __THROW;
310 /* Return entry from protocol data base for network with NAME. */
311 extern struct protoent *getprotobyname (__const char *__name) __THROW;
313 /* Return entry from protocol data base which number is PROTO. */
314 extern struct protoent *getprotobynumber (int __proto) __THROW;
317 #ifdef __USE_MISC
318 /* Reentrant versions of the functions above. The additional
319 arguments specify a buffer of BUFLEN starting at BUF. */
320 extern int getprotoent_r (struct protoent *__restrict __result_buf,
321 char *__restrict __buf, size_t __buflen,
322 struct protoent **__restrict __result) __THROW;
324 extern int getprotobyname_r (__const char *__restrict __name,
325 struct protoent *__restrict __result_buf,
326 char *__restrict __buf, size_t __buflen,
327 struct protoent **__restrict __result) __THROW;
329 extern int getprotobynumber_r (int __proto,
330 struct protoent *__restrict __result_buf,
331 char *__restrict __buf, size_t __buflen,
332 struct protoent **__restrict __result) __THROW;
333 #endif /* misc */
336 /* Establish network group NETGROUP for enumeration. */
337 extern int setnetgrent (__const char *__netgroup) __THROW;
339 /* Free all space allocated by previous `setnetgrent' call. */
340 extern void endnetgrent (void) __THROW;
342 /* Get next member of netgroup established by last `setnetgrent' call
343 and return pointers to elements in HOSTP, USERP, and DOMAINP. */
344 extern int getnetgrent (char **__restrict __hostp,
345 char **__restrict __userp,
346 char **__restrict __domainp) __THROW;
348 #ifdef __USE_MISC
349 /* Test whether NETGROUP contains the triple (HOST,USER,DOMAIN). */
350 extern int innetgr (__const char *__netgroup, __const char *__host,
351 __const char *__user, __const char *domain) __THROW;
353 /* Reentrant version of `getnetgrent' where result is placed in BUFFER. */
354 extern int getnetgrent_r (char **__restrict __hostp,
355 char **__restrict __userp,
356 char **__restrict __domainp,
357 char *__restrict __buffer, size_t __buflen) __THROW;
358 #endif /* misc */
361 #ifdef __USE_BSD
362 /* Call `rshd' at port RPORT on remote machine *AHOST to execute CMD.
363 The local user is LOCUSER, on the remote machine the command is
364 executed as REMUSER. In *FD2P the descriptor to the socket for the
365 connection is returned. The caller must have the right to use a
366 reserved port. When the function returns *AHOST contains the
367 official host name. */
368 extern int rcmd (char **__restrict __ahost, unsigned short int __rport,
369 __const char *__restrict __locuser,
370 __const char *__restrict __remuser,
371 __const char *__restrict __cmd, int *__restrict __fd2p)
372 __THROW;
374 /* This is the equivalent function where the protocol can be selected
375 and which therefore can be used for IPv6. */
376 extern int rcmd_af (char **__restrict __ahost, unsigned short int __rport,
377 __const char *__restrict __locuser,
378 __const char *__restrict __remuser,
379 __const char *__restrict __cmd, int *__restrict __fd2p,
380 sa_family_t __af) __THROW;
382 /* Call `rexecd' at port RPORT on remote machine *AHOST to execute
383 CMD. The process runs at the remote machine using the ID of user
384 NAME whose cleartext password is PASSWD. In *FD2P the descriptor
385 to the socket for the connection is returned. When the function
386 returns *AHOST contains the official host name. */
387 extern int rexec (char **__restrict __ahost, int __rport,
388 __const char *__restrict __name,
389 __const char *__restrict __pass,
390 __const char *__restrict __cmd, int *__restrict __fd2p)
391 __THROW;
393 /* This is the equivalent function where the protocol can be selected
394 and which therefore can be used for IPv6. */
395 extern int rexec_af (char **__restrict __ahost, int __rport,
396 __const char *__restrict __name,
397 __const char *__restrict __pass,
398 __const char *__restrict __cmd, int *__restrict __fd2p,
399 sa_family_t __af) __THROW;
401 /* Check whether user REMUSER on system RHOST is allowed to login as LOCUSER.
402 If SUSER is not zero the user tries to become superuser. Return 0 if
403 it is possible. */
404 extern int ruserok (__const char *__rhost, int __suser,
405 __const char *__remuser, __const char *__locuser) __THROW;
407 /* This is the equivalent function where the protocol can be selected
408 and which therefore can be used for IPv6. */
409 extern int ruserok_af (__const char *__rhost, int __suser,
410 __const char *__remuser, __const char *__locuser,
411 sa_family_t __af) __THROW;
413 /* Try to allocate reserved port, returning a descriptor for a socket opened
414 at this port or -1 if unsuccessful. The search for an available port
415 will start at ALPORT and continues with lower numbers. */
416 extern int rresvport (int *__alport) __THROW;
418 /* This is the equivalent function where the protocol can be selected
419 and which therefore can be used for IPv6. */
420 extern int rresvport_af (int *__alport, sa_family_t __af) __THROW;
421 #endif
424 /* Extension from POSIX.1g. */
425 #ifdef __USE_POSIX
426 /* Structure to contain information about address of a service provider. */
427 struct addrinfo
429 int ai_flags; /* Input flags. */
430 int ai_family; /* Protocol family for socket. */
431 int ai_socktype; /* Socket type. */
432 int ai_protocol; /* Protocol for socket. */
433 socklen_t ai_addrlen; /* Length of socket address. */
434 struct sockaddr *ai_addr; /* Socket address for socket. */
435 char *ai_canonname; /* Canonical name for service location. */
436 struct addrinfo *ai_next; /* Pointer to next in list. */
439 /* Possible values for `ai_flags' field in `addrinfo' structure. */
440 # define AI_PASSIVE 1 /* Socket address is intended for `bind'. */
441 # define AI_CANONNAME 2 /* Request for canonical name. */
442 # define AI_NUMERICHOST 4 /* Don't use name resolution. */
444 /* Error values for `getaddrinfo' function. */
445 # define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */
446 # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
447 # define EAI_AGAIN -3 /* Temporary failure in name resolution. */
448 # define EAI_FAIL -4 /* Non-recoverable failure in name res. */
449 # define EAI_NODATA -5 /* No address associated with NAME. */
450 # define EAI_FAMILY -6 /* `ai_family' not supported. */
451 # define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */
452 # define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
453 # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
454 # define EAI_MEMORY -10 /* Memory allocation failure. */
455 # define EAI_SYSTEM -11 /* System error returned in `errno'. */
457 # define NI_MAXHOST 1025
458 # define NI_MAXSERV 32
460 # define NI_NUMERICHOST 1 /* Don't try to look up hostname. */
461 # define NI_NUMERICSERV 2 /* Don't convert port number to name. */
462 # define NI_NOFQDN 4 /* Only return nodename portion. */
463 # define NI_NAMEREQD 8 /* Don't return numeric addresses. */
464 # define NI_DGRAM 16 /* Look up UDP service rather than TCP. */
466 /* Translate name of a service location and/or a service name to set of
467 socket addresses. */
468 extern int getaddrinfo (__const char *__restrict __name,
469 __const char *__restrict __service,
470 __const struct addrinfo *__restrict __req,
471 struct addrinfo **__restrict __pai) __THROW;
473 /* Free `addrinfo' structure AI including associated storage. */
474 extern void freeaddrinfo (struct addrinfo *__ai) __THROW;
476 /* Convert error return from getaddrinfo() to a string. */
477 extern char *gai_strerror (int __ecode) __THROW;
479 /* Translate a socket address to a location and service name. */
480 extern int getnameinfo (__const struct sockaddr *__restrict __sa,
481 socklen_t __salen, char *__restrict __host,
482 socklen_t __hostlen, char *__restrict __serv,
483 socklen_t __servlen, int __flags) __THROW;
485 #endif /* POSIX */
487 __END_DECLS
489 #endif /* netdb.h */