Regenerated: /usr/bin/perl scripts/gen-FAQ.pl FAQ.in
[glibc.git] / resolv / netdb.h
blob299d695eaa22b8d66e6ac9f3ce11510590081075
1 /* Copyright (C) 1996, 1997, 1998 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 /* Absolute file name for network data base files. */
36 #define _PATH_HEQUIV "/etc/hosts.equiv"
37 #define _PATH_HOSTS "/etc/hosts"
38 #define _PATH_NETWORKS "/etc/networks"
39 #define _PATH_NSSWITCH_CONF "/etc/nsswitch.conf"
40 #define _PATH_PROTOCOLS "/etc/protocols"
41 #define _PATH_SERVICES "/etc/services"
44 __BEGIN_DECLS
46 /* Error status for non-reentrant lookup functions. */
47 extern int h_errno;
49 /* Function to get address of global `h_errno' variable. */
50 extern int *__h_errno_location __P ((void)) __attribute__ ((__const__));
52 #ifdef _LIBC
53 # ifdef _LIBC_REENTRANT
54 static inline int
55 __set_h_errno (int __err)
57 return *__h_errno_location () = __err;
59 # else
60 # define __set_h_errno(x) (h_errno = (x))
61 # endif /* _LIBC_REENTRANT */
62 #endif /* _LIBC */
65 #if !defined _LIBC || defined _LIBC_REENTRANT
66 /* Use a macro to access always the thread specific `h_errno' variable. */
67 # define h_errno (*__h_errno_location ())
68 #endif
71 /* Possible values left in `h_errno'. */
72 #define NETDB_INTERNAL -1 /* See errno. */
73 #define NETDB_SUCCESS 0 /* No problem. */
74 #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found. */
75 #define TRY_AGAIN 2 /* Non-Authoritative Host not found,
76 or SERVERFAIL. */
77 #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED,
78 NOTIMP. */
79 #define NO_DATA 4 /* Valid name, no data record of requested
80 type. */
81 #define NO_ADDRESS NO_DATA /* No address, look for MX record. */
83 /* Print error indicated by `h_errno' variable on standard error. STR
84 if non-null is printed before the error string. */
85 extern void herror __P ((__const char *__str));
87 /* Return string associated with error ERR_NUM. */
88 extern __const char *hstrerror __P ((int __err_num));
92 /* Description of data base entry for a single host. */
93 struct hostent
95 char *h_name; /* Official name of host. */
96 char **h_aliases; /* Alias list. */
97 int h_addrtype; /* Host address type. */
98 int h_length; /* Length of address. */
99 char **h_addr_list; /* List of addresses from name server. */
100 #define h_addr h_addr_list[0] /* Address, for backward compatibility. */
103 /* Open host data base files and mark them as staying open even after
104 a later search if STAY_OPEN is non-zero. */
105 extern void sethostent __P ((int __stay_open));
107 /* Close host data base files and clear `stay open' flag. */
108 extern void endhostent __P ((void));
110 /* Get next entry from host data base file. Open data base if
111 necessary. */
112 extern struct hostent *gethostent __P ((void));
114 /* Return entry from host data base which address match ADDR with
115 length LEN and type TYPE. */
116 extern struct hostent *gethostbyaddr __P ((__const char *__addr, int __len,
117 int __type));
119 /* Return entry from host data base for host with NAME. */
120 extern struct hostent *gethostbyname __P ((__const char *__name));
122 /* Return entry from host data base for host with NAME. AF must be
123 set to the address type which is `AF_INET' for IPv4 or `AF_INET6'
124 for IPv6. */
125 extern struct hostent *gethostbyname2 __P ((__const char *__name, int __af));
127 #ifdef __USE_MISC
128 /* Reentrant versions of the functions above. The additional
129 arguments specify a buffer of BUFLEN starting at BUF. The last
130 argument is a pointer to a variable which gets the value which
131 would be stored in the global variable `herrno' by the
132 non-reentrant functions. */
133 extern int gethostent_r __P ((struct hostent *__restrict __result_buf,
134 char *__restrict __buf, size_t __buflen,
135 struct hostent **__restrict __result,
136 int *__restrict __h_errnop));
138 extern int gethostbyaddr_r __P ((__const char *__restrict __addr, int __len,
139 int __type,
140 struct hostent *__restrict __result_buf,
141 char *__restrict __buf, size_t __buflen,
142 struct hostent **__restrict __result,
143 int *__restrict __h_errnop));
145 extern int gethostbyname_r __P ((__const char *__restrict __name,
146 struct hostent *__restrict __result_buf,
147 char *__restrict __buf, size_t __buflen,
148 struct hostent **__restrict __result,
149 int *__restrict __h_errnop));
151 extern int gethostbyname2_r __P ((__const char *__restrict __name, int __af,
152 struct hostent *__restrict __result_buf,
153 char *__restrict __buf, size_t __buflen,
154 struct hostent **__restrict __result,
155 int *__restrict __h_errnop));
156 #endif /* misc */
159 /* Return entry from host data base for host with NAME. AF must be
160 set to the desired address type (either `AF_INET' or `AF_INET6').
161 FLAGS is some combination of the following AI_* values. */
162 extern struct hostent *getnodebyname __P ((__const char *__name, int __af,
163 int __flags));
165 #define AI_V4MAPPED 1 /* IPv4-mapped addresses are acceptable. */
166 #define AI_ALL 2 /* Return both IPv4 and IPv6 addresses. */
167 #define AI_ADDRCONFIG 4 /* Use configuration of this host to choose
168 returned address type. */
169 #define AI_DEFAULT (AI_V4MAPPED | AI_ADDRCONFIG)
172 /* Description of data base entry for a single network. NOTE: here a
173 poor assumption is made. The network number is expected to fit
174 into an unsigned long int variable. */
175 struct netent
177 char *n_name; /* Official name of network. */
178 char **n_aliases; /* Alias list. */
179 int n_addrtype; /* Net address type. */
180 unsigned long int n_net; /* Network number. */
183 /* Open network data base files and mark them as staying open even
184 after a later search if STAY_OPEN is non-zero. */
185 extern void setnetent __P ((int __stay_open));
187 /* Close network data base files and clear `stay open' flag. */
188 extern void endnetent __P ((void));
190 /* Get next entry from network data base file. Open data base if
191 necessary. */
192 extern struct netent *getnetent __P ((void));
194 /* Return entry from network data base which address match NET and
195 type TYPE. */
196 extern struct netent *getnetbyaddr __P ((unsigned long int __net,
197 int __type));
199 /* Return entry from network data base for network with NAME. */
200 extern struct netent *getnetbyname __P ((__const char *__name));
202 #ifdef __USE_MISC
203 /* Reentrant versions of the functions above. The additional
204 arguments specify a buffer of BUFLEN starting at BUF. The last
205 argument is a pointer to a variable which gets the value which
206 would be stored in the global variable `herrno' by the
207 non-reentrant functions. */
208 extern int getnetent_r __P ((struct netent *__restrict __result_buf,
209 char *__restrict __buf, size_t __buflen,
210 struct netent **__restrict __result,
211 int *__restrict __h_errnop));
213 extern int getnetbyaddr_r __P ((unsigned long int __net, int __type,
214 struct netent *__restrict __result_buf,
215 char *__restrict __buf, size_t __buflen,
216 struct netent **__restrict __result,
217 int *__restrict __h_errnop));
219 extern int getnetbyname_r __P ((__const char *__restrict __name,
220 struct netent *__restrict __result_buf,
221 char *__restrict __buf, size_t __buflen,
222 struct netent **__restrict __result,
223 int *__restrict __h_errnop));
224 #endif /* misc */
227 /* Description of data base entry for a single service. */
228 struct servent
230 char *s_name; /* Official service name. */
231 char **s_aliases; /* Alias list. */
232 int s_port; /* Port number. */
233 char *s_proto; /* Protocol to use. */
236 /* Open service data base files and mark them as staying open even
237 after a later search if STAY_OPEN is non-zero. */
238 extern void setservent __P ((int __stay_open));
240 /* Close service data base files and clear `stay open' flag. */
241 extern void endservent __P ((void));
243 /* Get next entry from service data base file. Open data base if
244 necessary. */
245 extern struct servent *getservent __P ((void));
247 /* Return entry from network data base for network with NAME and
248 protocol PROTO. */
249 extern struct servent *getservbyname __P ((__const char *__name,
250 __const char *__proto));
252 /* Return entry from service data base which matches port PORT and
253 protocol PROTO. */
254 extern struct servent *getservbyport __P ((int __port, __const char *__proto));
257 #ifdef __USE_MISC
258 /* Reentrant versions of the functions above. The additional
259 arguments specify a buffer of BUFLEN starting at BUF. */
260 extern int getservent_r __P ((struct servent *__restrict __result_buf,
261 char *__restrict __buf, size_t __buflen,
262 struct servent **__restrict __result));
264 extern int getservbyname_r __P ((__const char *__restrict __name,
265 __const char *__restrict __proto,
266 struct servent *__restrict __result_buf,
267 char *__restrict __buf, size_t __buflen,
268 struct servent **__restrict __result));
270 extern int getservbyport_r __P ((int __port, __const char *__restrict __proto,
271 struct servent *__restrict __result_buf,
272 char *__restrict __buf, size_t __buflen,
273 struct servent **__restrict __result));
274 #endif /* misc */
277 /* Description of data base entry for a single service. */
278 struct protoent
280 char *p_name; /* Official protocol name. */
281 char **p_aliases; /* Alias list. */
282 int p_proto; /* Protocol number. */
285 /* Open protocol data base files and mark them as staying open even
286 after a later search if STAY_OPEN is non-zero. */
287 extern void setprotoent __P ((int __stay_open));
289 /* Close protocol data base files and clear `stay open' flag. */
290 extern void endprotoent __P ((void));
292 /* Get next entry from protocol data base file. Open data base if
293 necessary. */
294 extern struct protoent *getprotoent __P ((void));
296 /* Return entry from protocol data base for network with NAME. */
297 extern struct protoent *getprotobyname __P ((__const char *__name));
299 /* Return entry from protocol data base which number is PROTO. */
300 extern struct protoent *getprotobynumber __P ((int __proto));
303 #ifdef __USE_MISC
304 /* Reentrant versions of the functions above. The additional
305 arguments specify a buffer of BUFLEN starting at BUF. */
306 extern int getprotoent_r __P ((struct protoent *__restrict __result_buf,
307 char *__restrict __buf, size_t __buflen,
308 struct protoent **__restrict __result));
310 extern int getprotobyname_r __P ((__const char *__restrict __name,
311 struct protoent *__restrict __result_buf,
312 char *__restrict __buf, size_t __buflen,
313 struct protoent **__restrict __result));
315 extern int getprotobynumber_r __P ((int __proto,
316 struct protoent *__restrict __result_buf,
317 char *__restrict __buf, size_t __buflen,
318 struct protoent **__restrict __result));
319 #endif /* misc */
322 /* Establish network group NETGROUP for enumeration. */
323 extern int setnetgrent __P ((__const char *__netgroup));
325 /* Free all space allocated by previous `setnetgrent' call. */
326 extern void endnetgrent __P ((void));
328 /* Get next member of netgroup established by last `setnetgrent' call
329 and return pointers to elements in HOSTP, USERP, and DOMAINP. */
330 extern int getnetgrent __P ((char **__restrict __hostp,
331 char **__restrict __userp,
332 char **__restrict __domainp));
334 /* Test whether NETGROUP contains the triple (HOST,USER,DOMAIN). */
335 extern int innetgr __P ((__const char *__netgroup, __const char *__host,
336 __const char *__user, __const char *domain));
338 #ifdef __USE_MISC
339 /* Reentrant version of `getnetgrent' where result is placed in BUFFER. */
340 extern int getnetgrent_r __P ((char **__restrict __hostp,
341 char **__restrict __userp,
342 char **__restrict __domainp,
343 char *__restrict __buffer, size_t __buflen));
344 #endif /* misc */
347 #ifdef __USE_BSD
348 /* Call `rshd' at port RPORT on remote machine *AHOST to execute CMD.
349 The local user is LOCUSER, on the remote machine the command is
350 executed as REMUSER. In *FD2P the descriptor to the socket for the
351 connection is returned. The caller must have the right to use a
352 reserved port. When the function returns *AHOST contains the
353 official host name. */
354 extern int rcmd __P ((char **__restrict __ahost, unsigned short int __rport,
355 __const char *__restrict __locuser,
356 __const char *__restrict __remuser,
357 __const char *__restrict __cmd, int *__restrict __fd2p));
359 /* Call `rexecd' at port RPORT on remote machine *AHOST to execute
360 CMD. The process runs at the remote machine using the ID of user
361 NAME whose cleartext password is PASSWD. In *FD2P the descriptor
362 to the socket for the connection is returned. When the function
363 returns *AHOST contains the official host name. */
364 extern int rexec __P ((char **__restrict __ahost, int __rport,
365 __const char *__restrict __name,
366 __const char *__restrict __pass,
367 __const char *__restrict __cmd,
368 int *__restrict __fd2p));
370 /* Check whether user REMUSER on system RHOST is allowed to login as LOCUSER.
371 If SUSER is not zero the user tries to become superuser. Return 0 if
372 it is possible. */
373 extern int ruserok __P ((__const char *__rhost, int __suser,
374 __const char *__remuser, __const char *__locuser));
376 /* Try to allocate reserved port, returning a descriptor for a socket opened
377 at this port or -1 if unsuccessful. The search for an available port
378 will start at ALPORT and continues with lower numbers. */
379 extern int rresvport __P ((int *__alport));
380 #endif
383 /* Extension from POSIX.1g. */
384 #ifdef __USE_POSIX
385 /* Structure to contain information about address of a service provider. */
386 struct addrinfo
388 int ai_flags; /* Input flags. */
389 int ai_family; /* Protocol family for socket. */
390 int ai_socktype; /* Socket type. */
391 int ai_protocol; /* Protocol for socket. */
392 int ai_addrlen; /* Length of socket address. */
393 struct sockaddr *ai_addr; /* Socket address for socket. */
394 char *ai_canonname; /* Canonical name for service location. */
395 struct addrinfo *ai_next; /* Pointer to next in list. */
398 /* Possible values for `ai_flags' field in `addrinfo' structure. */
399 # define AI_PASSIVE 1 /* Socket address is intended for `bind'. */
400 # define AI_CANONNAME 2 /* Request for canonical name. */
401 # define AI_NUMERICHOST 3 /* Don't use name resolution. */
403 /* Error values for `getaddrinfo' function. */
404 # define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */
405 # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
406 # define EAI_AGAIN -3 /* Temporary failure in name resolution. */
407 # define EAI_FAIL -4 /* Non-recoverable failure in name res. */
408 # define EAI_NODATA -5 /* No address associated with NAME. */
409 # define EAI_FAMILY -6 /* `ai_family' not supported. */
410 # define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */
411 # define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
412 # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
413 # define EAI_MEMORY -10 /* Memory allocation failure. */
414 # define EAI_SYSTEM -11 /* System error returned in `errno'. */
416 # define NI_MAXHOST 1025
417 # define NI_MAXSERV 32
419 # define NI_NUMERICHOST 1 /* Don't try to look up hostname. */
420 # define NI_NUMERICSERV 2 /* Don't convert port number to name. */
421 # define NI_NOFQDN 4 /* Only return nodename portion. */
422 # define NI_NAMEREQD 8 /* Don't return numeric addresses. */
423 # define NI_DGRAM 16 /* Look up UDP service rather than TCP. */
425 /* Translate name of a service location and/or a service name to set of
426 socket addresses. */
427 extern int getaddrinfo __P ((__const char *__restrict __name,
428 __const char *__restrict __service,
429 __const struct addrinfo *__restrict __req,
430 struct addrinfo **__restrict __pai));
432 /* Free `addrinfo' structure AI including associated storage. */
433 extern void freeaddrinfo __P ((struct addrinfo *__ai));
435 /* Convert error return from getaddrinfo() to a string. */
436 extern char *gai_strerror __P ((int __ecode));
438 /* Translate a socket address to a location and service name. */
439 extern int getnameinfo __P ((__const struct sockaddr *__restrict __sa,
440 socklen_t __salen,
441 char *__restrict __host, size_t __hostlen,
442 char *__restrict __serv, size_t __servlen,
443 int __flags));
445 #endif /* POSIX */
447 __END_DECLS
449 #endif /* netdb.h */