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