Optimize for kernels which are known to have the vfork syscall.
[glibc/pb-stable.git] / resolv / netdb.h
blobd153c9b325152aa3c573d0bdb6100e93596664a7
1 /* Copyright (C) 1996,97,98,99,2000,01,02 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 and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 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 #include <netinet/in.h>
29 #include <stdint.h>
30 #ifdef __USE_MISC
31 /* This is necessary to make this include file properly replace the
32 Sun version. */
33 # include <rpc/netdb.h>
34 #endif
36 #ifdef __USE_GNU
37 # define __need_sigevent_t
38 # include <bits/siginfo.h>
39 # define __need_timespec
40 # include <time.h>
41 #endif
43 #include <bits/netdb.h>
45 /* Absolute file name for network data base files. */
46 #define _PATH_HEQUIV "/etc/hosts.equiv"
47 #define _PATH_HOSTS "/etc/hosts"
48 #define _PATH_NETWORKS "/etc/networks"
49 #define _PATH_NSSWITCH_CONF "/etc/nsswitch.conf"
50 #define _PATH_PROTOCOLS "/etc/protocols"
51 #define _PATH_SERVICES "/etc/services"
54 __BEGIN_DECLS
56 /* Error status for non-reentrant lookup functions.
57 We use a macro to access always the thread-specific `h_errno' variable. */
58 #define h_errno (*__h_errno_location ())
60 /* Function to get address of global `h_errno' variable. */
61 extern int *__h_errno_location (void) __THROW __attribute__ ((__const__));
64 /* Possible values left in `h_errno'. */
65 #define NETDB_INTERNAL -1 /* See errno. */
66 #define NETDB_SUCCESS 0 /* No problem. */
67 #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found. */
68 #define TRY_AGAIN 2 /* Non-Authoritative Host not found,
69 or SERVERFAIL. */
70 #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED,
71 NOTIMP. */
72 #define NO_DATA 4 /* Valid name, no data record of requested
73 type. */
74 #define NO_ADDRESS NO_DATA /* No address, look for MX record. */
76 #ifdef __USE_XOPEN2K
77 /* Highest reserved Internet port number. */
78 # define IPPORT_RESERVED 1024
79 #endif
81 #ifdef __USE_GNU
82 /* Scope delimiter for getaddrinfo(), getnameinfo(). */
83 # define SCOPE_DELIMITER '%'
84 #endif
86 /* Print error indicated by `h_errno' variable on standard error. STR
87 if non-null is printed before the error string. */
88 extern void herror (__const char *__str) __THROW;
90 /* Return string associated with error ERR_NUM. */
91 extern __const char *hstrerror (int __err_num) __THROW;
95 /* Description of data base entry for a single host. */
96 struct hostent
98 char *h_name; /* Official name of host. */
99 char **h_aliases; /* Alias list. */
100 int h_addrtype; /* Host address type. */
101 int h_length; /* Length of address. */
102 char **h_addr_list; /* List of addresses from name server. */
103 #define h_addr h_addr_list[0] /* Address, for backward compatibility. */
106 /* Open host data base files and mark them as staying open even after
107 a later search if STAY_OPEN is non-zero. */
108 extern void sethostent (int __stay_open) __THROW;
110 /* Close host data base files and clear `stay open' flag. */
111 extern void endhostent (void) __THROW;
113 /* Get next entry from host data base file. Open data base if
114 necessary. */
115 extern struct hostent *gethostent (void) __THROW;
117 /* Return entry from host data base which address match ADDR with
118 length LEN and type TYPE. */
119 extern struct hostent *gethostbyaddr (__const void *__addr, __socklen_t __len,
120 int __type) __THROW;
122 /* Return entry from host data base for host with NAME. */
123 extern struct hostent *gethostbyname (__const char *__name) __THROW;
125 #ifdef __USE_MISC
126 /* Return entry from host data base for host with NAME. AF must be
127 set to the address type which is `AF_INET' for IPv4 or `AF_INET6'
128 for IPv6. */
129 extern struct hostent *gethostbyname2 (__const char *__name, int __af) __THROW;
131 /* Reentrant versions of the functions above. The additional
132 arguments specify a buffer of BUFLEN starting at BUF. The last
133 argument is a pointer to a variable which gets the value which
134 would be stored in the global variable `herrno' by the
135 non-reentrant functions. */
136 extern int gethostent_r (struct hostent *__restrict __result_buf,
137 char *__restrict __buf, size_t __buflen,
138 struct hostent **__restrict __result,
139 int *__restrict __h_errnop) __THROW;
141 extern int gethostbyaddr_r (__const void *__restrict __addr, __socklen_t __len,
142 int __type,
143 struct hostent *__restrict __result_buf,
144 char *__restrict __buf, size_t __buflen,
145 struct hostent **__restrict __result,
146 int *__restrict __h_errnop) __THROW;
148 extern int gethostbyname_r (__const char *__restrict __name,
149 struct hostent *__restrict __result_buf,
150 char *__restrict __buf, size_t __buflen,
151 struct hostent **__restrict __result,
152 int *__restrict __h_errnop) __THROW;
154 extern int gethostbyname2_r (__const char *__restrict __name, int __af,
155 struct hostent *__restrict __result_buf,
156 char *__restrict __buf, size_t __buflen,
157 struct hostent **__restrict __result,
158 int *__restrict __h_errnop) __THROW;
159 #endif /* misc */
162 /* Open network data base files and mark them as staying open even
163 after a later search if STAY_OPEN is non-zero. */
164 extern void setnetent (int __stay_open) __THROW;
166 /* Close network data base files and clear `stay open' flag. */
167 extern void endnetent (void) __THROW;
169 /* Get next entry from network data base file. Open data base if
170 necessary. */
171 extern struct netent *getnetent (void) __THROW;
173 /* Return entry from network data base which address match NET and
174 type TYPE. */
175 extern struct netent *getnetbyaddr (uint32_t __net, int __type)
176 __THROW;
178 /* Return entry from network data base for network with NAME. */
179 extern struct netent *getnetbyname (__const char *__name) __THROW;
181 #ifdef __USE_MISC
182 /* Reentrant versions of the functions above. The additional
183 arguments specify a buffer of BUFLEN starting at BUF. The last
184 argument is a pointer to a variable which gets the value which
185 would be stored in the global variable `herrno' by the
186 non-reentrant functions. */
187 extern int getnetent_r (struct netent *__restrict __result_buf,
188 char *__restrict __buf, size_t __buflen,
189 struct netent **__restrict __result,
190 int *__restrict __h_errnop) __THROW;
192 extern int getnetbyaddr_r (uint32_t __net, int __type,
193 struct netent *__restrict __result_buf,
194 char *__restrict __buf, size_t __buflen,
195 struct netent **__restrict __result,
196 int *__restrict __h_errnop) __THROW;
198 extern int getnetbyname_r (__const char *__restrict __name,
199 struct netent *__restrict __result_buf,
200 char *__restrict __buf, size_t __buflen,
201 struct netent **__restrict __result,
202 int *__restrict __h_errnop) __THROW;
203 #endif /* misc */
206 /* Description of data base entry for a single service. */
207 struct servent
209 char *s_name; /* Official service name. */
210 char **s_aliases; /* Alias list. */
211 int s_port; /* Port number. */
212 char *s_proto; /* Protocol to use. */
215 /* Open service data base files and mark them as staying open even
216 after a later search if STAY_OPEN is non-zero. */
217 extern void setservent (int __stay_open) __THROW;
219 /* Close service data base files and clear `stay open' flag. */
220 extern void endservent (void) __THROW;
222 /* Get next entry from service data base file. Open data base if
223 necessary. */
224 extern struct servent *getservent (void) __THROW;
226 /* Return entry from network data base for network with NAME and
227 protocol PROTO. */
228 extern struct servent *getservbyname (__const char *__name,
229 __const char *__proto) __THROW;
231 /* Return entry from service data base which matches port PORT and
232 protocol PROTO. */
233 extern struct servent *getservbyport (int __port, __const char *__proto)
234 __THROW;
237 #ifdef __USE_MISC
238 /* Reentrant versions of the functions above. The additional
239 arguments specify a buffer of BUFLEN starting at BUF. */
240 extern int getservent_r (struct servent *__restrict __result_buf,
241 char *__restrict __buf, size_t __buflen,
242 struct servent **__restrict __result) __THROW;
244 extern int getservbyname_r (__const char *__restrict __name,
245 __const char *__restrict __proto,
246 struct servent *__restrict __result_buf,
247 char *__restrict __buf, size_t __buflen,
248 struct servent **__restrict __result) __THROW;
250 extern int getservbyport_r (int __port, __const char *__restrict __proto,
251 struct servent *__restrict __result_buf,
252 char *__restrict __buf, size_t __buflen,
253 struct servent **__restrict __result) __THROW;
254 #endif /* misc */
257 /* Description of data base entry for a single service. */
258 struct protoent
260 char *p_name; /* Official protocol name. */
261 char **p_aliases; /* Alias list. */
262 int p_proto; /* Protocol number. */
265 /* Open protocol data base files and mark them as staying open even
266 after a later search if STAY_OPEN is non-zero. */
267 extern void setprotoent (int __stay_open) __THROW;
269 /* Close protocol data base files and clear `stay open' flag. */
270 extern void endprotoent (void) __THROW;
272 /* Get next entry from protocol data base file. Open data base if
273 necessary. */
274 extern struct protoent *getprotoent (void) __THROW;
276 /* Return entry from protocol data base for network with NAME. */
277 extern struct protoent *getprotobyname (__const char *__name) __THROW;
279 /* Return entry from protocol data base which number is PROTO. */
280 extern struct protoent *getprotobynumber (int __proto) __THROW;
283 #ifdef __USE_MISC
284 /* Reentrant versions of the functions above. The additional
285 arguments specify a buffer of BUFLEN starting at BUF. */
286 extern int getprotoent_r (struct protoent *__restrict __result_buf,
287 char *__restrict __buf, size_t __buflen,
288 struct protoent **__restrict __result) __THROW;
290 extern int getprotobyname_r (__const char *__restrict __name,
291 struct protoent *__restrict __result_buf,
292 char *__restrict __buf, size_t __buflen,
293 struct protoent **__restrict __result) __THROW;
295 extern int getprotobynumber_r (int __proto,
296 struct protoent *__restrict __result_buf,
297 char *__restrict __buf, size_t __buflen,
298 struct protoent **__restrict __result) __THROW;
299 #endif /* misc */
302 /* Establish network group NETGROUP for enumeration. */
303 extern int setnetgrent (__const char *__netgroup) __THROW;
305 /* Free all space allocated by previous `setnetgrent' call. */
306 extern void endnetgrent (void) __THROW;
308 /* Get next member of netgroup established by last `setnetgrent' call
309 and return pointers to elements in HOSTP, USERP, and DOMAINP. */
310 extern int getnetgrent (char **__restrict __hostp,
311 char **__restrict __userp,
312 char **__restrict __domainp) __THROW;
314 #ifdef __USE_MISC
315 /* Test whether NETGROUP contains the triple (HOST,USER,DOMAIN). */
316 extern int innetgr (__const char *__netgroup, __const char *__host,
317 __const char *__user, __const char *domain) __THROW;
319 /* Reentrant version of `getnetgrent' where result is placed in BUFFER. */
320 extern int getnetgrent_r (char **__restrict __hostp,
321 char **__restrict __userp,
322 char **__restrict __domainp,
323 char *__restrict __buffer, size_t __buflen) __THROW;
324 #endif /* misc */
327 #ifdef __USE_BSD
328 /* Call `rshd' at port RPORT on remote machine *AHOST to execute CMD.
329 The local user is LOCUSER, on the remote machine the command is
330 executed as REMUSER. In *FD2P the descriptor to the socket for the
331 connection is returned. The caller must have the right to use a
332 reserved port. When the function returns *AHOST contains the
333 official host name. */
334 extern int rcmd (char **__restrict __ahost, unsigned short int __rport,
335 __const char *__restrict __locuser,
336 __const char *__restrict __remuser,
337 __const char *__restrict __cmd, int *__restrict __fd2p)
338 __THROW;
340 /* This is the equivalent function where the protocol can be selected
341 and which therefore can be used for IPv6. */
342 extern int rcmd_af (char **__restrict __ahost, unsigned short int __rport,
343 __const char *__restrict __locuser,
344 __const char *__restrict __remuser,
345 __const char *__restrict __cmd, int *__restrict __fd2p,
346 sa_family_t __af) __THROW;
348 /* Call `rexecd' at port RPORT on remote machine *AHOST to execute
349 CMD. The process runs at the remote machine using the ID of user
350 NAME whose cleartext password is PASSWD. In *FD2P the descriptor
351 to the socket for the connection is returned. When the function
352 returns *AHOST contains the official host name. */
353 extern int rexec (char **__restrict __ahost, int __rport,
354 __const char *__restrict __name,
355 __const char *__restrict __pass,
356 __const char *__restrict __cmd, int *__restrict __fd2p)
357 __THROW;
359 /* This is the equivalent function where the protocol can be selected
360 and which therefore can be used for IPv6. */
361 extern int rexec_af (char **__restrict __ahost, int __rport,
362 __const char *__restrict __name,
363 __const char *__restrict __pass,
364 __const char *__restrict __cmd, int *__restrict __fd2p,
365 sa_family_t __af) __THROW;
367 /* Check whether user REMUSER on system RHOST is allowed to login as LOCUSER.
368 If SUSER is not zero the user tries to become superuser. Return 0 if
369 it is possible. */
370 extern int ruserok (__const char *__rhost, int __suser,
371 __const char *__remuser, __const char *__locuser) __THROW;
373 /* This is the equivalent function where the protocol can be selected
374 and which therefore can be used for IPv6. */
375 extern int ruserok_af (__const char *__rhost, int __suser,
376 __const char *__remuser, __const char *__locuser,
377 sa_family_t __af) __THROW;
379 /* Try to allocate reserved port, returning a descriptor for a socket opened
380 at this port or -1 if unsuccessful. The search for an available port
381 will start at ALPORT and continues with lower numbers. */
382 extern int rresvport (int *__alport) __THROW;
384 /* This is the equivalent function where the protocol can be selected
385 and which therefore can be used for IPv6. */
386 extern int rresvport_af (int *__alport, sa_family_t __af) __THROW;
387 #endif
390 /* Extension from POSIX.1g. */
391 #ifdef __USE_POSIX
392 /* Structure to contain information about address of a service provider. */
393 struct addrinfo
395 int ai_flags; /* Input flags. */
396 int ai_family; /* Protocol family for socket. */
397 int ai_socktype; /* Socket type. */
398 int ai_protocol; /* Protocol for socket. */
399 socklen_t ai_addrlen; /* Length of socket address. */
400 struct sockaddr *ai_addr; /* Socket address for socket. */
401 char *ai_canonname; /* Canonical name for service location. */
402 struct addrinfo *ai_next; /* Pointer to next in list. */
405 # ifdef __USE_GNU
406 /* Structure used as control block for asynchronous lookup. */
407 struct gaicb
409 const char *ar_name; /* Name to look up. */
410 const char *ar_service; /* Service name. */
411 const struct addrinfo *ar_request; /* Additional request specification. */
412 struct addrinfo *ar_result; /* Pointer to result. */
413 /* The following are internal elements. */
414 int __return;
415 int __unused[5];
418 /* Lookup mode. */
419 # define GAI_WAIT 0
420 # define GAI_NOWAIT 1
421 # endif
423 /* Possible values for `ai_flags' field in `addrinfo' structure. */
424 # define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */
425 # define AI_CANONNAME 0x0002 /* Request for canonical name. */
426 # define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */
428 /* Error values for `getaddrinfo' function. */
429 # define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */
430 # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
431 # define EAI_AGAIN -3 /* Temporary failure in name resolution. */
432 # define EAI_FAIL -4 /* Non-recoverable failure in name res. */
433 # define EAI_NODATA -5 /* No address associated with NAME. */
434 # define EAI_FAMILY -6 /* `ai_family' not supported. */
435 # define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */
436 # define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
437 # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
438 # define EAI_MEMORY -10 /* Memory allocation failure. */
439 # define EAI_SYSTEM -11 /* System error returned in `errno'. */
440 # ifdef __USE_GNU
441 # define EAI_INPROGRESS -100 /* Processing request in progress. */
442 # define EAI_CANCELED -101 /* Request canceled. */
443 # define EAI_NOTCANCELED -102 /* Request not canceled. */
444 # define EAI_ALLDONE -103 /* All requests done. */
445 # define EAI_INTR -104 /* Interrupted by a signal. */
446 # endif
448 # define NI_MAXHOST 1025
449 # define NI_MAXSERV 32
451 # define NI_NUMERICHOST 1 /* Don't try to look up hostname. */
452 # define NI_NUMERICSERV 2 /* Don't convert port number to name. */
453 # define NI_NOFQDN 4 /* Only return nodename portion. */
454 # define NI_NAMEREQD 8 /* Don't return numeric addresses. */
455 # define NI_DGRAM 16 /* Look up UDP service rather than TCP. */
457 /* Translate name of a service location and/or a service name to set of
458 socket addresses. */
459 extern int getaddrinfo (__const char *__restrict __name,
460 __const char *__restrict __service,
461 __const struct addrinfo *__restrict __req,
462 struct addrinfo **__restrict __pai) __THROW;
464 /* Free `addrinfo' structure AI including associated storage. */
465 extern void freeaddrinfo (struct addrinfo *__ai) __THROW;
467 /* Convert error return from getaddrinfo() to a string. */
468 extern __const char *gai_strerror (int __ecode) __THROW;
470 /* Translate a socket address to a location and service name. */
471 extern int getnameinfo (__const struct sockaddr *__restrict __sa,
472 socklen_t __salen, char *__restrict __host,
473 socklen_t __hostlen, char *__restrict __serv,
474 socklen_t __servlen, unsigned int __flags) __THROW;
476 # ifdef __USE_GNU
477 /* Enqueue ENT requests from the LIST. If MODE is GAI_WAIT wait until all
478 requests are handled. If WAIT is GAI_NOWAIT return immediately after
479 queueing the requests and signal completion according to SIG. */
480 extern int getaddrinfo_a (int __mode, struct gaicb *__list[__restrict_arr],
481 int __ent, struct sigevent *__restrict __sig)
482 __THROW;
484 /* Suspend execution of the thread until at least one of the ENT requests
485 in LIST is handled. If TIMEOUT is not a null pointer it specifies the
486 longest time the function keeps waiting before returning with an error. */
487 extern int gai_suspend (__const struct gaicb *__const __list[], int __ent,
488 __const struct timespec *__timeout) __THROW;
490 /* Get the error status of the request REQ. */
491 extern int gai_error (struct gaicb *__req) __THROW;
493 /* Cancel the requests associated with GAICBP. */
494 extern int gai_cancel (struct gaicb *__gaicbp) __THROW;
495 # endif /* GNU */
496 #endif /* POSIX */
498 __END_DECLS
500 #endif /* netdb.h */