]> git.ipfire.org Git - thirdparty/glibc.git/blame - resolv/netdb.h
Update.
[thirdparty/glibc.git] / resolv / netdb.h
CommitLineData
4317f9e1 1/* Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
23396375 2 This file is part of the GNU C Library.
3d61b63c 3
23396375
UD
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.
8
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.
13
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. */
18
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). */
22
23#ifndef _NETDB_H
23396375 24#define _NETDB_H 1
5107cf1d 25
23396375
UD
26#include <features.h>
27
28/* This is necessary to make this include file properly replace the
29 Sun version. */
30#include <rpc/netdb.h>
4bca4c17 31#include <sys/socket.h> /* need socklen_t */
ba1ffaa1
UD
32#define __need_size_t
33#include <stddef.h>
23396375
UD
34
35/* Absolute file name for network data base files. */
5f0e6fc7
RM
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"
28f540f4 42
23396375
UD
43
44__BEGIN_DECLS
45
46/* Error status for non-reentrant lookup functions. */
3d61b63c
RM
47extern int h_errno;
48
ba1ffaa1 49/* Function to get address of global `h_errno' variable. */
edf5b2d7
UD
50extern int *__h_errno_location __P ((void)) __attribute__ ((__const__));
51
ba1ffaa1 52#ifdef _LIBC
ba1ffaa1
UD
53# ifdef _LIBC_REENTRANT
54static inline int
55__set_h_errno (int __err)
56{
4317f9e1 57 return *__h_errno_location () = __err;
ba1ffaa1
UD
58}
59# else
60# define __set_h_errno(x) (h_errno = (x))
61# endif /* _LIBC_REENTRANT */
62#endif /* _LIBC */
63
64
19361cb7 65#if !defined _LIBC || defined _LIBC_REENTRANT
ba1ffaa1
UD
66/* Use a macro to access always the thread specific `h_errno' variable. */
67# define h_errno (*__h_errno_location ())
edf5b2d7
UD
68#endif
69
ba1ffaa1 70
23396375
UD
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. */
6d52618b 75#define TRY_AGAIN 2 /* Non-Authoritative Host not found,
23396375
UD
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. */
82
83/* Print error indicated by `h_errno' variable on standard error. STR
84 if non-null is printed before the error string. */
85extern void herror __P ((__const char *__str));
86
87/* Return string associated with error ERR_NUM. */
88extern __const char *hstrerror __P ((int __err_num));
89
28f540f4 90
23396375
UD
91
92/* Description of data base entry for a single host. */
93struct hostent
94{
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. */
6d52618b 100#define h_addr h_addr_list[0] /* Address, for backward compatibility. */
28f540f4
RM
101};
102
23396375
UD
103/* Open host data base files and mark them as staying open even after
104 a later search if STAY_OPEN is non-zero. */
105extern void sethostent __P ((int __stay_open));
106
107/* Close host data base files and clear `stay open' flag. */
108extern void endhostent __P ((void));
109
110/* Get next entry from host data base file. Open data base if
111 necessary. */
112extern struct hostent *gethostent __P ((void));
113
114/* Return entry from host data base which address match ADDR with
115 length LEN and type TYPE. */
116extern struct hostent *gethostbyaddr __P ((__const char *__addr, int __len,
117 int __type));
118
119/* Return entry from host data base for host with NAME. */
120extern struct hostent *gethostbyname __P ((__const char *__name));
121
122/* Return entry from host data base for host with NAME. AF must be
4bca4c17 123 set to the address type which is `AF_INET' for IPv4 or `AF_INET6'
23396375
UD
124 for IPv6. */
125extern struct hostent *gethostbyname2 __P ((__const char *__name, int __af));
126
19361cb7 127#ifdef __USE_MISC
23396375
UD
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. */
a6ff34d7
UD
133extern 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));
137extern int gethostent_r __P ((struct hostent *__restrict __result_buf,
138 char *__restrict __buf, size_t __buflen,
139 struct hostent **__restrict __result,
140 int *__restrict __h_errnop));
141
142extern int __gethostbyaddr_r __P ((__const char *__restrict __addr,
143 int __len, int __type,
144 struct hostent *__restrict __result_buf,
145 char *__restrict __buf, size_t __buflen,
146 struct hostent **__restrict __result,
147 int *__restrict __h_errnop));
148extern int gethostbyaddr_r __P ((__const char *__restrict __addr, int __len,
149 int __type,
150 struct hostent *__restrict __result_buf,
151 char *__restrict __buf, size_t __buflen,
152 struct hostent **__restrict __result,
153 int *__restrict __h_errnop));
154
155extern int __gethostbyname_r __P ((__const char *__restrict __name,
156 struct hostent *__restrict __result_buf,
157 char *__restrict __buf, size_t __buflen,
158 struct hostent **__restrict __result,
159 int *__restrict __h_errnop));
160extern int gethostbyname_r __P ((__const char *__restrict __name,
161 struct hostent *__restrict __result_buf,
162 char *__restrict __buf, size_t __buflen,
163 struct hostent **__restrict __result,
164 int *__restrict __h_errnop));
165
166extern int __gethostbyname2_r __P ((__const char *__restrict __name, int __af,
167 struct hostent *__restrict __result_buf,
168 char *__restrict __buf, size_t __buflen,
169 struct hostent **__restrict __result,
170 int *__restrict __h_errnop));
171extern int gethostbyname2_r __P ((__const char *__restrict __name, int __af,
172 struct hostent *__restrict __result_buf,
173 char *__restrict __buf, size_t __buflen,
174 struct hostent **__restrict __result,
175 int *__restrict __h_errnop));
19361cb7 176#endif /* misc */
23396375
UD
177
178
4bca4c17
UD
179/* Return entry from host data base for host with NAME. AF must be
180 set to the desired address type (either `AF_INET' or `AF_INET6').
181 FLAGS is some combination of the following AI_* values. */
182extern struct hostent *getnodebyname __P ((__const char *__name, int __af,
183 int __flags));
184
185#define AI_V4MAPPED 1 /* IPv4-mapped addresses are acceptable. */
186#define AI_ALL 2 /* Return both IPv4 and IPv6 addresses. */
187#define AI_ADDRCONFIG 4 /* Use configuration of this host to choose
188 returned address type. */
189#define AI_DEFAULT (AI_V4MAPPED | AI_ADDRCONFIG)
190
191
23396375
UD
192/* Description of data base entry for a single network. NOTE: here a
193 poor assumption is made. The network number is expected to fit
194 into an unsigned long int variable. */
195struct netent
196{
197 char *n_name; /* Official name of network. */
198 char **n_aliases; /* Alias list. */
199 int n_addrtype; /* Net address type. */
200 unsigned long int n_net; /* Network number. */
28f540f4
RM
201};
202
23396375
UD
203/* Open network data base files and mark them as staying open even
204 after a later search if STAY_OPEN is non-zero. */
205extern void setnetent __P ((int __stay_open));
206
207/* Close network data base files and clear `stay open' flag. */
208extern void endnetent __P ((void));
209
210/* Get next entry from network data base file. Open data base if
211 necessary. */
212extern struct netent *getnetent __P ((void));
213
214/* Return entry from network data base which address match NET and
215 type TYPE. */
216extern struct netent *getnetbyaddr __P ((unsigned long int __net,
217 int __type));
218
219/* Return entry from network data base for network with NAME. */
220extern struct netent *getnetbyname __P ((__const char *__name));
221
19361cb7 222#ifdef __USE_MISC
23396375
UD
223/* Reentrant versions of the functions above. The additional
224 arguments specify a buffer of BUFLEN starting at BUF. The last
225 argument is a pointer to a variable which gets the value which
226 would be stored in the global variable `herrno' by the
227 non-reentrant functions. */
a6ff34d7
UD
228extern int __getnetent_r __P ((struct netent *__restrict __result_buf,
229 char *__restrict __buf, size_t __buflen,
230 struct netent **__restrict __result,
231 int *__restrict __h_errnop));
232extern int getnetent_r __P ((struct netent *__restrict __result_buf,
233 char *__restrict __buf, size_t __buflen,
234 struct netent **__restrict __result,
235 int *__restrict __h_errnop));
ba1ffaa1
UD
236
237extern int __getnetbyaddr_r __P ((unsigned long int __net, int __type,
a6ff34d7
UD
238 struct netent *__restrict __result_buf,
239 char *__restrict __buf, size_t __buflen,
240 struct netent **__restrict __result,
241 int *__restrict __h_errnop));
ba1ffaa1 242extern int getnetbyaddr_r __P ((unsigned long int __net, int __type,
a6ff34d7
UD
243 struct netent *__restrict __result_buf,
244 char *__restrict __buf, size_t __buflen,
245 struct netent **__restrict __result,
246 int *__restrict __h_errnop));
247
248extern int __getnetbyname_r __P ((__const char *__restrict __name,
249 struct netent *__restrict __result_buf,
250 char *__restrict __buf, size_t __buflen,
251 struct netent **__restrict __result,
252 int *__restrict __h_errnop));
253extern int getnetbyname_r __P ((__const char *__restrict __name,
254 struct netent *__restrict __result_buf,
255 char *__restrict __buf, size_t __buflen,
256 struct netent **__restrict __result,
257 int *__restrict __h_errnop));
19361cb7 258#endif /* misc */
23396375
UD
259
260
261/* Description of data base entry for a single service. */
262struct servent
263{
264 char *s_name; /* Official service name. */
265 char **s_aliases; /* Alias list. */
266 int s_port; /* Port number. */
267 char *s_proto; /* Protocol to use. */
28f540f4
RM
268};
269
23396375
UD
270/* Open service data base files and mark them as staying open even
271 after a later search if STAY_OPEN is non-zero. */
272extern void setservent __P ((int __stay_open));
28f540f4 273
23396375
UD
274/* Close service data base files and clear `stay open' flag. */
275extern void endservent __P ((void));
28f540f4 276
23396375
UD
277/* Get next entry from service data base file. Open data base if
278 necessary. */
279extern struct servent *getservent __P ((void));
28f540f4 280
23396375
UD
281/* Return entry from network data base for network with NAME and
282 protocol PROTO. */
283extern struct servent *getservbyname __P ((__const char *__name,
284 __const char *__proto));
285
286/* Return entry from service data base which matches port PORT and
287 protocol PROTO. */
288extern struct servent *getservbyport __P ((int __port, __const char *__proto));
289
290
19361cb7 291#ifdef __USE_MISC
23396375
UD
292/* Reentrant versions of the functions above. The additional
293 arguments specify a buffer of BUFLEN starting at BUF. */
a6ff34d7
UD
294extern int __getservent_r __P ((struct servent *__restrict __result_buf,
295 char *__restrict __buf, size_t __buflen,
296 struct servent **__restrict __result));
297extern int getservent_r __P ((struct servent *__restrict __result_buf,
298 char *__restrict __buf, size_t __buflen,
299 struct servent **__restrict __result));
300
301extern int __getservbyname_r __P ((__const char *__restrict __name,
302 __const char *__restrict __proto,
303 struct servent *__restrict __result_buf,
304 char *__restrict __buf, size_t __buflen,
305 struct servent **__restrict __result));
306extern int getservbyname_r __P ((__const char *__restrict __name,
307 __const char *__restrict __proto,
308 struct servent *__restrict __result_buf,
309 char *__restrict __buf, size_t __buflen,
310 struct servent **__restrict __result));
311
312extern int __getservbyport_r __P ((int __port,
313 __const char *__restrict __proto,
314 struct servent *__restrict __result_buf,
315 char *__restrict __buf, size_t __buflen,
316 struct servent **__restrict __result));
317extern int getservbyport_r __P ((int __port, __const char *__restrict __proto,
318 struct servent *__restrict __result_buf,
319 char *__restrict __buf, size_t __buflen,
320 struct servent **__restrict __result));
19361cb7 321#endif /* misc */
23396375
UD
322
323
324/* Description of data base entry for a single service. */
325struct protoent
326{
327 char *p_name; /* Official protocol name. */
328 char **p_aliases; /* Alias list. */
329 int p_proto; /* Protocol number. */
3d61b63c 330};
3d61b63c 331
23396375
UD
332/* Open protocol data base files and mark them as staying open even
333 after a later search if STAY_OPEN is non-zero. */
334extern void setprotoent __P ((int __stay_open));
335
336/* Close protocol data base files and clear `stay open' flag. */
337extern void endprotoent __P ((void));
338
339/* Get next entry from protocol data base file. Open data base if
340 necessary. */
341extern struct protoent *getprotoent __P ((void));
342
343/* Return entry from protocol data base for network with NAME. */
344extern struct protoent *getprotobyname __P ((__const char *__name));
345
346/* Return entry from protocol data base which number is PROTO. */
347extern struct protoent *getprotobynumber __P ((int __proto));
348
349
19361cb7 350#ifdef __USE_MISC
23396375
UD
351/* Reentrant versions of the functions above. The additional
352 arguments specify a buffer of BUFLEN starting at BUF. */
a6ff34d7
UD
353extern int __getprotoent_r __P ((struct protoent *__restrict __result_buf,
354 char *__restrict __buf, size_t __buflen,
355 struct protoent **__restrict __result));
356extern int getprotoent_r __P ((struct protoent *__restrict __result_buf,
357 char *__restrict __buf, size_t __buflen,
358 struct protoent **__restrict __result));
359
360extern int __getprotobyname_r __P ((__const char *__restrict __name,
361 struct protoent *__restrict __result_buf,
362 char *__restrict __buf, size_t __buflen,
363 struct protoent **__restrict __result));
364extern int getprotobyname_r __P ((__const char *__restrict __name,
365 struct protoent *__restrict __result_buf,
366 char *__restrict __buf, size_t __buflen,
367 struct protoent **__restrict __result));
368
369extern int __getprotobynumber_r __P ((int __proto,
370 struct protoent *__restrict __res_buf,
371 char *__restrict __buf, size_t __buflen,
372 struct protoent **__restrict __result));
373extern int getprotobynumber_r __P ((int __proto,
374 struct protoent *__restrict __result_buf,
375 char *__restrict __buf, size_t __buflen,
376 struct protoent **__restrict __result));
19361cb7 377#endif /* misc */
23396375
UD
378
379
a68b0d31
UD
380/* Establish network group NETGROUP for enumeration. */
381extern int setnetgrent __P ((__const char *__netgroup));
382
383/* Free all space allocated by previous `setnetgrent' call. */
384extern void endnetgrent __P ((void));
385
386/* Get next member of netgroup established by last `setnetgrent' call
387 and return pointers to elements in HOSTP, USERP, and DOMAINP. */
a6ff34d7
UD
388extern int getnetgrent __P ((char **__restrict __hostp,
389 char **__restrict __userp,
390 char **__restrict __domainp));
a68b0d31
UD
391
392/* Test whether NETGROUP contains the triple (HOST,USER,DOMAIN). */
393extern int innetgr __P ((__const char *__netgroup, __const char *__host,
394 __const char *__user, __const char *domain));
395
19361cb7 396#ifdef __USE_MISC
a68b0d31 397/* Reentrant version of `getnetgrent' where result is placed in BUFFER. */
a6ff34d7
UD
398extern int __getnetgrent_r __P ((char **__restrict __hostp,
399 char **__restrict __userp,
400 char **__restrict __domainp,
401 char *__restrict __buffer, size_t __buflen));
402extern int getnetgrent_r __P ((char **__restrict __hostp,
403 char **__restrict __userp,
404 char **__restrict __domainp,
405 char *__restrict __buffer, size_t __buflen));
19361cb7 406#endif /* misc */
a68b0d31 407
46ec036d 408
e7fd8a39
UD
409#ifdef __USE_BSD
410/* Call `rshd' at port RPORT on remote machine *AHOST to execute CMD.
411 The local user is LOCUSER, on the remote machine the command is
412 executed as REMUSER. In *FD2P the descriptor to the socket for the
413 connection is returned. The caller must have the right to use a
414 reserved port. When the function returns *AHOST contains the
415 official host name. */
a6ff34d7
UD
416extern int rcmd __P ((char **__restrict __ahost, unsigned short int __rport,
417 __const char *__restrict __locuser,
418 __const char *__restrict __remuser,
419 __const char *__restrict __cmd, int *__restrict __fd2p));
e7fd8a39
UD
420
421/* Call `rexecd' at port RPORT on remote machine *AHOST to execute
422 CMD. The process runs at the remote machine using the ID of user
423 NAME whose cleartext password is PASSWD. In *FD2P the descriptor
424 to the socket for the connection is returned. When the function
425 returns *AHOST contains the official host name. */
a6ff34d7
UD
426extern int rexec __P ((char **__restrict __ahost, int __rport,
427 __const char *__restrict __name,
428 __const char *__restrict __pass,
429 __const char *__restrict __cmd,
430 int *__restrict __fd2p));
e7fd8a39
UD
431
432/* Check whether user REMUSER on system RHOST is allowed to login as LOCUSER.
433 If SUSER is not zero the user tries to become superuser. Return 0 if
434 it is possible. */
435extern int ruserok __P ((__const char *__rhost, int __suser,
436 __const char *__remuser, __const char *__locuser));
437
438/* Try to allocate reserved port, returning a descriptor for a socket opened
439 at this port or -1 if unsuccessful. The search for an available port
440 will start at ALPORT and continues with lower numbers. */
441extern int rresvport __P ((int *__alport));
442#endif
443
444
46ec036d
UD
445/* Extension from POSIX.1g. */
446#ifdef __USE_POSIX
447/* Structure to contain information about address of a service provider. */
448struct addrinfo
449{
450 int ai_flags; /* Input flags. */
451 int ai_family; /* Protocol family for socket. */
452 int ai_socktype; /* Socket type. */
453 int ai_protocol; /* Protocol for socket. */
454 int ai_addrlen; /* Length of socket address. */
455 struct sockaddr *ai_addr; /* Socket address for socket. */
456 char *ai_canonname; /* Canonical name for service location. */
457 struct addrinfo *ai_next; /* Pointer to next in list. */
458};
459
460/* Possible values for `ai_flags' field in `addrinfo' structure. */
dfd2257a
UD
461# define AI_PASSIVE 1 /* Socket address is intended for `bind'. */
462# define AI_CANONNAME 2 /* Request for canonical name. */
4bca4c17 463# define AI_NUMERICHOST 3 /* Don't use name resolution. */
46ec036d
UD
464
465/* Error values for `getaddrinfo' function. */
dfd2257a
UD
466# define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */
467# define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
468# define EAI_AGAIN -3 /* Temporary failure in name resolution. */
469# define EAI_FAIL -4 /* Non-recoverable failure in name res. */
470# define EAI_NODATA -5 /* No address associated with NAME. */
471# define EAI_FAMILY -6 /* `ai_family' not supported. */
472# define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */
473# define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
474# define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
475# define EAI_MEMORY -10 /* Memory allocation failure. */
476# define EAI_SYSTEM -11 /* System error returned in `errno'. */
477
478# define NI_MAXHOST 1025
479# define NI_MAXSERV 32
480
4bca4c17
UD
481# define NI_NUMERICHOST 1 /* Don't try to look up hostname. */
482# define NI_NUMERICSERV 2 /* Don't convert port number to name. */
483# define NI_NOFQDN 4 /* Only return nodename portion. */
484# define NI_NAMEREQD 8 /* Don't return numeric addresses. */
485# define NI_DGRAM 16 /* Look up UDP service rather than TCP. */
46ec036d
UD
486
487/* Translate name of a service location and/or a service name to set of
488 socket addresses. */
a6ff34d7
UD
489extern int getaddrinfo __P ((__const char *__restrict __name,
490 __const char *__restrict __service,
491 __const struct addrinfo *__restrict __req,
492 struct addrinfo **__restrict __pai));
46ec036d
UD
493
494/* Free `addrinfo' structure AI including associated storage. */
495extern void freeaddrinfo __P ((struct addrinfo *__ai));
0d8733c4
UD
496
497/* Convert error return from getaddrinfo() to a string. */
498extern char *gai_strerror __P ((int __ecode));
499
500/* Translate a socket address to a location and service name. */
a6ff34d7
UD
501extern int getnameinfo __P ((__const struct sockaddr *__restrict __sa,
502 socklen_t __salen,
503 char *__restrict __host, size_t __hostlen,
504 char *__restrict __serv, size_t __servlen,
0d8733c4
UD
505 int __flags));
506
46ec036d
UD
507#endif /* POSIX */
508
23396375
UD
509__END_DECLS
510
511#endif /* netdb.h */