1 /* Copyright (C) 1996, 1997, 1998, 1999, 2000 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 #ifndef __uint32_t_defined
36 typedef unsigned int uint32_t;
37 # define __uint32_t_defined
40 #include <bits/netdb.h>
42 /* Absolute file name for network data base files. */
43 #define _PATH_HEQUIV "/etc/hosts.equiv"
44 #define _PATH_HOSTS "/etc/hosts"
45 #define _PATH_NETWORKS "/etc/networks"
46 #define _PATH_NSSWITCH_CONF "/etc/nsswitch.conf"
47 #define _PATH_PROTOCOLS "/etc/protocols"
48 #define _PATH_SERVICES "/etc/services"
53 /* Error status for non-reentrant lookup functions. */
56 /* Function to get address of global `h_errno' variable. */
57 extern int *__h_errno_location (void) __THROW __attribute__ ((__const__));
60 # ifdef _LIBC_REENTRANT
62 __set_h_errno (int __err)
64 return *__h_errno_location () = __err;
67 # define __set_h_errno(x) (h_errno = (x))
68 # endif /* _LIBC_REENTRANT */
72 #if !defined _LIBC || defined _LIBC_REENTRANT
73 /* Use a macro to access always the thread specific `h_errno' variable. */
74 # define h_errno (*__h_errno_location ())
78 /* Possible values left in `h_errno'. */
79 #define NETDB_INTERNAL -1 /* See errno. */
80 #define NETDB_SUCCESS 0 /* No problem. */
81 #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found. */
82 #define TRY_AGAIN 2 /* Non-Authoritative Host not found,
84 #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED,
86 #define NO_DATA 4 /* Valid name, no data record of requested
88 #define NO_ADDRESS NO_DATA /* No address, look for MX record. */
91 /* Scope delimiter for getaddrinfo(), getnameinfo(). */
92 # define SCOPE_DELIMITER '%'
95 /* Print error indicated by `h_errno' variable on standard error. STR
96 if non-null is printed before the error string. */
97 extern void herror (__const char *__str) __THROW;
99 /* Return string associated with error ERR_NUM. */
100 extern __const char *hstrerror (int __err_num) __THROW;
104 /* Description of data base entry for a single host. */
107 char *h_name; /* Official name of host. */
108 char **h_aliases; /* Alias list. */
109 int h_addrtype; /* Host address type. */
110 socklen_t h_length; /* Length of address. */
111 char **h_addr_list; /* List of addresses from name server. */
112 #define h_addr h_addr_list[0] /* Address, for backward compatibility. */
115 /* Open host data base files and mark them as staying open even after
116 a later search if STAY_OPEN is non-zero. */
117 extern void sethostent (int __stay_open) __THROW;
119 /* Close host data base files and clear `stay open' flag. */
120 extern void endhostent (void) __THROW;
122 /* Get next entry from host data base file. Open data base if
124 extern struct hostent *gethostent (void) __THROW;
126 /* Return entry from host data base which address match ADDR with
127 length LEN and type TYPE. */
128 extern struct hostent *gethostbyaddr (__const void *__addr, __socklen_t __len,
131 /* Return entry from host data base for host with NAME. */
132 extern struct hostent *gethostbyname (__const char *__name) __THROW;
135 /* Return entry from host data base for host with NAME. AF must be
136 set to the address type which is `AF_INET' for IPv4 or `AF_INET6'
138 extern struct hostent *gethostbyname2 (__const char *__name, int __af) __THROW;
140 /* Reentrant versions of the functions above. The additional
141 arguments specify a buffer of BUFLEN starting at BUF. The last
142 argument is a pointer to a variable which gets the value which
143 would be stored in the global variable `herrno' by the
144 non-reentrant functions. */
145 extern int gethostent_r (struct hostent *__restrict __result_buf,
146 char *__restrict __buf, size_t __buflen,
147 struct hostent **__restrict __result,
148 int *__restrict __h_errnop) __THROW;
150 extern int gethostbyaddr_r (__const void *__restrict __addr, __socklen_t __len,
152 struct hostent *__restrict __result_buf,
153 char *__restrict __buf, size_t __buflen,
154 struct hostent **__restrict __result,
155 int *__restrict __h_errnop) __THROW;
157 extern int gethostbyname_r (__const char *__restrict __name,
158 struct hostent *__restrict __result_buf,
159 char *__restrict __buf, size_t __buflen,
160 struct hostent **__restrict __result,
161 int *__restrict __h_errnop) __THROW;
163 extern int gethostbyname2_r (__const char *__restrict __name, int __af,
164 struct hostent *__restrict __result_buf,
165 char *__restrict __buf, size_t __buflen,
166 struct hostent **__restrict __result,
167 int *__restrict __h_errnop) __THROW;
171 /* Open network data base files and mark them as staying open even
172 after a later search if STAY_OPEN is non-zero. */
173 extern void setnetent (int __stay_open) __THROW;
175 /* Close network data base files and clear `stay open' flag. */
176 extern void endnetent (void) __THROW;
178 /* Get next entry from network data base file. Open data base if
180 extern struct netent *getnetent (void) __THROW;
182 /* Return entry from network data base which address match NET and
184 extern struct netent *getnetbyaddr (uint32_t __net, int __type)
187 /* Return entry from network data base for network with NAME. */
188 extern struct netent *getnetbyname (__const char *__name) __THROW;
191 /* Reentrant versions of the functions above. The additional
192 arguments specify a buffer of BUFLEN starting at BUF. The last
193 argument is a pointer to a variable which gets the value which
194 would be stored in the global variable `herrno' by the
195 non-reentrant functions. */
196 extern int getnetent_r (struct netent *__restrict __result_buf,
197 char *__restrict __buf, size_t __buflen,
198 struct netent **__restrict __result,
199 int *__restrict __h_errnop) __THROW;
201 extern int getnetbyaddr_r (uint32_t __net, int __type,
202 struct netent *__restrict __result_buf,
203 char *__restrict __buf, size_t __buflen,
204 struct netent **__restrict __result,
205 int *__restrict __h_errnop) __THROW;
207 extern int getnetbyname_r (__const char *__restrict __name,
208 struct netent *__restrict __result_buf,
209 char *__restrict __buf, size_t __buflen,
210 struct netent **__restrict __result,
211 int *__restrict __h_errnop) __THROW;
215 /* Description of data base entry for a single service. */
218 char *s_name; /* Official service name. */
219 char **s_aliases; /* Alias list. */
220 int s_port; /* Port number. */
221 char *s_proto; /* Protocol to use. */
224 /* Open service data base files and mark them as staying open even
225 after a later search if STAY_OPEN is non-zero. */
226 extern void setservent (int __stay_open) __THROW;
228 /* Close service data base files and clear `stay open' flag. */
229 extern void endservent (void) __THROW;
231 /* Get next entry from service data base file. Open data base if
233 extern struct servent *getservent (void) __THROW;
235 /* Return entry from network data base for network with NAME and
237 extern struct servent *getservbyname (__const char *__name,
238 __const char *__proto) __THROW;
240 /* Return entry from service data base which matches port PORT and
242 extern struct servent *getservbyport (int __port, __const char *__proto)
247 /* Reentrant versions of the functions above. The additional
248 arguments specify a buffer of BUFLEN starting at BUF. */
249 extern int getservent_r (struct servent *__restrict __result_buf,
250 char *__restrict __buf, size_t __buflen,
251 struct servent **__restrict __result) __THROW;
253 extern int getservbyname_r (__const char *__restrict __name,
254 __const char *__restrict __proto,
255 struct servent *__restrict __result_buf,
256 char *__restrict __buf, size_t __buflen,
257 struct servent **__restrict __result) __THROW;
259 extern int getservbyport_r (int __port, __const char *__restrict __proto,
260 struct servent *__restrict __result_buf,
261 char *__restrict __buf, size_t __buflen,
262 struct servent **__restrict __result) __THROW;
266 /* Description of data base entry for a single service. */
269 char *p_name; /* Official protocol name. */
270 char **p_aliases; /* Alias list. */
271 int p_proto; /* Protocol number. */
274 /* Open protocol data base files and mark them as staying open even
275 after a later search if STAY_OPEN is non-zero. */
276 extern void setprotoent (int __stay_open) __THROW;
278 /* Close protocol data base files and clear `stay open' flag. */
279 extern void endprotoent (void) __THROW;
281 /* Get next entry from protocol data base file. Open data base if
283 extern struct protoent *getprotoent (void) __THROW;
285 /* Return entry from protocol data base for network with NAME. */
286 extern struct protoent *getprotobyname (__const char *__name) __THROW;
288 /* Return entry from protocol data base which number is PROTO. */
289 extern struct protoent *getprotobynumber (int __proto) __THROW;
293 /* Reentrant versions of the functions above. The additional
294 arguments specify a buffer of BUFLEN starting at BUF. */
295 extern int getprotoent_r (struct protoent *__restrict __result_buf,
296 char *__restrict __buf, size_t __buflen,
297 struct protoent **__restrict __result) __THROW;
299 extern int getprotobyname_r (__const char *__restrict __name,
300 struct protoent *__restrict __result_buf,
301 char *__restrict __buf, size_t __buflen,
302 struct protoent **__restrict __result) __THROW;
304 extern int getprotobynumber_r (int __proto,
305 struct protoent *__restrict __result_buf,
306 char *__restrict __buf, size_t __buflen,
307 struct protoent **__restrict __result) __THROW;
311 /* Establish network group NETGROUP for enumeration. */
312 extern int setnetgrent (__const char *__netgroup) __THROW;
314 /* Free all space allocated by previous `setnetgrent' call. */
315 extern void endnetgrent (void) __THROW;
317 /* Get next member of netgroup established by last `setnetgrent' call
318 and return pointers to elements in HOSTP, USERP, and DOMAINP. */
319 extern int getnetgrent (char **__restrict __hostp,
320 char **__restrict __userp,
321 char **__restrict __domainp) __THROW;
324 /* Test whether NETGROUP contains the triple (HOST,USER,DOMAIN). */
325 extern int innetgr (__const char *__netgroup, __const char *__host,
326 __const char *__user, __const char *domain) __THROW;
328 /* Reentrant version of `getnetgrent' where result is placed in BUFFER. */
329 extern int getnetgrent_r (char **__restrict __hostp,
330 char **__restrict __userp,
331 char **__restrict __domainp,
332 char *__restrict __buffer, size_t __buflen) __THROW;
337 /* Call `rshd' at port RPORT on remote machine *AHOST to execute CMD.
338 The local user is LOCUSER, on the remote machine the command is
339 executed as REMUSER. In *FD2P the descriptor to the socket for the
340 connection is returned. The caller must have the right to use a
341 reserved port. When the function returns *AHOST contains the
342 official host name. */
343 extern int rcmd (char **__restrict __ahost, unsigned short int __rport,
344 __const char *__restrict __locuser,
345 __const char *__restrict __remuser,
346 __const char *__restrict __cmd, int *__restrict __fd2p)
349 /* This is the equivalent function where the protocol can be selected
350 and which therefore can be used for IPv6. */
351 extern int rcmd_af (char **__restrict __ahost, unsigned short int __rport,
352 __const char *__restrict __locuser,
353 __const char *__restrict __remuser,
354 __const char *__restrict __cmd, int *__restrict __fd2p,
355 sa_family_t __af) __THROW;
357 /* Call `rexecd' at port RPORT on remote machine *AHOST to execute
358 CMD. The process runs at the remote machine using the ID of user
359 NAME whose cleartext password is PASSWD. In *FD2P the descriptor
360 to the socket for the connection is returned. When the function
361 returns *AHOST contains the official host name. */
362 extern int rexec (char **__restrict __ahost, int __rport,
363 __const char *__restrict __name,
364 __const char *__restrict __pass,
365 __const char *__restrict __cmd, int *__restrict __fd2p)
368 /* This is the equivalent function where the protocol can be selected
369 and which therefore can be used for IPv6. */
370 extern int rexec_af (char **__restrict __ahost, int __rport,
371 __const char *__restrict __name,
372 __const char *__restrict __pass,
373 __const char *__restrict __cmd, int *__restrict __fd2p,
374 sa_family_t __af) __THROW;
376 /* Check whether user REMUSER on system RHOST is allowed to login as LOCUSER.
377 If SUSER is not zero the user tries to become superuser. Return 0 if
379 extern int ruserok (__const char *__rhost, int __suser,
380 __const char *__remuser, __const char *__locuser) __THROW;
382 /* This is the equivalent function where the protocol can be selected
383 and which therefore can be used for IPv6. */
384 extern int ruserok_af (__const char *__rhost, int __suser,
385 __const char *__remuser, __const char *__locuser,
386 sa_family_t __af) __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;
393 /* This is the equivalent function where the protocol can be selected
394 and which therefore can be used for IPv6. */
395 extern int rresvport_af (int *__alport, sa_family_t __af) __THROW;
399 /* Extension from POSIX.1g. */
401 /* Structure to contain information about address of a service provider. */
404 int ai_flags; /* Input flags. */
405 int ai_family; /* Protocol family for socket. */
406 int ai_socktype; /* Socket type. */
407 int ai_protocol; /* Protocol for socket. */
408 socklen_t ai_addrlen; /* Length of socket address. */
409 struct sockaddr *ai_addr; /* Socket address for socket. */
410 char *ai_canonname; /* Canonical name for service location. */
411 struct addrinfo *ai_next; /* Pointer to next in list. */
414 /* Possible values for `ai_flags' field in `addrinfo' structure. */
415 # define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */
416 # define AI_CANONNAME 0x0002 /* Request for canonical name. */
417 # define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */
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 /* Don't try to look up hostname. */
436 # define NI_NUMERICSERV 2 /* Don't convert port number to name. */
437 # define NI_NOFQDN 4 /* Only return nodename portion. */
438 # define NI_NAMEREQD 8 /* Don't return numeric addresses. */
439 # define NI_DGRAM 16 /* Look up UDP service rather than TCP. */
441 /* Translate name of a service location and/or a service name to set of
443 extern int getaddrinfo (__const char *__restrict __name,
444 __const char *__restrict __service,
445 __const struct addrinfo *__restrict __req,
446 struct addrinfo **__restrict __pai) __THROW;
448 /* Free `addrinfo' structure AI including associated storage. */
449 extern void freeaddrinfo (struct addrinfo *__ai) __THROW;
451 /* Convert error return from getaddrinfo() to a string. */
452 extern char *gai_strerror (int __ecode) __THROW;
454 /* Translate a socket address to a location and service name. */
455 extern int getnameinfo (__const struct sockaddr *__restrict __sa,
456 socklen_t __salen, char *__restrict __host,
457 socklen_t __hostlen, char *__restrict __serv,
458 socklen_t __servlen, int __flags) __THROW;