]>
sourceware.org Git - glibc.git/blob - resolv/netdb.h
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
28 /* This is necessary to make this include file properly replace the
30 #include <rpc/netdb.h>
31 #include <sys/socket.h> /* need socklen_t */
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"
46 /* Error status for non-reentrant lookup functions. */
49 /* Function to get address of global `h_errno' variable. */
50 extern int *__h_errno_location
__P ((void)) __attribute__ ((__const__
));
53 # ifdef _LIBC_REENTRANT
55 __set_h_errno (int __err
)
57 return *__h_errno_location () = __err
;
60 # define __set_h_errno(x) (h_errno = (x))
61 # endif /* _LIBC_REENTRANT */
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 ())
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,
77 #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED,
79 #define NO_DATA 4 /* Valid name, no data record of requested
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. */
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
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
,
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'
125 extern struct hostent
*gethostbyname2
__P ((__const
char *__name
, int __af
));
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
));
137 extern 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
));
142 extern 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
));
148 extern int gethostbyaddr_r
__P ((__const
char *__restrict __addr
, int __len
,
150 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 __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
));
160 extern 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
));
166 extern 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
));
171 extern 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
));
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. */
182 extern struct hostent
*getnodebyname
__P ((__const
char *__name
, int __af
,
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)
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. */
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. */
203 /* Open network data base files and mark them as staying open even
204 after a later search if STAY_OPEN is non-zero. */
205 extern void setnetent
__P ((int __stay_open
));
207 /* Close network data base files and clear `stay open' flag. */
208 extern void endnetent
__P ((void));
210 /* Get next entry from network data base file. Open data base if
212 extern struct netent
*getnetent
__P ((void));
214 /* Return entry from network data base which address match NET and
216 extern struct netent
*getnetbyaddr
__P ((unsigned long int __net
,
219 /* Return entry from network data base for network with NAME. */
220 extern struct netent
*getnetbyname
__P ((__const
char *__name
));
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. */
228 extern 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
));
232 extern 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
));
237 extern int __getnetbyaddr_r
__P ((unsigned long int __net
, int __type
,
238 struct netent
*__restrict __result_buf
,
239 char *__restrict __buf
, size_t __buflen
,
240 struct netent
**__restrict __result
,
241 int *__restrict __h_errnop
));
242 extern int getnetbyaddr_r
__P ((unsigned long int __net
, int __type
,
243 struct netent
*__restrict __result_buf
,
244 char *__restrict __buf
, size_t __buflen
,
245 struct netent
**__restrict __result
,
246 int *__restrict __h_errnop
));
248 extern 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
));
253 extern 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
));
261 /* Description of data base entry for a single service. */
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. */
270 /* Open service data base files and mark them as staying open even
271 after a later search if STAY_OPEN is non-zero. */
272 extern void setservent
__P ((int __stay_open
));
274 /* Close service data base files and clear `stay open' flag. */
275 extern void endservent
__P ((void));
277 /* Get next entry from service data base file. Open data base if
279 extern struct servent
*getservent
__P ((void));
281 /* Return entry from network data base for network with NAME and
283 extern struct servent
*getservbyname
__P ((__const
char *__name
,
284 __const
char *__proto
));
286 /* Return entry from service data base which matches port PORT and
288 extern struct servent
*getservbyport
__P ((int __port
, __const
char *__proto
));
292 /* Reentrant versions of the functions above. The additional
293 arguments specify a buffer of BUFLEN starting at BUF. */
294 extern int __getservent_r
__P ((struct servent
*__restrict __result_buf
,
295 char *__restrict __buf
, size_t __buflen
,
296 struct servent
**__restrict __result
));
297 extern int getservent_r
__P ((struct servent
*__restrict __result_buf
,
298 char *__restrict __buf
, size_t __buflen
,
299 struct servent
**__restrict __result
));
301 extern 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
));
306 extern 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
));
312 extern 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
));
317 extern 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
));
324 /* Description of data base entry for a single service. */
327 char *p_name
; /* Official protocol name. */
328 char **p_aliases
; /* Alias list. */
329 int p_proto
; /* Protocol number. */
332 /* Open protocol data base files and mark them as staying open even
333 after a later search if STAY_OPEN is non-zero. */
334 extern void setprotoent
__P ((int __stay_open
));
336 /* Close protocol data base files and clear `stay open' flag. */
337 extern void endprotoent
__P ((void));
339 /* Get next entry from protocol data base file. Open data base if
341 extern struct protoent
*getprotoent
__P ((void));
343 /* Return entry from protocol data base for network with NAME. */
344 extern struct protoent
*getprotobyname
__P ((__const
char *__name
));
346 /* Return entry from protocol data base which number is PROTO. */
347 extern struct protoent
*getprotobynumber
__P ((int __proto
));
351 /* Reentrant versions of the functions above. The additional
352 arguments specify a buffer of BUFLEN starting at BUF. */
353 extern int __getprotoent_r
__P ((struct protoent
*__restrict __result_buf
,
354 char *__restrict __buf
, size_t __buflen
,
355 struct protoent
**__restrict __result
));
356 extern int getprotoent_r
__P ((struct protoent
*__restrict __result_buf
,
357 char *__restrict __buf
, size_t __buflen
,
358 struct protoent
**__restrict __result
));
360 extern 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
));
364 extern 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
));
369 extern int __getprotobynumber_r
__P ((int __proto
,
370 struct protoent
*__restrict __res_buf
,
371 char *__restrict __buf
, size_t __buflen
,
372 struct protoent
**__restrict __result
));
373 extern int getprotobynumber_r
__P ((int __proto
,
374 struct protoent
*__restrict __result_buf
,
375 char *__restrict __buf
, size_t __buflen
,
376 struct protoent
**__restrict __result
));
380 /* Establish network group NETGROUP for enumeration. */
381 extern int setnetgrent
__P ((__const
char *__netgroup
));
383 /* Free all space allocated by previous `setnetgrent' call. */
384 extern void endnetgrent
__P ((void));
386 /* Get next member of netgroup established by last `setnetgrent' call
387 and return pointers to elements in HOSTP, USERP, and DOMAINP. */
388 extern int getnetgrent
__P ((char **__restrict __hostp
,
389 char **__restrict __userp
,
390 char **__restrict __domainp
));
392 /* Test whether NETGROUP contains the triple (HOST,USER,DOMAIN). */
393 extern int innetgr
__P ((__const
char *__netgroup
, __const
char *__host
,
394 __const
char *__user
, __const
char *domain
));
397 /* Reentrant version of `getnetgrent' where result is placed in BUFFER. */
398 extern int __getnetgrent_r
__P ((char **__restrict __hostp
,
399 char **__restrict __userp
,
400 char **__restrict __domainp
,
401 char *__restrict __buffer
, size_t __buflen
));
402 extern int getnetgrent_r
__P ((char **__restrict __hostp
,
403 char **__restrict __userp
,
404 char **__restrict __domainp
,
405 char *__restrict __buffer
, size_t __buflen
));
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. */
416 extern 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
));
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. */
426 extern 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
));
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
435 extern int ruserok
__P ((__const
char *__rhost
, int __suser
,
436 __const
char *__remuser
, __const
char *__locuser
));
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. */
441 extern int rresvport
__P ((int *__alport
));
445 /* Extension from POSIX.1g. */
447 /* Structure to contain information about address of a service provider. */
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. */
460 /* Possible values for `ai_flags' field in `addrinfo' structure. */
461 # define AI_PASSIVE 1 /* Socket address is intended for `bind'. */
462 # define AI_CANONNAME 2 /* Request for canonical name. */
463 # define AI_NUMERICHOST 3 /* Don't use name resolution. */
465 /* Error values for `getaddrinfo' function. */
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'. */
478 # define NI_MAXHOST 1025
479 # define NI_MAXSERV 32
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. */
487 /* Translate name of a service location and/or a service name to set of
489 extern int getaddrinfo
__P ((__const
char *__restrict __name
,
490 __const
char *__restrict __service
,
491 __const
struct addrinfo
*__restrict __req
,
492 struct addrinfo
**__restrict __pai
));
494 /* Free `addrinfo' structure AI including associated storage. */
495 extern void freeaddrinfo
__P ((struct addrinfo
*__ai
));
497 /* Convert error return from getaddrinfo() to a string. */
498 extern char *gai_strerror
__P ((int __ecode
));
500 /* Translate a socket address to a location and service name. */
501 extern int getnameinfo
__P ((__const
struct sockaddr
*__restrict __sa
,
503 char *__restrict __host
, size_t __hostlen
,
504 char *__restrict __serv
, size_t __servlen
,
This page took 0.069072 seconds and 6 git commands to generate.