Update.
[glibc.git] / resolv / netdb.h
blobfdfc056750acbfb83e8c20df4b3f22ab67248d5c
1 /* Copyright (C) 1996, 1997 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 #define __need_size_t
32 #include <stddef.h>
34 /* Absolute file name for network data base files. */
35 #define _PATH_HEQUIV "/etc/hosts.equiv"
36 #define _PATH_HOSTS "/etc/hosts"
37 #define _PATH_NETWORKS "/etc/networks"
38 #define _PATH_NSSWITCH_CONF "/etc/nsswitch.conf"
39 #define _PATH_PROTOCOLS "/etc/protocols"
40 #define _PATH_SERVICES "/etc/services"
43 __BEGIN_DECLS
45 /* Error status for non-reentrant lookup functions. */
46 extern int h_errno;
48 /* Function to get address of global `h_errno' variable. */
49 extern int *__h_errno_location __P ((void)) __attribute__ ((__const__));
51 #ifdef _LIBC
52 /* Retain some binary compatibility with old libraries by having both the
53 global variable and the per-thread variable set on error. */
54 # ifdef _LIBC_REENTRANT
55 static inline int
56 __set_h_errno (int __err)
58 return *__h_errno_location () = h_errno = __err;
60 # else
61 # define __set_h_errno(x) (h_errno = (x))
62 # endif /* _LIBC_REENTRANT */
63 #endif /* _LIBC */
66 #if !defined _LIBC || defined _LIBC_REENTRANT
67 /* Use a macro to access always the thread specific `h_errno' variable. */
68 # define h_errno (*__h_errno_location ())
69 #endif
72 /* Possible values left in `h_errno'. */
73 #define NETDB_INTERNAL -1 /* See errno. */
74 #define NETDB_SUCCESS 0 /* No problem. */
75 #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found. */
76 #define TRY_AGAIN 2 /* Non-Authoritative Host not found,
77 or SERVERFAIL. */
78 #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED,
79 NOTIMP. */
80 #define NO_DATA 4 /* Valid name, no data record of requested
81 type. */
82 #define NO_ADDRESS NO_DATA /* No address, look for MX record. */
84 /* Print error indicated by `h_errno' variable on standard error. STR
85 if non-null is printed before the error string. */
86 extern void herror __P ((__const char *__str));
88 /* Return string associated with error ERR_NUM. */
89 extern __const char *hstrerror __P ((int __err_num));
93 /* Description of data base entry for a single host. */
94 struct hostent
96 char *h_name; /* Official name of host. */
97 char **h_aliases; /* Alias list. */
98 int h_addrtype; /* Host address type. */
99 int h_length; /* Length of address. */
100 char **h_addr_list; /* List of addresses from name server. */
101 #define h_addr h_addr_list[0] /* Address, for backward compatibility. */
104 /* Open host data base files and mark them as staying open even after
105 a later search if STAY_OPEN is non-zero. */
106 extern void sethostent __P ((int __stay_open));
108 /* Close host data base files and clear `stay open' flag. */
109 extern void endhostent __P ((void));
111 /* Get next entry from host data base file. Open data base if
112 necessary. */
113 extern struct hostent *gethostent __P ((void));
115 /* Return entry from host data base which address match ADDR with
116 length LEN and type TYPE. */
117 extern struct hostent *gethostbyaddr __P ((__const char *__addr, int __len,
118 int __type));
120 /* Return entry from host data base for host with NAME. */
121 extern struct hostent *gethostbyname __P ((__const char *__name));
123 /* Return entry from host data base for host with NAME. AF must be
124 set to the address type which as `AF_INET' for IPv4 or `AF_INET6'
125 for IPv6. */
126 extern struct hostent *gethostbyname2 __P ((__const char *__name, int __af));
128 #ifdef __USE_MISC
129 /* Reentrant versions of the functions above. The additional
130 arguments specify a buffer of BUFLEN starting at BUF. The last
131 argument is a pointer to a variable which gets the value which
132 would be stored in the global variable `herrno' by the
133 non-reentrant functions. */
134 extern int __gethostent_r __P ((struct hostent *__result_buf, char *__buf,
135 size_t __buflen, struct hostent **__result,
136 int *__h_errnop));
137 extern int gethostent_r __P ((struct hostent *__result_buf, char *__buf,
138 size_t __buflen, struct hostent **__result,
139 int *__h_errnop));
141 extern int __gethostbyaddr_r __P ((__const char *__addr, int __len, int __type,
142 struct hostent *__result_buf, char *__buf,
143 size_t __buflen, struct hostent **__result,
144 int *__h_errnop));
145 extern int gethostbyaddr_r __P ((__const char *__addr, int __len, int __type,
146 struct hostent *__result_buf, char *__buf,
147 size_t __buflen, struct hostent **__result,
148 int *__h_errnop));
150 extern int __gethostbyname_r __P ((__const char *__name,
151 struct hostent *__result_buf, char *__buf,
152 size_t __buflen, struct hostent **__result,
153 int *__h_errnop));
154 extern int gethostbyname_r __P ((__const char *__name,
155 struct hostent *__result_buf, char *__buf,
156 size_t __buflen, struct hostent **__result,
157 int *__h_errnop));
159 extern int __gethostbyname2_r __P ((__const char *__name, int __af,
160 struct hostent *__result_buf, char *__buf,
161 size_t __buflen, struct hostent **__result,
162 int *__h_errnop));
163 extern int gethostbyname2_r __P ((__const char *__name, int __af,
164 struct hostent *__result_buf, char *__buf,
165 size_t __buflen, struct hostent **__result,
166 int *__h_errnop));
167 #endif /* misc */
170 /* Description of data base entry for a single network. NOTE: here a
171 poor assumption is made. The network number is expected to fit
172 into an unsigned long int variable. */
173 struct netent
175 char *n_name; /* Official name of network. */
176 char **n_aliases; /* Alias list. */
177 int n_addrtype; /* Net address type. */
178 unsigned long int n_net; /* Network number. */
181 /* Open network data base files and mark them as staying open even
182 after a later search if STAY_OPEN is non-zero. */
183 extern void setnetent __P ((int __stay_open));
185 /* Close network data base files and clear `stay open' flag. */
186 extern void endnetent __P ((void));
188 /* Get next entry from network data base file. Open data base if
189 necessary. */
190 extern struct netent *getnetent __P ((void));
192 /* Return entry from network data base which address match NET and
193 type TYPE. */
194 extern struct netent *getnetbyaddr __P ((unsigned long int __net,
195 int __type));
197 /* Return entry from network data base for network with NAME. */
198 extern struct netent *getnetbyname __P ((__const char *__name));
200 #ifdef __USE_MISC
201 /* Reentrant versions of the functions above. The additional
202 arguments specify a buffer of BUFLEN starting at BUF. The last
203 argument is a pointer to a variable which gets the value which
204 would be stored in the global variable `herrno' by the
205 non-reentrant functions. */
206 extern int __getnetent_r __P ((struct netent *__result_buf, char *__buf,
207 size_t __buflen, struct netent **__result,
208 int *__h_errnop));
209 extern int getnetent_r __P ((struct netent *__result_buf, char *__buf,
210 size_t __buflen, struct netent **__result,
211 int *__h_errnop));
213 extern int __getnetbyaddr_r __P ((unsigned long int __net, int __type,
214 struct netent *__result_buf, char *__buf,
215 size_t __buflen, struct netent **__result,
216 int *__h_errnop));
217 extern int getnetbyaddr_r __P ((unsigned long int __net, int __type,
218 struct netent *__result_buf, char *__buf,
219 size_t __buflen, struct netent **__result,
220 int *__h_errnop));
222 extern int __getnetbyname_r __P ((__const char *__name,
223 struct netent *__result_buf, char *__buf,
224 size_t __buflen, struct netent **__result,
225 int *__h_errnop));
226 extern int getnetbyname_r __P ((__const char *__name,
227 struct netent *__result_buf, char *__buf,
228 size_t __buflen, struct netent **__result,
229 int *__h_errnop));
230 #endif /* misc */
233 /* Description of data base entry for a single service. */
234 struct servent
236 char *s_name; /* Official service name. */
237 char **s_aliases; /* Alias list. */
238 int s_port; /* Port number. */
239 char *s_proto; /* Protocol to use. */
242 /* Open service data base files and mark them as staying open even
243 after a later search if STAY_OPEN is non-zero. */
244 extern void setservent __P ((int __stay_open));
246 /* Close service data base files and clear `stay open' flag. */
247 extern void endservent __P ((void));
249 /* Get next entry from service data base file. Open data base if
250 necessary. */
251 extern struct servent *getservent __P ((void));
253 /* Return entry from network data base for network with NAME and
254 protocol PROTO. */
255 extern struct servent *getservbyname __P ((__const char *__name,
256 __const char *__proto));
258 /* Return entry from service data base which matches port PORT and
259 protocol PROTO. */
260 extern struct servent *getservbyport __P ((int __port, __const char *__proto));
263 #ifdef __USE_MISC
264 /* Reentrant versions of the functions above. The additional
265 arguments specify a buffer of BUFLEN starting at BUF. */
266 extern int __getservent_r __P ((struct servent *__result_buf, char *__buf,
267 size_t __buflen, struct servent **__result));
268 extern int getservent_r __P ((struct servent *__result_buf, char *__buf,
269 size_t __buflen, struct servent **__result));
271 extern int __getservbyname_r __P ((__const char *__name, __const char *__proto,
272 struct servent *__result_buf, char *__buf,
273 size_t __buflen,
274 struct servent **__result));
275 extern int getservbyname_r __P ((__const char *__name, __const char *__proto,
276 struct servent *__result_buf, char *__buf,
277 size_t __buflen, struct servent **__result));
279 extern int __getservbyport_r __P ((int __port, __const char *__proto,
280 struct servent *__result_buf, char *__buf,
281 size_t __buflen,
282 struct servent **__result));
283 extern int getservbyport_r __P ((int __port, __const char *__proto,
284 struct servent *__result_buf, char *__buf,
285 size_t __buflen, struct servent **__result));
286 #endif /* misc */
289 /* Description of data base entry for a single service. */
290 struct protoent
292 char *p_name; /* Official protocol name. */
293 char **p_aliases; /* Alias list. */
294 int p_proto; /* Protocol number. */
297 /* Open protocol data base files and mark them as staying open even
298 after a later search if STAY_OPEN is non-zero. */
299 extern void setprotoent __P ((int __stay_open));
301 /* Close protocol data base files and clear `stay open' flag. */
302 extern void endprotoent __P ((void));
304 /* Get next entry from protocol data base file. Open data base if
305 necessary. */
306 extern struct protoent *getprotoent __P ((void));
308 /* Return entry from protocol data base for network with NAME. */
309 extern struct protoent *getprotobyname __P ((__const char *__name));
311 /* Return entry from protocol data base which number is PROTO. */
312 extern struct protoent *getprotobynumber __P ((int __proto));
315 #ifdef __USE_MISC
316 /* Reentrant versions of the functions above. The additional
317 arguments specify a buffer of BUFLEN starting at BUF. */
318 extern int __getprotoent_r __P ((struct protoent *__result_buf, char *__buf,
319 size_t __buflen, struct protoent **__result));
320 extern int getprotoent_r __P ((struct protoent *__result_buf, char *__buf,
321 size_t __buflen, struct protoent **__result));
323 extern int __getprotobyname_r __P ((__const char *__name,
324 struct protoent *__result_buf, char *__buf,
325 size_t __buflen,
326 struct protoent **__result));
327 extern int getprotobyname_r __P ((__const char *__name,
328 struct protoent *__result_buf, char *__buf,
329 size_t __buflen,
330 struct protoent **__result));
332 extern int __getprotobynumber_r __P ((int __proto, struct protoent *__res_buf,
333 char *__buf, size_t __buflen,
334 struct protoent **__result));
335 extern int getprotobynumber_r __P ((int __proto, struct protoent *__result_buf,
336 char *__buf, size_t __buflen,
337 struct protoent **__result));
338 #endif /* misc */
341 /* Establish network group NETGROUP for enumeration. */
342 extern int setnetgrent __P ((__const char *__netgroup));
344 /* Free all space allocated by previous `setnetgrent' call. */
345 extern void endnetgrent __P ((void));
347 /* Get next member of netgroup established by last `setnetgrent' call
348 and return pointers to elements in HOSTP, USERP, and DOMAINP. */
349 extern int getnetgrent __P ((char **__hostp, char **__userp,
350 char **__domainp));
352 /* Test whether NETGROUP contains the triple (HOST,USER,DOMAIN). */
353 extern int innetgr __P ((__const char *__netgroup, __const char *__host,
354 __const char *__user, __const char *domain));
356 #ifdef __USE_MISC
357 /* Reentrant version of `getnetgrent' where result is placed in BUFFER. */
358 extern int __getnetgrent_r __P ((char **__hostp, char **__userp,
359 char **__domainp,
360 char *__buffer, size_t __buflen));
361 extern int getnetgrent_r __P ((char **__hostp, char **__userp,
362 char **__domainp,
363 char *__buffer, size_t __buflen));
364 #endif /* misc */
367 #ifdef __USE_BSD
368 /* Call `rshd' at port RPORT on remote machine *AHOST to execute CMD.
369 The local user is LOCUSER, on the remote machine the command is
370 executed as REMUSER. In *FD2P the descriptor to the socket for the
371 connection is returned. The caller must have the right to use a
372 reserved port. When the function returns *AHOST contains the
373 official host name. */
374 extern int rcmd __P ((char **__ahost, unsigned short int __rport,
375 __const char *__locuser, __const char *__remuser,
376 __const char *__cmd, int *__fd2p));
378 /* Call `rexecd' at port RPORT on remote machine *AHOST to execute
379 CMD. The process runs at the remote machine using the ID of user
380 NAME whose cleartext password is PASSWD. In *FD2P the descriptor
381 to the socket for the connection is returned. When the function
382 returns *AHOST contains the official host name. */
383 extern int rexec __P ((char **__ahost, int __rport, __const char *__name,
384 __const char *__pass, __const char *__cmd,
385 int *__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. */
419 /* Error values for `getaddrinfo' function. */
420 # define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */
421 # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
422 # define EAI_AGAIN -3 /* Temporary failure in name resolution. */
423 # define EAI_FAIL -4 /* Non-recoverable failure in name res. */
424 # define EAI_NODATA -5 /* No address associated with NAME. */
425 # define EAI_FAMILY -6 /* `ai_family' not supported. */
426 # define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */
427 # define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
428 # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
429 # define EAI_MEMORY -10 /* Memory allocation failure. */
430 # define EAI_SYSTEM -11 /* System error returned in `errno'. */
432 # define NI_MAXHOST 1025
433 # define NI_MAXSERV 32
435 # define NI_NUMERICHOST 1
436 # define NI_NUMERICSERV 2
437 # define NI_NOFQDN 4
438 # define NI_NAMEREQD 8
439 # define NI_DGRAM 16
441 /* Translate name of a service location and/or a service name to set of
442 socket addresses. */
443 extern int getaddrinfo __P ((__const char *__name, __const char *__service,
444 __const struct addrinfo *__req,
445 struct addrinfo **__pai));
447 /* Free `addrinfo' structure AI including associated storage. */
448 extern void freeaddrinfo __P ((struct addrinfo *__ai));
450 /* Convert error return from getaddrinfo() to a string. */
451 extern char *gai_strerror __P ((int __ecode));
453 /* Translate a socket address to a location and service name. */
454 extern int getnameinfo __P ((__const struct sockaddr *__sa, size_t __salen,
455 char *__host, size_t __hostlen,
456 char *__serv, size_t __servlen,
457 int __flags));
459 #endif /* POSIX */
461 __END_DECLS
463 #endif /* netdb.h */