Update.
[glibc.git] / resolv / netdb.h
blobd041163ac6785d8021558f348f83aa16e7740cba
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 extern int h_errno;
59 /* Function to get address of global `h_errno' variable. */
60 extern int *__h_errno_location (void) __THROW __attribute__ ((__const__));
62 /* Use a macro to access always the thread specific `h_errno' variable. */
63 #define h_errno (*__h_errno_location ())
66 /* Possible values left in `h_errno'. */
67 #define NETDB_INTERNAL -1 /* See errno. */
68 #define NETDB_SUCCESS 0 /* No problem. */
69 #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found. */
70 #define TRY_AGAIN 2 /* Non-Authoritative Host not found,
71 or SERVERFAIL. */
72 #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED,
73 NOTIMP. */
74 #define NO_DATA 4 /* Valid name, no data record of requested
75 type. */
76 #define NO_ADDRESS NO_DATA /* No address, look for MX record. */
78 #ifdef __USE_XOPEN2K
79 /* Highest reserved Internet port number. */
80 # define IPPORT_RESERVED 1024
81 #endif
83 #ifdef __USE_GNU
84 /* Scope delimiter for getaddrinfo(), getnameinfo(). */
85 # define SCOPE_DELIMITER '%'
86 #endif
88 /* Print error indicated by `h_errno' variable on standard error. STR
89 if non-null is printed before the error string. */
90 extern void herror (__const char *__str) __THROW;
92 /* Return string associated with error ERR_NUM. */
93 extern __const char *hstrerror (int __err_num) __THROW;
97 /* Description of data base entry for a single host. */
98 struct hostent
100 char *h_name; /* Official name of host. */
101 char **h_aliases; /* Alias list. */
102 int h_addrtype; /* Host address type. */
103 int h_length; /* Length of address. */
104 char **h_addr_list; /* List of addresses from name server. */
105 #define h_addr h_addr_list[0] /* Address, for backward compatibility. */
108 /* Open host data base files and mark them as staying open even after
109 a later search if STAY_OPEN is non-zero. */
110 extern void sethostent (int __stay_open) __THROW;
112 /* Close host data base files and clear `stay open' flag. */
113 extern void endhostent (void) __THROW;
115 /* Get next entry from host data base file. Open data base if
116 necessary. */
117 extern struct hostent *gethostent (void) __THROW;
119 /* Return entry from host data base which address match ADDR with
120 length LEN and type TYPE. */
121 extern struct hostent *gethostbyaddr (__const void *__addr, __socklen_t __len,
122 int __type) __THROW;
124 /* Return entry from host data base for host with NAME. */
125 extern struct hostent *gethostbyname (__const char *__name) __THROW;
127 #ifdef __USE_MISC
128 /* Return entry from host data base for host with NAME. AF must be
129 set to the address type which is `AF_INET' for IPv4 or `AF_INET6'
130 for IPv6. */
131 extern struct hostent *gethostbyname2 (__const char *__name, int __af) __THROW;
133 /* Reentrant versions of the functions above. The additional
134 arguments specify a buffer of BUFLEN starting at BUF. The last
135 argument is a pointer to a variable which gets the value which
136 would be stored in the global variable `herrno' by the
137 non-reentrant functions. */
138 extern int gethostent_r (struct hostent *__restrict __result_buf,
139 char *__restrict __buf, size_t __buflen,
140 struct hostent **__restrict __result,
141 int *__restrict __h_errnop) __THROW;
143 extern int gethostbyaddr_r (__const void *__restrict __addr, __socklen_t __len,
144 int __type,
145 struct hostent *__restrict __result_buf,
146 char *__restrict __buf, size_t __buflen,
147 struct hostent **__restrict __result,
148 int *__restrict __h_errnop) __THROW;
150 extern int gethostbyname_r (__const char *__restrict __name,
151 struct hostent *__restrict __result_buf,
152 char *__restrict __buf, size_t __buflen,
153 struct hostent **__restrict __result,
154 int *__restrict __h_errnop) __THROW;
156 extern int gethostbyname2_r (__const char *__restrict __name, int __af,
157 struct hostent *__restrict __result_buf,
158 char *__restrict __buf, size_t __buflen,
159 struct hostent **__restrict __result,
160 int *__restrict __h_errnop) __THROW;
161 #endif /* misc */
164 /* Open network data base files and mark them as staying open even
165 after a later search if STAY_OPEN is non-zero. */
166 extern void setnetent (int __stay_open) __THROW;
168 /* Close network data base files and clear `stay open' flag. */
169 extern void endnetent (void) __THROW;
171 /* Get next entry from network data base file. Open data base if
172 necessary. */
173 extern struct netent *getnetent (void) __THROW;
175 /* Return entry from network data base which address match NET and
176 type TYPE. */
177 extern struct netent *getnetbyaddr (uint32_t __net, int __type)
178 __THROW;
180 /* Return entry from network data base for network with NAME. */
181 extern struct netent *getnetbyname (__const char *__name) __THROW;
183 #ifdef __USE_MISC
184 /* Reentrant versions of the functions above. The additional
185 arguments specify a buffer of BUFLEN starting at BUF. The last
186 argument is a pointer to a variable which gets the value which
187 would be stored in the global variable `herrno' by the
188 non-reentrant functions. */
189 extern int getnetent_r (struct netent *__restrict __result_buf,
190 char *__restrict __buf, size_t __buflen,
191 struct netent **__restrict __result,
192 int *__restrict __h_errnop) __THROW;
194 extern int getnetbyaddr_r (uint32_t __net, int __type,
195 struct netent *__restrict __result_buf,
196 char *__restrict __buf, size_t __buflen,
197 struct netent **__restrict __result,
198 int *__restrict __h_errnop) __THROW;
200 extern int getnetbyname_r (__const char *__restrict __name,
201 struct netent *__restrict __result_buf,
202 char *__restrict __buf, size_t __buflen,
203 struct netent **__restrict __result,
204 int *__restrict __h_errnop) __THROW;
205 #endif /* misc */
208 /* Description of data base entry for a single service. */
209 struct servent
211 char *s_name; /* Official service name. */
212 char **s_aliases; /* Alias list. */
213 int s_port; /* Port number. */
214 char *s_proto; /* Protocol to use. */
217 /* Open service data base files and mark them as staying open even
218 after a later search if STAY_OPEN is non-zero. */
219 extern void setservent (int __stay_open) __THROW;
221 /* Close service data base files and clear `stay open' flag. */
222 extern void endservent (void) __THROW;
224 /* Get next entry from service data base file. Open data base if
225 necessary. */
226 extern struct servent *getservent (void) __THROW;
228 /* Return entry from network data base for network with NAME and
229 protocol PROTO. */
230 extern struct servent *getservbyname (__const char *__name,
231 __const char *__proto) __THROW;
233 /* Return entry from service data base which matches port PORT and
234 protocol PROTO. */
235 extern struct servent *getservbyport (int __port, __const char *__proto)
236 __THROW;
239 #ifdef __USE_MISC
240 /* Reentrant versions of the functions above. The additional
241 arguments specify a buffer of BUFLEN starting at BUF. */
242 extern int getservent_r (struct servent *__restrict __result_buf,
243 char *__restrict __buf, size_t __buflen,
244 struct servent **__restrict __result) __THROW;
246 extern int getservbyname_r (__const char *__restrict __name,
247 __const char *__restrict __proto,
248 struct servent *__restrict __result_buf,
249 char *__restrict __buf, size_t __buflen,
250 struct servent **__restrict __result) __THROW;
252 extern int getservbyport_r (int __port, __const char *__restrict __proto,
253 struct servent *__restrict __result_buf,
254 char *__restrict __buf, size_t __buflen,
255 struct servent **__restrict __result) __THROW;
256 #endif /* misc */
259 /* Description of data base entry for a single service. */
260 struct protoent
262 char *p_name; /* Official protocol name. */
263 char **p_aliases; /* Alias list. */
264 int p_proto; /* Protocol number. */
267 /* Open protocol data base files and mark them as staying open even
268 after a later search if STAY_OPEN is non-zero. */
269 extern void setprotoent (int __stay_open) __THROW;
271 /* Close protocol data base files and clear `stay open' flag. */
272 extern void endprotoent (void) __THROW;
274 /* Get next entry from protocol data base file. Open data base if
275 necessary. */
276 extern struct protoent *getprotoent (void) __THROW;
278 /* Return entry from protocol data base for network with NAME. */
279 extern struct protoent *getprotobyname (__const char *__name) __THROW;
281 /* Return entry from protocol data base which number is PROTO. */
282 extern struct protoent *getprotobynumber (int __proto) __THROW;
285 #ifdef __USE_MISC
286 /* Reentrant versions of the functions above. The additional
287 arguments specify a buffer of BUFLEN starting at BUF. */
288 extern int getprotoent_r (struct protoent *__restrict __result_buf,
289 char *__restrict __buf, size_t __buflen,
290 struct protoent **__restrict __result) __THROW;
292 extern int getprotobyname_r (__const char *__restrict __name,
293 struct protoent *__restrict __result_buf,
294 char *__restrict __buf, size_t __buflen,
295 struct protoent **__restrict __result) __THROW;
297 extern int getprotobynumber_r (int __proto,
298 struct protoent *__restrict __result_buf,
299 char *__restrict __buf, size_t __buflen,
300 struct protoent **__restrict __result) __THROW;
301 #endif /* misc */
304 /* Establish network group NETGROUP for enumeration. */
305 extern int setnetgrent (__const char *__netgroup) __THROW;
307 /* Free all space allocated by previous `setnetgrent' call. */
308 extern void endnetgrent (void) __THROW;
310 /* Get next member of netgroup established by last `setnetgrent' call
311 and return pointers to elements in HOSTP, USERP, and DOMAINP. */
312 extern int getnetgrent (char **__restrict __hostp,
313 char **__restrict __userp,
314 char **__restrict __domainp) __THROW;
316 #ifdef __USE_MISC
317 /* Test whether NETGROUP contains the triple (HOST,USER,DOMAIN). */
318 extern int innetgr (__const char *__netgroup, __const char *__host,
319 __const char *__user, __const char *domain) __THROW;
321 /* Reentrant version of `getnetgrent' where result is placed in BUFFER. */
322 extern int getnetgrent_r (char **__restrict __hostp,
323 char **__restrict __userp,
324 char **__restrict __domainp,
325 char *__restrict __buffer, size_t __buflen) __THROW;
326 #endif /* misc */
329 #ifdef __USE_BSD
330 /* Call `rshd' at port RPORT on remote machine *AHOST to execute CMD.
331 The local user is LOCUSER, on the remote machine the command is
332 executed as REMUSER. In *FD2P the descriptor to the socket for the
333 connection is returned. The caller must have the right to use a
334 reserved port. When the function returns *AHOST contains the
335 official host name. */
336 extern int rcmd (char **__restrict __ahost, unsigned short int __rport,
337 __const char *__restrict __locuser,
338 __const char *__restrict __remuser,
339 __const char *__restrict __cmd, int *__restrict __fd2p)
340 __THROW;
342 /* This is the equivalent function where the protocol can be selected
343 and which therefore can be used for IPv6. */
344 extern int rcmd_af (char **__restrict __ahost, unsigned short int __rport,
345 __const char *__restrict __locuser,
346 __const char *__restrict __remuser,
347 __const char *__restrict __cmd, int *__restrict __fd2p,
348 sa_family_t __af) __THROW;
350 /* Call `rexecd' at port RPORT on remote machine *AHOST to execute
351 CMD. The process runs at the remote machine using the ID of user
352 NAME whose cleartext password is PASSWD. In *FD2P the descriptor
353 to the socket for the connection is returned. When the function
354 returns *AHOST contains the official host name. */
355 extern int rexec (char **__restrict __ahost, int __rport,
356 __const char *__restrict __name,
357 __const char *__restrict __pass,
358 __const char *__restrict __cmd, int *__restrict __fd2p)
359 __THROW;
361 /* This is the equivalent function where the protocol can be selected
362 and which therefore can be used for IPv6. */
363 extern int rexec_af (char **__restrict __ahost, int __rport,
364 __const char *__restrict __name,
365 __const char *__restrict __pass,
366 __const char *__restrict __cmd, int *__restrict __fd2p,
367 sa_family_t __af) __THROW;
369 /* Check whether user REMUSER on system RHOST is allowed to login as LOCUSER.
370 If SUSER is not zero the user tries to become superuser. Return 0 if
371 it is possible. */
372 extern int ruserok (__const char *__rhost, int __suser,
373 __const char *__remuser, __const char *__locuser) __THROW;
375 /* This is the equivalent function where the protocol can be selected
376 and which therefore can be used for IPv6. */
377 extern int ruserok_af (__const char *__rhost, int __suser,
378 __const char *__remuser, __const char *__locuser,
379 sa_family_t __af) __THROW;
381 /* Try to allocate reserved port, returning a descriptor for a socket opened
382 at this port or -1 if unsuccessful. The search for an available port
383 will start at ALPORT and continues with lower numbers. */
384 extern int rresvport (int *__alport) __THROW;
386 /* This is the equivalent function where the protocol can be selected
387 and which therefore can be used for IPv6. */
388 extern int rresvport_af (int *__alport, sa_family_t __af) __THROW;
389 #endif
392 /* Extension from POSIX.1g. */
393 #ifdef __USE_POSIX
394 /* Structure to contain information about address of a service provider. */
395 struct addrinfo
397 int ai_flags; /* Input flags. */
398 int ai_family; /* Protocol family for socket. */
399 int ai_socktype; /* Socket type. */
400 int ai_protocol; /* Protocol for socket. */
401 socklen_t ai_addrlen; /* Length of socket address. */
402 struct sockaddr *ai_addr; /* Socket address for socket. */
403 char *ai_canonname; /* Canonical name for service location. */
404 struct addrinfo *ai_next; /* Pointer to next in list. */
407 # ifdef __USE_GNU
408 /* Structure used as control block for asynchronous lookup. */
409 struct gaicb
411 const char *ar_name; /* Name to look up. */
412 const char *ar_service; /* Service name. */
413 const struct addrinfo *ar_request; /* Additional request specification. */
414 struct addrinfo *ar_result; /* Pointer to result. */
415 /* The following are internal elements. */
416 int __return;
417 int __unused[5];
420 /* Lookup mode. */
421 # define GAI_WAIT 0
422 # define GAI_NOWAIT 1
423 # endif
425 /* Possible values for `ai_flags' field in `addrinfo' structure. */
426 # define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */
427 # define AI_CANONNAME 0x0002 /* Request for canonical name. */
428 # define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */
430 /* Error values for `getaddrinfo' function. */
431 # define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */
432 # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
433 # define EAI_AGAIN -3 /* Temporary failure in name resolution. */
434 # define EAI_FAIL -4 /* Non-recoverable failure in name res. */
435 # define EAI_NODATA -5 /* No address associated with NAME. */
436 # define EAI_FAMILY -6 /* `ai_family' not supported. */
437 # define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */
438 # define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
439 # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
440 # define EAI_MEMORY -10 /* Memory allocation failure. */
441 # define EAI_SYSTEM -11 /* System error returned in `errno'. */
442 # ifdef __USE_GNU
443 # define EAI_INPROGRESS -100 /* Processing request in progress. */
444 # define EAI_CANCELED -101 /* Request canceled. */
445 # define EAI_NOTCANCELED -102 /* Request not canceled. */
446 # define EAI_ALLDONE -103 /* All requests done. */
447 # define EAI_INTR -104 /* Interrupted by a signal. */
448 # endif
450 # define NI_MAXHOST 1025
451 # define NI_MAXSERV 32
453 # define NI_NUMERICHOST 1 /* Don't try to look up hostname. */
454 # define NI_NUMERICSERV 2 /* Don't convert port number to name. */
455 # define NI_NOFQDN 4 /* Only return nodename portion. */
456 # define NI_NAMEREQD 8 /* Don't return numeric addresses. */
457 # define NI_DGRAM 16 /* Look up UDP service rather than TCP. */
459 /* Translate name of a service location and/or a service name to set of
460 socket addresses. */
461 extern int getaddrinfo (__const char *__restrict __name,
462 __const char *__restrict __service,
463 __const struct addrinfo *__restrict __req,
464 struct addrinfo **__restrict __pai) __THROW;
466 /* Free `addrinfo' structure AI including associated storage. */
467 extern void freeaddrinfo (struct addrinfo *__ai) __THROW;
469 /* Convert error return from getaddrinfo() to a string. */
470 extern __const char *gai_strerror (int __ecode) __THROW;
472 /* Translate a socket address to a location and service name. */
473 extern int getnameinfo (__const struct sockaddr *__restrict __sa,
474 socklen_t __salen, char *__restrict __host,
475 socklen_t __hostlen, char *__restrict __serv,
476 socklen_t __servlen, unsigned int __flags) __THROW;
478 # ifdef __USE_GNU
479 /* Enqueue ENT requests from the LIST. If MODE is GAI_WAIT wait until all
480 requests are handled. If WAIT is GAI_NOWAIT return immediately after
481 queueing the requests and signal completion according to SIG. */
482 extern int getaddrinfo_a (int __mode, struct gaicb *__list[__restrict_arr],
483 int __ent, struct sigevent *__restrict __sig)
484 __THROW;
486 /* Suspend execution of the thread until at least one of the ENT requests
487 in LIST is handled. If TIMEOUT is not a null pointer it specifies the
488 longest time the function keeps waiting before returning with an error. */
489 extern int gai_suspend (__const struct gaicb *__const __list[], int __ent,
490 __const struct timespec *__timeout) __THROW;
492 /* Get the error status of the request REQ. */
493 extern int gai_error (struct gaicb *__req) __THROW;
495 /* Cancel the requests associated with GAICBP. */
496 extern int gai_cancel (struct gaicb *__gaicbp) __THROW;
497 # endif /* GNU */
498 #endif /* POSIX */
500 __END_DECLS
502 #endif /* netdb.h */