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>
34 /* Absolute file name for network data base files. */
35 #define _PATH_HEQUIV "/etc/hosts.equiv"
36 #define _PATH_HOSTS "/etc/hosts"
37 #define _PATH_NETWORKS "/etc/networks"
38 #define _PATH_NSSWITCH_CONF "/etc/nsswitch.conf"
39 #define _PATH_PROTOCOLS "/etc/protocols"
40 #define _PATH_SERVICES "/etc/services"
45 /* Error status for non-reentrant lookup functions. */
48 /* Function to get address of global `h_errno' variable. */
49 extern int *__h_errno_location __P ((void)) __attribute__ ((__const__));
52 # ifdef _LIBC_REENTRANT
54 __set_h_errno (int __err)
56 return *__h_errno_location () = __err;
59 # define __set_h_errno(x) (h_errno = (x))
60 # endif /* _LIBC_REENTRANT */
64 #if !defined _LIBC || defined _LIBC_REENTRANT
65 /* Use a macro to access always the thread specific `h_errno' variable. */
66 # define h_errno (*__h_errno_location ())
70 /* Possible values left in `h_errno'. */
71 #define NETDB_INTERNAL -1 /* See errno. */
72 #define NETDB_SUCCESS 0 /* No problem. */
73 #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found. */
74 #define TRY_AGAIN 2 /* Non-Authoritative Host not found,
76 #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED,
78 #define NO_DATA 4 /* Valid name, no data record of requested
80 #define NO_ADDRESS NO_DATA /* No address, look for MX record. */
82 /* Print error indicated by `h_errno' variable on standard error. STR
83 if non-null is printed before the error string. */
84 extern void herror __P ((__const char *__str));
86 /* Return string associated with error ERR_NUM. */
87 extern __const char *hstrerror __P ((int __err_num));
91 /* Description of data base entry for a single host. */
94 char *h_name; /* Official name of host. */
95 char **h_aliases; /* Alias list. */
96 int h_addrtype; /* Host address type. */
97 int h_length; /* Length of address. */
98 char **h_addr_list; /* List of addresses from name server. */
99 #define h_addr h_addr_list[0] /* Address, for backward compatibility. */
102 /* Open host data base files and mark them as staying open even after
103 a later search if STAY_OPEN is non-zero. */
104 extern void sethostent __P ((int __stay_open));
106 /* Close host data base files and clear `stay open' flag. */
107 extern void endhostent __P ((void));
109 /* Get next entry from host data base file. Open data base if
111 extern struct hostent *gethostent __P ((void));
113 /* Return entry from host data base which address match ADDR with
114 length LEN and type TYPE. */
115 extern struct hostent *gethostbyaddr __P ((__const char *__addr, int __len,
118 /* Return entry from host data base for host with NAME. */
119 extern struct hostent *gethostbyname __P ((__const char *__name));
121 /* Return entry from host data base for host with NAME. AF must be
122 set to the address type which as `AF_INET' for IPv4 or `AF_INET6'
124 extern struct hostent *gethostbyname2 __P ((__const char *__name, int __af));
127 /* Reentrant versions of the functions above. The additional
128 arguments specify a buffer of BUFLEN starting at BUF. The last
129 argument is a pointer to a variable which gets the value which
130 would be stored in the global variable `herrno' by the
131 non-reentrant functions. */
132 extern int __gethostent_r __P ((struct hostent *__result_buf, char *__buf,
133 size_t __buflen, struct hostent **__result,
135 extern int gethostent_r __P ((struct hostent *__result_buf, char *__buf,
136 size_t __buflen, struct hostent **__result,
139 extern int __gethostbyaddr_r __P ((__const char *__addr, int __len, int __type,
140 struct hostent *__result_buf, char *__buf,
141 size_t __buflen, struct hostent **__result,
143 extern int gethostbyaddr_r __P ((__const char *__addr, int __len, int __type,
144 struct hostent *__result_buf, char *__buf,
145 size_t __buflen, struct hostent **__result,
148 extern int __gethostbyname_r __P ((__const char *__name,
149 struct hostent *__result_buf, char *__buf,
150 size_t __buflen, struct hostent **__result,
152 extern int gethostbyname_r __P ((__const char *__name,
153 struct hostent *__result_buf, char *__buf,
154 size_t __buflen, struct hostent **__result,
157 extern int __gethostbyname2_r __P ((__const char *__name, int __af,
158 struct hostent *__result_buf, char *__buf,
159 size_t __buflen, struct hostent **__result,
161 extern int gethostbyname2_r __P ((__const char *__name, int __af,
162 struct hostent *__result_buf, char *__buf,
163 size_t __buflen, struct hostent **__result,
168 /* Description of data base entry for a single network. NOTE: here a
169 poor assumption is made. The network number is expected to fit
170 into an unsigned long int variable. */
173 char *n_name; /* Official name of network. */
174 char **n_aliases; /* Alias list. */
175 int n_addrtype; /* Net address type. */
176 unsigned long int n_net; /* Network number. */
179 /* Open network data base files and mark them as staying open even
180 after a later search if STAY_OPEN is non-zero. */
181 extern void setnetent __P ((int __stay_open));
183 /* Close network data base files and clear `stay open' flag. */
184 extern void endnetent __P ((void));
186 /* Get next entry from network data base file. Open data base if
188 extern struct netent *getnetent __P ((void));
190 /* Return entry from network data base which address match NET and
192 extern struct netent *getnetbyaddr __P ((unsigned long int __net,
195 /* Return entry from network data base for network with NAME. */
196 extern struct netent *getnetbyname __P ((__const char *__name));
199 /* Reentrant versions of the functions above. The additional
200 arguments specify a buffer of BUFLEN starting at BUF. The last
201 argument is a pointer to a variable which gets the value which
202 would be stored in the global variable `herrno' by the
203 non-reentrant functions. */
204 extern int __getnetent_r __P ((struct netent *__result_buf, char *__buf,
205 size_t __buflen, struct netent **__result,
207 extern int getnetent_r __P ((struct netent *__result_buf, char *__buf,
208 size_t __buflen, struct netent **__result,
211 extern int __getnetbyaddr_r __P ((unsigned long int __net, int __type,
212 struct netent *__result_buf, char *__buf,
213 size_t __buflen, struct netent **__result,
215 extern int getnetbyaddr_r __P ((unsigned long int __net, int __type,
216 struct netent *__result_buf, char *__buf,
217 size_t __buflen, struct netent **__result,
220 extern int __getnetbyname_r __P ((__const char *__name,
221 struct netent *__result_buf, char *__buf,
222 size_t __buflen, struct netent **__result,
224 extern int getnetbyname_r __P ((__const char *__name,
225 struct netent *__result_buf, char *__buf,
226 size_t __buflen, struct netent **__result,
231 /* Description of data base entry for a single service. */
234 char *s_name; /* Official service name. */
235 char **s_aliases; /* Alias list. */
236 int s_port; /* Port number. */
237 char *s_proto; /* Protocol to use. */
240 /* Open service data base files and mark them as staying open even
241 after a later search if STAY_OPEN is non-zero. */
242 extern void setservent __P ((int __stay_open));
244 /* Close service data base files and clear `stay open' flag. */
245 extern void endservent __P ((void));
247 /* Get next entry from service data base file. Open data base if
249 extern struct servent *getservent __P ((void));
251 /* Return entry from network data base for network with NAME and
253 extern struct servent *getservbyname __P ((__const char *__name,
254 __const char *__proto));
256 /* Return entry from service data base which matches port PORT and
258 extern struct servent *getservbyport __P ((int __port, __const char *__proto));
262 /* Reentrant versions of the functions above. The additional
263 arguments specify a buffer of BUFLEN starting at BUF. */
264 extern int __getservent_r __P ((struct servent *__result_buf, char *__buf,
265 size_t __buflen, struct servent **__result));
266 extern int getservent_r __P ((struct servent *__result_buf, char *__buf,
267 size_t __buflen, struct servent **__result));
269 extern int __getservbyname_r __P ((__const char *__name, __const char *__proto,
270 struct servent *__result_buf, char *__buf,
272 struct servent **__result));
273 extern int getservbyname_r __P ((__const char *__name, __const char *__proto,
274 struct servent *__result_buf, char *__buf,
275 size_t __buflen, struct servent **__result));
277 extern int __getservbyport_r __P ((int __port, __const char *__proto,
278 struct servent *__result_buf, char *__buf,
280 struct servent **__result));
281 extern int getservbyport_r __P ((int __port, __const char *__proto,
282 struct servent *__result_buf, char *__buf,
283 size_t __buflen, struct servent **__result));
287 /* Description of data base entry for a single service. */
290 char *p_name; /* Official protocol name. */
291 char **p_aliases; /* Alias list. */
292 int p_proto; /* Protocol number. */
295 /* Open protocol data base files and mark them as staying open even
296 after a later search if STAY_OPEN is non-zero. */
297 extern void setprotoent __P ((int __stay_open));
299 /* Close protocol data base files and clear `stay open' flag. */
300 extern void endprotoent __P ((void));
302 /* Get next entry from protocol data base file. Open data base if
304 extern struct protoent *getprotoent __P ((void));
306 /* Return entry from protocol data base for network with NAME. */
307 extern struct protoent *getprotobyname __P ((__const char *__name));
309 /* Return entry from protocol data base which number is PROTO. */
310 extern struct protoent *getprotobynumber __P ((int __proto));
314 /* Reentrant versions of the functions above. The additional
315 arguments specify a buffer of BUFLEN starting at BUF. */
316 extern int __getprotoent_r __P ((struct protoent *__result_buf, char *__buf,
317 size_t __buflen, struct protoent **__result));
318 extern int getprotoent_r __P ((struct protoent *__result_buf, char *__buf,
319 size_t __buflen, struct protoent **__result));
321 extern int __getprotobyname_r __P ((__const char *__name,
322 struct protoent *__result_buf, char *__buf,
324 struct protoent **__result));
325 extern int getprotobyname_r __P ((__const char *__name,
326 struct protoent *__result_buf, char *__buf,
328 struct protoent **__result));
330 extern int __getprotobynumber_r __P ((int __proto, struct protoent *__res_buf,
331 char *__buf, size_t __buflen,
332 struct protoent **__result));
333 extern int getprotobynumber_r __P ((int __proto, struct protoent *__result_buf,
334 char *__buf, size_t __buflen,
335 struct protoent **__result));
339 /* Establish network group NETGROUP for enumeration. */
340 extern int setnetgrent __P ((__const char *__netgroup));
342 /* Free all space allocated by previous `setnetgrent' call. */
343 extern void endnetgrent __P ((void));
345 /* Get next member of netgroup established by last `setnetgrent' call
346 and return pointers to elements in HOSTP, USERP, and DOMAINP. */
347 extern int getnetgrent __P ((char **__hostp, char **__userp,
350 /* Test whether NETGROUP contains the triple (HOST,USER,DOMAIN). */
351 extern int innetgr __P ((__const char *__netgroup, __const char *__host,
352 __const char *__user, __const char *domain));
355 /* Reentrant version of `getnetgrent' where result is placed in BUFFER. */
356 extern int __getnetgrent_r __P ((char **__hostp, char **__userp,
358 char *__buffer, size_t __buflen));
359 extern int getnetgrent_r __P ((char **__hostp, char **__userp,
361 char *__buffer, size_t __buflen));
366 /* Call `rshd' at port RPORT on remote machine *AHOST to execute CMD.
367 The local user is LOCUSER, on the remote machine the command is
368 executed as REMUSER. In *FD2P the descriptor to the socket for the
369 connection is returned. The caller must have the right to use a
370 reserved port. When the function returns *AHOST contains the
371 official host name. */
372 extern int rcmd __P ((char **__ahost, unsigned short int __rport,
373 __const char *__locuser, __const char *__remuser,
374 __const char *__cmd, int *__fd2p));
376 /* Call `rexecd' at port RPORT on remote machine *AHOST to execute
377 CMD. The process runs at the remote machine using the ID of user
378 NAME whose cleartext password is PASSWD. In *FD2P the descriptor
379 to the socket for the connection is returned. When the function
380 returns *AHOST contains the official host name. */
381 extern int rexec __P ((char **__ahost, int __rport, __const char *__name,
382 __const char *__pass, __const char *__cmd,
385 /* Check whether user REMUSER on system RHOST is allowed to login as LOCUSER.
386 If SUSER is not zero the user tries to become superuser. Return 0 if
388 extern int ruserok __P ((__const char *__rhost, int __suser,
389 __const char *__remuser, __const char *__locuser));
391 /* Try to allocate reserved port, returning a descriptor for a socket opened
392 at this port or -1 if unsuccessful. The search for an available port
393 will start at ALPORT and continues with lower numbers. */
394 extern int rresvport __P ((int *__alport));
398 /* Extension from POSIX.1g. */
400 /* Structure to contain information about address of a service provider. */
403 int ai_flags; /* Input flags. */
404 int ai_family; /* Protocol family for socket. */
405 int ai_socktype; /* Socket type. */
406 int ai_protocol; /* Protocol for socket. */
407 int ai_addrlen; /* Length of socket address. */
408 struct sockaddr *ai_addr; /* Socket address for socket. */
409 char *ai_canonname; /* Canonical name for service location. */
410 struct addrinfo *ai_next; /* Pointer to next in list. */
413 /* Possible values for `ai_flags' field in `addrinfo' structure. */
414 # define AI_PASSIVE 1 /* Socket address is intended for `bind'. */
415 # define AI_CANONNAME 2 /* Request for canonical name. */
417 /* Error values for `getaddrinfo' function. */
418 # define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */
419 # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
420 # define EAI_AGAIN -3 /* Temporary failure in name resolution. */
421 # define EAI_FAIL -4 /* Non-recoverable failure in name res. */
422 # define EAI_NODATA -5 /* No address associated with NAME. */
423 # define EAI_FAMILY -6 /* `ai_family' not supported. */
424 # define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */
425 # define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
426 # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
427 # define EAI_MEMORY -10 /* Memory allocation failure. */
428 # define EAI_SYSTEM -11 /* System error returned in `errno'. */
430 # define NI_MAXHOST 1025
431 # define NI_MAXSERV 32
433 # define NI_NUMERICHOST 1
434 # define NI_NUMERICSERV 2
436 # define NI_NAMEREQD 8
439 /* Translate name of a service location and/or a service name to set of
441 extern int getaddrinfo __P ((__const char *__name, __const char *__service,
442 __const struct addrinfo *__req,
443 struct addrinfo **__pai));
445 /* Free `addrinfo' structure AI including associated storage. */
446 extern void freeaddrinfo __P ((struct addrinfo *__ai));
448 /* Convert error return from getaddrinfo() to a string. */
449 extern char *gai_strerror __P ((int __ecode));
451 /* Translate a socket address to a location and service name. */
452 extern int getnameinfo __P ((__const struct sockaddr *__sa, size_t __salen,
453 char *__host, size_t __hostlen,
454 char *__serv, size_t __servlen,