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
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 (void) __THROW
__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 (__const
char *__str
) __THROW
;
87 /* Return string associated with error ERR_NUM. */
88 extern __const
char *hstrerror (int __err_num
) __THROW
;
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 (int __stay_open
) __THROW
;
107 /* Close host data base files and clear `stay open' flag. */
108 extern void endhostent (void) __THROW
;
110 /* Get next entry from host data base file. Open data base if
112 extern struct hostent
*gethostent (void) __THROW
;
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
,
119 /* Return entry from host data base for host with NAME. */
120 extern struct hostent
*gethostbyname (__const
char *__name
) __THROW
;
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 (__const
char *__name
, int __af
) __THROW
;
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
;
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
;
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)
144 /* Free structure returned by previous `getipnodebyaddr' or `getipnodebyname'
146 extern void freehostent (struct hostent
*__ptr
) __THROW
;
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
;
161 extern int gethostbyaddr_r (__const
char *__restrict __addr
, size_t __len
,
163 struct hostent
*__restrict __result_buf
,
164 char *__restrict __buf
, size_t __buflen
,
165 struct hostent
**__restrict __result
,
166 int *__restrict __h_errnop
) __THROW
;
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
;
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
;
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. */
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. */
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
;
197 /* Close network data base files and clear `stay open' flag. */
198 extern void endnetent (void) __THROW
;
200 /* Get next entry from network data base file. Open data base if
202 extern struct netent
*getnetent (void) __THROW
;
204 /* Return entry from network data base which address match NET and
206 extern struct netent
*getnetbyaddr (unsigned long int __net
, int __type
)
209 /* Return entry from network data base for network with NAME. */
210 extern struct netent
*getnetbyname (__const
char *__name
) __THROW
;
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
;
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
;
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
;
237 /* Description of data base entry for a single service. */
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. */
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
;
250 /* Close service data base files and clear `stay open' flag. */
251 extern void endservent (void) __THROW
;
253 /* Get next entry from service data base file. Open data base if
255 extern struct servent
*getservent (void) __THROW
;
257 /* Return entry from network data base for network with NAME and
259 extern struct servent
*getservbyname (__const
char *__name
,
260 __const
char *__proto
) __THROW
;
262 /* Return entry from service data base which matches port PORT and
264 extern struct servent
*getservbyport (int __port
, __const
char *__proto
)
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
;
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
;
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
;
288 /* Description of data base entry for a single service. */
291 char *p_name
; /* Official protocol name. */
292 char **p_aliases
; /* Alias list. */
293 int p_proto
; /* Protocol number. */
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
;
300 /* Close protocol data base files and clear `stay open' flag. */
301 extern void endprotoent (void) __THROW
;
303 /* Get next entry from protocol data base file. Open data base if
305 extern struct protoent
*getprotoent (void) __THROW
;
307 /* Return entry from protocol data base for network with NAME. */
308 extern struct protoent
*getprotobyname (__const
char *__name
) __THROW
;
310 /* Return entry from protocol data base which number is PROTO. */
311 extern struct protoent
*getprotobynumber (int __proto
) __THROW
;
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
;
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
;
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
;
333 /* Establish network group NETGROUP for enumeration. */
334 extern int setnetgrent (__const
char *__netgroup
) __THROW
;
336 /* Free all space allocated by previous `setnetgrent' call. */
337 extern void endnetgrent (void) __THROW
;
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
;
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
;
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
;
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
)
371 /* Call `rexecd' at port RPORT on remote machine *AHOST to execute
372 CMD. The process runs at the remote machine using the ID of user
373 NAME whose cleartext password is PASSWD. In *FD2P the descriptor
374 to the socket for the connection is returned. When the function
375 returns *AHOST contains the official host name. */
376 extern int rexec (char **__restrict __ahost
, int __rport
,
377 __const
char *__restrict __name
,
378 __const
char *__restrict __pass
,
379 __const
char *__restrict __cmd
, int *__restrict __fd2p
)
382 /* Check whether user REMUSER on system RHOST is allowed to login as LOCUSER.
383 If SUSER is not zero the user tries to become superuser. Return 0 if
385 extern int ruserok (__const
char *__rhost
, int __suser
,
386 __const
char *__remuser
, __const
char *__locuser
) __THROW
;
388 /* Try to allocate reserved port, returning a descriptor for a socket opened
389 at this port or -1 if unsuccessful. The search for an available port
390 will start at ALPORT and continues with lower numbers. */
391 extern int rresvport (int *__alport
) __THROW
;
395 /* Extension from POSIX.1g. */
397 /* Structure to contain information about address of a service provider. */
400 int ai_flags
; /* Input flags. */
401 int ai_family
; /* Protocol family for socket. */
402 int ai_socktype
; /* Socket type. */
403 int ai_protocol
; /* Protocol for socket. */
404 int ai_addrlen
; /* Length of socket address. */
405 struct sockaddr
*ai_addr
; /* Socket address for socket. */
406 char *ai_canonname
; /* Canonical name for service location. */
407 struct addrinfo
*ai_next
; /* Pointer to next in list. */
410 /* Possible values for `ai_flags' field in `addrinfo' structure. */
411 # define AI_PASSIVE 1 /* Socket address is intended for `bind'. */
412 # define AI_CANONNAME 2 /* Request for canonical name. */
413 # define AI_NUMERICHOST 4 /* Don't use name resolution. */
415 /* Error values for `getaddrinfo' function. */
416 # define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */
417 # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
418 # define EAI_AGAIN -3 /* Temporary failure in name resolution. */
419 # define EAI_FAIL -4 /* Non-recoverable failure in name res. */
420 # define EAI_NODATA -5 /* No address associated with NAME. */
421 # define EAI_FAMILY -6 /* `ai_family' not supported. */
422 # define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */
423 # define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
424 # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
425 # define EAI_MEMORY -10 /* Memory allocation failure. */
426 # define EAI_SYSTEM -11 /* System error returned in `errno'. */
428 # define NI_MAXHOST 1025
429 # define NI_MAXSERV 32
431 # define NI_NUMERICHOST 1 /* Don't try to look up hostname. */
432 # define NI_NUMERICSERV 2 /* Don't convert port number to name. */
433 # define NI_NOFQDN 4 /* Only return nodename portion. */
434 # define NI_NAMEREQD 8 /* Don't return numeric addresses. */
435 # define NI_DGRAM 16 /* Look up UDP service rather than TCP. */
437 /* Translate name of a service location and/or a service name to set of
439 extern int getaddrinfo (__const
char *__restrict __name
,
440 __const
char *__restrict __service
,
441 __const
struct addrinfo
*__restrict __req
,
442 struct addrinfo
**__restrict __pai
) __THROW
;
444 /* Free `addrinfo' structure AI including associated storage. */
445 extern void freeaddrinfo (struct addrinfo
*__ai
) __THROW
;
447 /* Convert error return from getaddrinfo() to a string. */
448 extern char *gai_strerror (int __ecode
) __THROW
;
450 /* Translate a socket address to a location and service name. */
451 extern int getnameinfo (__const
struct sockaddr
*__restrict __sa
,
452 socklen_t __salen
, char *__restrict __host
,
453 size_t __hostlen
, char *__restrict __serv
,
454 size_t __servlen
, int __flags
) __THROW
;