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
*__result_buf
, char *__buf
,
134 size_t __buflen
, struct hostent
**__result
,
136 extern int gethostent_r
__P ((struct hostent
*__result_buf
, char *__buf
,
137 size_t __buflen
, struct hostent
**__result
,
140 extern int __gethostbyaddr_r
__P ((__const
char *__addr
, int __len
, int __type
,
141 struct hostent
*__result_buf
, char *__buf
,
142 size_t __buflen
, struct hostent
**__result
,
144 extern int gethostbyaddr_r
__P ((__const
char *__addr
, int __len
, int __type
,
145 struct hostent
*__result_buf
, char *__buf
,
146 size_t __buflen
, struct hostent
**__result
,
149 extern int __gethostbyname_r
__P ((__const
char *__name
,
150 struct hostent
*__result_buf
, char *__buf
,
151 size_t __buflen
, struct hostent
**__result
,
153 extern int gethostbyname_r
__P ((__const
char *__name
,
154 struct hostent
*__result_buf
, char *__buf
,
155 size_t __buflen
, struct hostent
**__result
,
158 extern int __gethostbyname2_r
__P ((__const
char *__name
, int __af
,
159 struct hostent
*__result_buf
, char *__buf
,
160 size_t __buflen
, struct hostent
**__result
,
162 extern int gethostbyname2_r
__P ((__const
char *__name
, int __af
,
163 struct hostent
*__result_buf
, char *__buf
,
164 size_t __buflen
, struct hostent
**__result
,
169 /* Return entry from host data base for host with NAME. AF must be
170 set to the desired address type (either `AF_INET' or `AF_INET6').
171 FLAGS is some combination of the following AI_* values. */
172 extern struct hostent
*getnodebyname
__P ((__const
char *__name
, int __af
,
175 #define AI_V4MAPPED 1 /* IPv4-mapped addresses are acceptable. */
176 #define AI_ALL 2 /* Return both IPv4 and IPv6 addresses. */
177 #define AI_ADDRCONFIG 4 /* Use configuration of this host to choose
178 returned address type. */
179 #define AI_DEFAULT (AI_V4MAPPED | AI_ADDRCONFIG)
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
__P ((int __stay_open
));
197 /* Close network data base files and clear `stay open' flag. */
198 extern void endnetent
__P ((void));
200 /* Get next entry from network data base file. Open data base if
202 extern struct netent
*getnetent
__P ((void));
204 /* Return entry from network data base which address match NET and
206 extern struct netent
*getnetbyaddr
__P ((unsigned long int __net
,
209 /* Return entry from network data base for network with NAME. */
210 extern struct netent
*getnetbyname
__P ((__const
char *__name
));
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
__P ((struct netent
*__result_buf
, char *__buf
,
219 size_t __buflen
, struct netent
**__result
,
221 extern int getnetent_r
__P ((struct netent
*__result_buf
, char *__buf
,
222 size_t __buflen
, struct netent
**__result
,
225 extern int __getnetbyaddr_r
__P ((unsigned long int __net
, int __type
,
226 struct netent
*__result_buf
, char *__buf
,
227 size_t __buflen
, struct netent
**__result
,
229 extern int getnetbyaddr_r
__P ((unsigned long int __net
, int __type
,
230 struct netent
*__result_buf
, char *__buf
,
231 size_t __buflen
, struct netent
**__result
,
234 extern int __getnetbyname_r
__P ((__const
char *__name
,
235 struct netent
*__result_buf
, char *__buf
,
236 size_t __buflen
, struct netent
**__result
,
238 extern int getnetbyname_r
__P ((__const
char *__name
,
239 struct netent
*__result_buf
, char *__buf
,
240 size_t __buflen
, struct netent
**__result
,
245 /* Description of data base entry for a single service. */
248 char *s_name
; /* Official service name. */
249 char **s_aliases
; /* Alias list. */
250 int s_port
; /* Port number. */
251 char *s_proto
; /* Protocol to use. */
254 /* Open service data base files and mark them as staying open even
255 after a later search if STAY_OPEN is non-zero. */
256 extern void setservent
__P ((int __stay_open
));
258 /* Close service data base files and clear `stay open' flag. */
259 extern void endservent
__P ((void));
261 /* Get next entry from service data base file. Open data base if
263 extern struct servent
*getservent
__P ((void));
265 /* Return entry from network data base for network with NAME and
267 extern struct servent
*getservbyname
__P ((__const
char *__name
,
268 __const
char *__proto
));
270 /* Return entry from service data base which matches port PORT and
272 extern struct servent
*getservbyport
__P ((int __port
, __const
char *__proto
));
276 /* Reentrant versions of the functions above. The additional
277 arguments specify a buffer of BUFLEN starting at BUF. */
278 extern int __getservent_r
__P ((struct servent
*__result_buf
, char *__buf
,
279 size_t __buflen
, struct servent
**__result
));
280 extern int getservent_r
__P ((struct servent
*__result_buf
, char *__buf
,
281 size_t __buflen
, struct servent
**__result
));
283 extern int __getservbyname_r
__P ((__const
char *__name
, __const
char *__proto
,
284 struct servent
*__result_buf
, char *__buf
,
286 struct servent
**__result
));
287 extern int getservbyname_r
__P ((__const
char *__name
, __const
char *__proto
,
288 struct servent
*__result_buf
, char *__buf
,
289 size_t __buflen
, struct servent
**__result
));
291 extern int __getservbyport_r
__P ((int __port
, __const
char *__proto
,
292 struct servent
*__result_buf
, char *__buf
,
294 struct servent
**__result
));
295 extern int getservbyport_r
__P ((int __port
, __const
char *__proto
,
296 struct servent
*__result_buf
, char *__buf
,
297 size_t __buflen
, struct servent
**__result
));
301 /* Description of data base entry for a single service. */
304 char *p_name
; /* Official protocol name. */
305 char **p_aliases
; /* Alias list. */
306 int p_proto
; /* Protocol number. */
309 /* Open protocol data base files and mark them as staying open even
310 after a later search if STAY_OPEN is non-zero. */
311 extern void setprotoent
__P ((int __stay_open
));
313 /* Close protocol data base files and clear `stay open' flag. */
314 extern void endprotoent
__P ((void));
316 /* Get next entry from protocol data base file. Open data base if
318 extern struct protoent
*getprotoent
__P ((void));
320 /* Return entry from protocol data base for network with NAME. */
321 extern struct protoent
*getprotobyname
__P ((__const
char *__name
));
323 /* Return entry from protocol data base which number is PROTO. */
324 extern struct protoent
*getprotobynumber
__P ((int __proto
));
328 /* Reentrant versions of the functions above. The additional
329 arguments specify a buffer of BUFLEN starting at BUF. */
330 extern int __getprotoent_r
__P ((struct protoent
*__result_buf
, char *__buf
,
331 size_t __buflen
, struct protoent
**__result
));
332 extern int getprotoent_r
__P ((struct protoent
*__result_buf
, char *__buf
,
333 size_t __buflen
, struct protoent
**__result
));
335 extern int __getprotobyname_r
__P ((__const
char *__name
,
336 struct protoent
*__result_buf
, char *__buf
,
338 struct protoent
**__result
));
339 extern int getprotobyname_r
__P ((__const
char *__name
,
340 struct protoent
*__result_buf
, char *__buf
,
342 struct protoent
**__result
));
344 extern int __getprotobynumber_r
__P ((int __proto
, struct protoent
*__res_buf
,
345 char *__buf
, size_t __buflen
,
346 struct protoent
**__result
));
347 extern int getprotobynumber_r
__P ((int __proto
, struct protoent
*__result_buf
,
348 char *__buf
, size_t __buflen
,
349 struct protoent
**__result
));
353 /* Establish network group NETGROUP for enumeration. */
354 extern int setnetgrent
__P ((__const
char *__netgroup
));
356 /* Free all space allocated by previous `setnetgrent' call. */
357 extern void endnetgrent
__P ((void));
359 /* Get next member of netgroup established by last `setnetgrent' call
360 and return pointers to elements in HOSTP, USERP, and DOMAINP. */
361 extern int getnetgrent
__P ((char **__hostp
, char **__userp
,
364 /* Test whether NETGROUP contains the triple (HOST,USER,DOMAIN). */
365 extern int innetgr
__P ((__const
char *__netgroup
, __const
char *__host
,
366 __const
char *__user
, __const
char *domain
));
369 /* Reentrant version of `getnetgrent' where result is placed in BUFFER. */
370 extern int __getnetgrent_r
__P ((char **__hostp
, char **__userp
,
372 char *__buffer
, size_t __buflen
));
373 extern int getnetgrent_r
__P ((char **__hostp
, char **__userp
,
375 char *__buffer
, size_t __buflen
));
380 /* Call `rshd' at port RPORT on remote machine *AHOST to execute CMD.
381 The local user is LOCUSER, on the remote machine the command is
382 executed as REMUSER. In *FD2P the descriptor to the socket for the
383 connection is returned. The caller must have the right to use a
384 reserved port. When the function returns *AHOST contains the
385 official host name. */
386 extern int rcmd
__P ((char **__ahost
, unsigned short int __rport
,
387 __const
char *__locuser
, __const
char *__remuser
,
388 __const
char *__cmd
, int *__fd2p
));
390 /* Call `rexecd' at port RPORT on remote machine *AHOST to execute
391 CMD. The process runs at the remote machine using the ID of user
392 NAME whose cleartext password is PASSWD. In *FD2P the descriptor
393 to the socket for the connection is returned. When the function
394 returns *AHOST contains the official host name. */
395 extern int rexec
__P ((char **__ahost
, int __rport
, __const
char *__name
,
396 __const
char *__pass
, __const
char *__cmd
,
399 /* Check whether user REMUSER on system RHOST is allowed to login as LOCUSER.
400 If SUSER is not zero the user tries to become superuser. Return 0 if
402 extern int ruserok
__P ((__const
char *__rhost
, int __suser
,
403 __const
char *__remuser
, __const
char *__locuser
));
405 /* Try to allocate reserved port, returning a descriptor for a socket opened
406 at this port or -1 if unsuccessful. The search for an available port
407 will start at ALPORT and continues with lower numbers. */
408 extern int rresvport
__P ((int *__alport
));
412 /* Extension from POSIX.1g. */
414 /* Structure to contain information about address of a service provider. */
417 int ai_flags
; /* Input flags. */
418 int ai_family
; /* Protocol family for socket. */
419 int ai_socktype
; /* Socket type. */
420 int ai_protocol
; /* Protocol for socket. */
421 int ai_addrlen
; /* Length of socket address. */
422 struct sockaddr
*ai_addr
; /* Socket address for socket. */
423 char *ai_canonname
; /* Canonical name for service location. */
424 struct addrinfo
*ai_next
; /* Pointer to next in list. */
427 /* Possible values for `ai_flags' field in `addrinfo' structure. */
428 # define AI_PASSIVE 1 /* Socket address is intended for `bind'. */
429 # define AI_CANONNAME 2 /* Request for canonical name. */
430 # define AI_NUMERICHOST 3 /* Don't use name resolution. */
432 /* Error values for `getaddrinfo' function. */
433 # define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */
434 # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
435 # define EAI_AGAIN -3 /* Temporary failure in name resolution. */
436 # define EAI_FAIL -4 /* Non-recoverable failure in name res. */
437 # define EAI_NODATA -5 /* No address associated with NAME. */
438 # define EAI_FAMILY -6 /* `ai_family' not supported. */
439 # define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */
440 # define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
441 # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
442 # define EAI_MEMORY -10 /* Memory allocation failure. */
443 # define EAI_SYSTEM -11 /* System error returned in `errno'. */
445 # define NI_MAXHOST 1025
446 # define NI_MAXSERV 32
448 # define NI_NUMERICHOST 1 /* Don't try to look up hostname. */
449 # define NI_NUMERICSERV 2 /* Don't convert port number to name. */
450 # define NI_NOFQDN 4 /* Only return nodename portion. */
451 # define NI_NAMEREQD 8 /* Don't return numeric addresses. */
452 # define NI_DGRAM 16 /* Look up UDP service rather than TCP. */
454 /* Translate name of a service location and/or a service name to set of
456 extern int getaddrinfo
__P ((__const
char *__name
, __const
char *__service
,
457 __const
struct addrinfo
*__req
,
458 struct addrinfo
**__pai
));
460 /* Free `addrinfo' structure AI including associated storage. */
461 extern void freeaddrinfo
__P ((struct addrinfo
*__ai
));
463 /* Convert error return from getaddrinfo() to a string. */
464 extern char *gai_strerror
__P ((int __ecode
));
466 /* Translate a socket address to a location and service name. */
467 extern int getnameinfo
__P ((__const
struct sockaddr
*__sa
, socklen_t __salen
,
468 char *__host
, size_t __hostlen
,
469 char *__serv
, size_t __servlen
,