Regenerated: autoconf configure.in
[glibc/pb-stable.git] / resolv / netdb.h
blobfe04471afb2b4bc5f2b5783671f48ebcb1782332
1 /* Copyright (C) 1996, 1997, 1998, 1999 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, size_t __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_UNIX98
128 /* Return entry from host data base which address match ADDR with
129 length LEN and type TYPE in newly allocated buffer. */
130 extern struct hostent *getipnodebyaddr __P ((__const char *__addr,
131 size_t __len, int __type,
132 int *__error_num));
134 /* Return entry from host data base for host with NAME and newly allocated
135 buffer. */
136 extern struct hostent *getipnodebyname __P ((__const char *__name, int __type,
137 int __flags, int *__error_num));
139 /* Free structure returned by previous `getipnodebyaddr' or `getipnodebyname'
140 call. */
141 extern void freehostent __P ((struct hostent *__ptr));
142 #endif
144 #ifdef __USE_MISC
145 /* Reentrant versions of the functions above. The additional
146 arguments specify a buffer of BUFLEN starting at BUF. The last
147 argument is a pointer to a variable which gets the value which
148 would be stored in the global variable `herrno' by the
149 non-reentrant functions. */
150 extern int gethostent_r __P ((struct hostent *__restrict __result_buf,
151 char *__restrict __buf, size_t __buflen,
152 struct hostent **__restrict __result,
153 int *__restrict __h_errnop));
155 extern int gethostbyaddr_r __P ((__const char *__restrict __addr, size_t __len,
156 int __type,
157 struct hostent *__restrict __result_buf,
158 char *__restrict __buf, size_t __buflen,
159 struct hostent **__restrict __result,
160 int *__restrict __h_errnop));
162 extern int gethostbyname_r __P ((__const char *__restrict __name,
163 struct hostent *__restrict __result_buf,
164 char *__restrict __buf, size_t __buflen,
165 struct hostent **__restrict __result,
166 int *__restrict __h_errnop));
168 extern int gethostbyname2_r __P ((__const char *__restrict __name, int __af,
169 struct hostent *__restrict __result_buf,
170 char *__restrict __buf, size_t __buflen,
171 struct hostent **__restrict __result,
172 int *__restrict __h_errnop));
173 #endif /* misc */
176 /* Return entry from host data base for host with NAME. AF must be
177 set to the desired address type (either `AF_INET' or `AF_INET6').
178 FLAGS is some combination of the following AI_* values. */
179 extern struct hostent *getnodebyname __P ((__const char *__name, int __af,
180 int __flags));
182 #define AI_V4MAPPED 1 /* IPv4-mapped addresses are acceptable. */
183 #define AI_ALL 2 /* Return both IPv4 and IPv6 addresses. */
184 #define AI_ADDRCONFIG 4 /* Use configuration of this host to choose
185 returned address type. */
186 #define AI_DEFAULT (AI_V4MAPPED | AI_ADDRCONFIG)
189 /* Description of data base entry for a single network. NOTE: here a
190 poor assumption is made. The network number is expected to fit
191 into an unsigned long int variable. */
192 struct netent
194 char *n_name; /* Official name of network. */
195 char **n_aliases; /* Alias list. */
196 int n_addrtype; /* Net address type. */
197 unsigned long int n_net; /* Network number. */
200 /* Open network data base files and mark them as staying open even
201 after a later search if STAY_OPEN is non-zero. */
202 extern void setnetent __P ((int __stay_open));
204 /* Close network data base files and clear `stay open' flag. */
205 extern void endnetent __P ((void));
207 /* Get next entry from network data base file. Open data base if
208 necessary. */
209 extern struct netent *getnetent __P ((void));
211 /* Return entry from network data base which address match NET and
212 type TYPE. */
213 extern struct netent *getnetbyaddr __P ((unsigned long int __net,
214 int __type));
216 /* Return entry from network data base for network with NAME. */
217 extern struct netent *getnetbyname __P ((__const char *__name));
219 #ifdef __USE_MISC
220 /* Reentrant versions of the functions above. The additional
221 arguments specify a buffer of BUFLEN starting at BUF. The last
222 argument is a pointer to a variable which gets the value which
223 would be stored in the global variable `herrno' by the
224 non-reentrant functions. */
225 extern int getnetent_r __P ((struct netent *__restrict __result_buf,
226 char *__restrict __buf, size_t __buflen,
227 struct netent **__restrict __result,
228 int *__restrict __h_errnop));
230 extern int getnetbyaddr_r __P ((unsigned long int __net, int __type,
231 struct netent *__restrict __result_buf,
232 char *__restrict __buf, size_t __buflen,
233 struct netent **__restrict __result,
234 int *__restrict __h_errnop));
236 extern int getnetbyname_r __P ((__const char *__restrict __name,
237 struct netent *__restrict __result_buf,
238 char *__restrict __buf, size_t __buflen,
239 struct netent **__restrict __result,
240 int *__restrict __h_errnop));
241 #endif /* misc */
244 /* Description of data base entry for a single service. */
245 struct servent
247 char *s_name; /* Official service name. */
248 char **s_aliases; /* Alias list. */
249 int s_port; /* Port number. */
250 char *s_proto; /* Protocol to use. */
253 /* Open service data base files and mark them as staying open even
254 after a later search if STAY_OPEN is non-zero. */
255 extern void setservent __P ((int __stay_open));
257 /* Close service data base files and clear `stay open' flag. */
258 extern void endservent __P ((void));
260 /* Get next entry from service data base file. Open data base if
261 necessary. */
262 extern struct servent *getservent __P ((void));
264 /* Return entry from network data base for network with NAME and
265 protocol PROTO. */
266 extern struct servent *getservbyname __P ((__const char *__name,
267 __const char *__proto));
269 /* Return entry from service data base which matches port PORT and
270 protocol PROTO. */
271 extern struct servent *getservbyport __P ((int __port, __const char *__proto));
274 #ifdef __USE_MISC
275 /* Reentrant versions of the functions above. The additional
276 arguments specify a buffer of BUFLEN starting at BUF. */
277 extern int getservent_r __P ((struct servent *__restrict __result_buf,
278 char *__restrict __buf, size_t __buflen,
279 struct servent **__restrict __result));
281 extern int getservbyname_r __P ((__const char *__restrict __name,
282 __const char *__restrict __proto,
283 struct servent *__restrict __result_buf,
284 char *__restrict __buf, size_t __buflen,
285 struct servent **__restrict __result));
287 extern int getservbyport_r __P ((int __port, __const char *__restrict __proto,
288 struct servent *__restrict __result_buf,
289 char *__restrict __buf, size_t __buflen,
290 struct servent **__restrict __result));
291 #endif /* misc */
294 /* Description of data base entry for a single service. */
295 struct protoent
297 char *p_name; /* Official protocol name. */
298 char **p_aliases; /* Alias list. */
299 int p_proto; /* Protocol number. */
302 /* Open protocol data base files and mark them as staying open even
303 after a later search if STAY_OPEN is non-zero. */
304 extern void setprotoent __P ((int __stay_open));
306 /* Close protocol data base files and clear `stay open' flag. */
307 extern void endprotoent __P ((void));
309 /* Get next entry from protocol data base file. Open data base if
310 necessary. */
311 extern struct protoent *getprotoent __P ((void));
313 /* Return entry from protocol data base for network with NAME. */
314 extern struct protoent *getprotobyname __P ((__const char *__name));
316 /* Return entry from protocol data base which number is PROTO. */
317 extern struct protoent *getprotobynumber __P ((int __proto));
320 #ifdef __USE_MISC
321 /* Reentrant versions of the functions above. The additional
322 arguments specify a buffer of BUFLEN starting at BUF. */
323 extern int getprotoent_r __P ((struct protoent *__restrict __result_buf,
324 char *__restrict __buf, size_t __buflen,
325 struct protoent **__restrict __result));
327 extern int getprotobyname_r __P ((__const char *__restrict __name,
328 struct protoent *__restrict __result_buf,
329 char *__restrict __buf, size_t __buflen,
330 struct protoent **__restrict __result));
332 extern int getprotobynumber_r __P ((int __proto,
333 struct protoent *__restrict __result_buf,
334 char *__restrict __buf, size_t __buflen,
335 struct protoent **__restrict __result));
336 #endif /* misc */
339 /* Establish network group NETGROUP for enumeration. */
340 extern int setnetgrent __P ((__const char *__netgroup));
342 /* Free all space allocated by previous `setnetgrent' call. */
343 extern void endnetgrent __P ((void));
345 /* Get next member of netgroup established by last `setnetgrent' call
346 and return pointers to elements in HOSTP, USERP, and DOMAINP. */
347 extern int getnetgrent __P ((char **__restrict __hostp,
348 char **__restrict __userp,
349 char **__restrict __domainp));
351 /* Test whether NETGROUP contains the triple (HOST,USER,DOMAIN). */
352 extern int innetgr __P ((__const char *__netgroup, __const char *__host,
353 __const char *__user, __const char *domain));
355 #ifdef __USE_MISC
356 /* Reentrant version of `getnetgrent' where result is placed in BUFFER. */
357 extern int getnetgrent_r __P ((char **__restrict __hostp,
358 char **__restrict __userp,
359 char **__restrict __domainp,
360 char *__restrict __buffer, size_t __buflen));
361 #endif /* misc */
364 #ifdef __USE_BSD
365 /* Call `rshd' at port RPORT on remote machine *AHOST to execute CMD.
366 The local user is LOCUSER, on the remote machine the command is
367 executed as REMUSER. In *FD2P the descriptor to the socket for the
368 connection is returned. The caller must have the right to use a
369 reserved port. When the function returns *AHOST contains the
370 official host name. */
371 extern int rcmd __P ((char **__restrict __ahost, unsigned short int __rport,
372 __const char *__restrict __locuser,
373 __const char *__restrict __remuser,
374 __const char *__restrict __cmd, int *__restrict __fd2p));
376 /* Call `rexecd' at port RPORT on remote machine *AHOST to execute
377 CMD. The process runs at the remote machine using the ID of user
378 NAME whose cleartext password is PASSWD. In *FD2P the descriptor
379 to the socket for the connection is returned. When the function
380 returns *AHOST contains the official host name. */
381 extern int rexec __P ((char **__restrict __ahost, int __rport,
382 __const char *__restrict __name,
383 __const char *__restrict __pass,
384 __const char *__restrict __cmd,
385 int *__restrict __fd2p));
387 /* Check whether user REMUSER on system RHOST is allowed to login as LOCUSER.
388 If SUSER is not zero the user tries to become superuser. Return 0 if
389 it is possible. */
390 extern int ruserok __P ((__const char *__rhost, int __suser,
391 __const char *__remuser, __const char *__locuser));
393 /* Try to allocate reserved port, returning a descriptor for a socket opened
394 at this port or -1 if unsuccessful. The search for an available port
395 will start at ALPORT and continues with lower numbers. */
396 extern int rresvport __P ((int *__alport));
397 #endif
400 /* Extension from POSIX.1g. */
401 #ifdef __USE_POSIX
402 /* Structure to contain information about address of a service provider. */
403 struct addrinfo
405 int ai_flags; /* Input flags. */
406 int ai_family; /* Protocol family for socket. */
407 int ai_socktype; /* Socket type. */
408 int ai_protocol; /* Protocol for socket. */
409 int ai_addrlen; /* Length of socket address. */
410 struct sockaddr *ai_addr; /* Socket address for socket. */
411 char *ai_canonname; /* Canonical name for service location. */
412 struct addrinfo *ai_next; /* Pointer to next in list. */
415 /* Possible values for `ai_flags' field in `addrinfo' structure. */
416 # define AI_PASSIVE 1 /* Socket address is intended for `bind'. */
417 # define AI_CANONNAME 2 /* Request for canonical name. */
418 # define AI_NUMERICHOST 4 /* Don't use name resolution. */
420 /* Error values for `getaddrinfo' function. */
421 # define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */
422 # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
423 # define EAI_AGAIN -3 /* Temporary failure in name resolution. */
424 # define EAI_FAIL -4 /* Non-recoverable failure in name res. */
425 # define EAI_NODATA -5 /* No address associated with NAME. */
426 # define EAI_FAMILY -6 /* `ai_family' not supported. */
427 # define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */
428 # define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
429 # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
430 # define EAI_MEMORY -10 /* Memory allocation failure. */
431 # define EAI_SYSTEM -11 /* System error returned in `errno'. */
433 # define NI_MAXHOST 1025
434 # define NI_MAXSERV 32
436 # define NI_NUMERICHOST 1 /* Don't try to look up hostname. */
437 # define NI_NUMERICSERV 2 /* Don't convert port number to name. */
438 # define NI_NOFQDN 4 /* Only return nodename portion. */
439 # define NI_NAMEREQD 8 /* Don't return numeric addresses. */
440 # define NI_DGRAM 16 /* Look up UDP service rather than TCP. */
442 /* Translate name of a service location and/or a service name to set of
443 socket addresses. */
444 extern int getaddrinfo __P ((__const char *__restrict __name,
445 __const char *__restrict __service,
446 __const struct addrinfo *__restrict __req,
447 struct addrinfo **__restrict __pai));
449 /* Free `addrinfo' structure AI including associated storage. */
450 extern void freeaddrinfo __P ((struct addrinfo *__ai));
452 /* Convert error return from getaddrinfo() to a string. */
453 extern char *gai_strerror __P ((int __ecode));
455 /* Translate a socket address to a location and service name. */
456 extern int getnameinfo __P ((__const struct sockaddr *__restrict __sa,
457 socklen_t __salen,
458 char *__restrict __host, size_t __hostlen,
459 char *__restrict __serv, size_t __servlen,
460 int __flags));
462 #endif /* POSIX */
464 __END_DECLS
466 #endif /* netdb.h */