1 /* Copyright (C) 1996-2002, 2003, 2004 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 and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
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 #include <netinet/in.h>
31 /* This is necessary to make this include file properly replace the
33 # include <rpc/netdb.h>
37 # define __need_sigevent_t
38 # include <bits/siginfo.h>
39 # define __need_timespec
43 #include <bits/netdb.h>
45 /* Absolute file name for network data base files. */
46 #define _PATH_HEQUIV "/etc/hosts.equiv"
47 #define _PATH_HOSTS "/etc/hosts"
48 #define _PATH_NETWORKS "/etc/networks"
49 #define _PATH_NSSWITCH_CONF "/etc/nsswitch.conf"
50 #define _PATH_PROTOCOLS "/etc/protocols"
51 #define _PATH_SERVICES "/etc/services"
56 /* Error status for non-reentrant lookup functions.
57 We use a macro to access always the thread-specific `h_errno' variable.
58 We always need the extern int here in case internal libc code undefines
59 the macro because it needs access to the underlying storage. */
61 #ifdef __UCLIBC_HAS_THREADS__
62 # define h_errno (*__h_errno_location ())
65 /* Function to get address of global `h_errno' variable. */
66 extern int *__h_errno_location (void) __THROW __attribute__ ((__const__));
69 # define __set_h_errno(x) (h_errno = (x))
72 /* Possible values left in `h_errno'. */
73 #define NETDB_INTERNAL -1 /* See errno. */
74 #define NETDB_SUCCESS 0 /* No problem. */
75 #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found. */
76 #define TRY_AGAIN 2 /* Non-Authoritative Host not found,
78 #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED,
80 #define NO_DATA 4 /* Valid name, no data record of requested
82 #define NO_ADDRESS NO_DATA /* No address, look for MX record. */
85 /* Highest reserved Internet port number. */
86 # define IPPORT_RESERVED 1024
90 /* Scope delimiter for getaddrinfo(), getnameinfo(). */
91 # define SCOPE_DELIMITER '%'
94 /* Print error indicated by `h_errno' variable on standard error. STR
95 if non-null is printed before the error string. */
96 extern void herror (__const char *__str) __THROW;
98 /* Return string associated with error ERR_NUM. */
99 extern __const char *hstrerror (int __err_num) __THROW;
103 /* Description of data base entry for a single host. */
106 char *h_name; /* Official name of host. */
107 char **h_aliases; /* Alias list. */
108 int h_addrtype; /* Host address type. */
109 int h_length; /* Length of address. */
110 char **h_addr_list; /* List of addresses from name server. */
111 #define h_addr h_addr_list[0] /* Address, for backward compatibility. */
114 /* Open host data base files and mark them as staying open even after
115 a later search if STAY_OPEN is non-zero.
117 This function is a possible cancellation point and therefore not
118 marked with __THROW. */
119 extern void sethostent (int __stay_open);
121 /* Close host data base files and clear `stay open' flag.
123 This function is a possible cancellation point and therefore not
124 marked with __THROW. */
125 extern void endhostent (void);
127 /* Get next entry from host data base file. Open data base if
130 This function is a possible cancellation point and therefore not
131 marked with __THROW. */
132 extern struct hostent *gethostent (void);
134 /* Return entry from host data base which address match ADDR with
135 length LEN and type TYPE.
137 This function is a possible cancellation point and therefore not
138 marked with __THROW. */
139 extern struct hostent *gethostbyaddr (__const void *__addr, __socklen_t __len,
142 /* Return entry from host data base for host with NAME.
144 This function is a possible cancellation point and therefore not
145 marked with __THROW. */
146 extern struct hostent *gethostbyname (__const char *__name);
149 /* Return entry from host data base for host with NAME. AF must be
150 set to the address type which is `AF_INET' for IPv4 or `AF_INET6'
153 This function is not part of POSIX and therefore no official
154 cancellation point. But due to similarity with an POSIX interface
155 or due to the implementation it is a cancellation point and
156 therefore not marked with __THROW. */
157 extern struct hostent *gethostbyname2 (__const char *__name, int __af);
159 /* Reentrant versions of the functions above. The additional
160 arguments specify a buffer of BUFLEN starting at BUF. The last
161 argument is a pointer to a variable which gets the value which
162 would be stored in the global variable `herrno' by the
163 non-reentrant functions.
165 These functions are not part of POSIX and therefore no official
166 cancellation point. But due to similarity with an POSIX interface
167 or due to the implementation they are cancellation points and
168 therefore not marked with __THROW. */
169 extern int gethostent_r (struct hostent *__restrict __result_buf,
170 char *__restrict __buf, size_t __buflen,
171 struct hostent **__restrict __result,
172 int *__restrict __h_errnop);
174 extern int gethostbyaddr_r (__const void *__restrict __addr, __socklen_t __len,
176 struct hostent *__restrict __result_buf,
177 char *__restrict __buf, size_t __buflen,
178 struct hostent **__restrict __result,
179 int *__restrict __h_errnop);
181 extern int gethostbyname_r (__const char *__restrict __name,
182 struct hostent *__restrict __result_buf,
183 char *__restrict __buf, size_t __buflen,
184 struct hostent **__restrict __result,
185 int *__restrict __h_errnop);
187 extern int gethostbyname2_r (__const char *__restrict __name, int __af,
188 struct hostent *__restrict __result_buf,
189 char *__restrict __buf, size_t __buflen,
190 struct hostent **__restrict __result,
191 int *__restrict __h_errnop);
195 /* Open network data base files and mark them as staying open even
196 after a later search if STAY_OPEN is non-zero.
198 This function is a possible cancellation point and therefore not
199 marked with __THROW. */
200 extern void setnetent (int __stay_open);
202 /* Close network data base files and clear `stay open' flag.
204 This function is a possible cancellation point and therefore not
205 marked with __THROW. */
206 extern void endnetent (void);
208 /* Get next entry from network data base file. Open data base if
211 This function is a possible cancellation point and therefore not
212 marked with __THROW. */
213 extern struct netent *getnetent (void);
215 /* Return entry from network data base which address match NET and
218 This function is a possible cancellation point and therefore not
219 marked with __THROW. */
220 extern struct netent *getnetbyaddr (uint32_t __net, int __type);
222 /* Return entry from network data base for network with NAME.
224 This function is a possible cancellation point and therefore not
225 marked with __THROW. */
226 extern struct netent *getnetbyname (__const char *__name);
231 /* Reentrant versions of the functions above. The additional
232 arguments specify a buffer of BUFLEN starting at BUF. The last
233 argument is a pointer to a variable which gets the value which
234 would be stored in the global variable `herrno' by the
235 non-reentrant functions.
237 These functions are not part of POSIX and therefore no official
238 cancellation point. But due to similarity with an POSIX interface
239 or due to the implementation they are cancellation points and
240 therefore not marked with __THROW. */
241 extern int getnetent_r (struct netent *__restrict __result_buf,
242 char *__restrict __buf, size_t __buflen,
243 struct netent **__restrict __result,
244 int *__restrict __h_errnop);
246 extern int getnetbyaddr_r (uint32_t __net, int __type,
247 struct netent *__restrict __result_buf,
248 char *__restrict __buf, size_t __buflen,
249 struct netent **__restrict __result,
250 int *__restrict __h_errnop);
252 extern int getnetbyname_r (__const char *__restrict __name,
253 struct netent *__restrict __result_buf,
254 char *__restrict __buf, size_t __buflen,
255 struct netent **__restrict __result,
256 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.
273 This function is a possible cancellation point and therefore not
274 marked with __THROW. */
275 extern void setservent (int __stay_open);
277 /* Close service data base files and clear `stay open' flag.
279 This function is a possible cancellation point and therefore not
280 marked with __THROW. */
281 extern void endservent (void);
283 /* Get next entry from service data base file. Open data base if
286 This function is a possible cancellation point and therefore not
287 marked with __THROW. */
288 extern struct servent *getservent (void);
290 /* Return entry from network data base for network with NAME and
293 This function is a possible cancellation point and therefore not
294 marked with __THROW. */
295 extern struct servent *getservbyname (__const char *__name,
296 __const char *__proto);
298 /* Return entry from service data base which matches port PORT and
301 This function is a possible cancellation point and therefore not
302 marked with __THROW. */
303 extern struct servent *getservbyport (int __port, __const char *__proto);
307 /* Reentrant versions of the functions above. The additional
308 arguments specify a buffer of BUFLEN starting at BUF.
310 These functions are not part of POSIX and therefore no official
311 cancellation point. But due to similarity with an POSIX interface
312 or due to the implementation they are cancellation points and
313 therefore not marked with __THROW. */
314 extern int getservent_r (struct servent *__restrict __result_buf,
315 char *__restrict __buf, size_t __buflen,
316 struct servent **__restrict __result);
318 extern int getservbyname_r (__const char *__restrict __name,
319 __const char *__restrict __proto,
320 struct servent *__restrict __result_buf,
321 char *__restrict __buf, size_t __buflen,
322 struct servent **__restrict __result);
324 extern int getservbyport_r (int __port, __const char *__restrict __proto,
325 struct servent *__restrict __result_buf,
326 char *__restrict __buf, size_t __buflen,
327 struct servent **__restrict __result);
331 /* Description of data base entry for a single service. */
334 char *p_name; /* Official protocol name. */
335 char **p_aliases; /* Alias list. */
336 int p_proto; /* Protocol number. */
339 /* Open protocol data base files and mark them as staying open even
340 after a later search if STAY_OPEN is non-zero.
342 This function is a possible cancellation point and therefore not
343 marked with __THROW. */
344 extern void setprotoent (int __stay_open);
346 /* Close protocol data base files and clear `stay open' flag.
348 This function is a possible cancellation point and therefore not
349 marked with __THROW. */
350 extern void endprotoent (void);
352 /* Get next entry from protocol data base file. Open data base if
355 This function is a possible cancellation point and therefore not
356 marked with __THROW. */
357 extern struct protoent *getprotoent (void);
359 /* Return entry from protocol data base for network with NAME.
361 This function is a possible cancellation point and therefore not
362 marked with __THROW. */
363 extern struct protoent *getprotobyname (__const char *__name);
365 /* Return entry from protocol data base which number is PROTO.
367 This function is a possible cancellation point and therefore not
368 marked with __THROW. */
369 extern struct protoent *getprotobynumber (int __proto);
373 /* Reentrant versions of the functions above. The additional
374 arguments specify a buffer of BUFLEN starting at BUF.
376 These functions are not part of POSIX and therefore no official
377 cancellation point. But due to similarity with an POSIX interface
378 or due to the implementation they are cancellation points and
379 therefore not marked with __THROW. */
380 extern int getprotoent_r (struct protoent *__restrict __result_buf,
381 char *__restrict __buf, size_t __buflen,
382 struct protoent **__restrict __result);
384 extern int getprotobyname_r (__const char *__restrict __name,
385 struct protoent *__restrict __result_buf,
386 char *__restrict __buf, size_t __buflen,
387 struct protoent **__restrict __result);
389 extern int getprotobynumber_r (int __proto,
390 struct protoent *__restrict __result_buf,
391 char *__restrict __buf, size_t __buflen,
392 struct protoent **__restrict __result);
395 #ifdef __UCLIBC_HAS_NETGROUP__
396 /* Establish network group NETGROUP for enumeration.
398 This function is not part of POSIX and therefore no official
399 cancellation point. But due to similarity with an POSIX interface
400 or due to the implementation it is a cancellation point and
401 therefore not marked with __THROW. */
402 extern int setnetgrent (__const char *__netgroup);
404 /* Free all space allocated by previous `setnetgrent' call.
406 This function is not part of POSIX and therefore no official
407 cancellation point. But due to similarity with an POSIX interface
408 or due to the implementation it is a cancellation point and
409 therefore not marked with __THROW. */
410 extern void endnetgrent (void);
412 /* Get next member of netgroup established by last `setnetgrent' call
413 and return pointers to elements in HOSTP, USERP, and DOMAINP.
415 This function is not part of POSIX and therefore no official
416 cancellation point. But due to similarity with an POSIX interface
417 or due to the implementation it is a cancellation point and
418 therefore not marked with __THROW. */
419 extern int getnetgrent (char **__restrict __hostp,
420 char **__restrict __userp,
421 char **__restrict __domainp);
424 /* Test whether NETGROUP contains the triple (HOST,USER,DOMAIN).
426 This function is not part of POSIX and therefore no official
427 cancellation point. But due to similarity with an POSIX interface
428 or due to the implementation it is a cancellation point and
429 therefore not marked with __THROW. */
430 extern int innetgr (__const char *__netgroup, __const char *__host,
431 __const char *__user, __const char *domain);
433 /* Reentrant version of `getnetgrent' where result is placed in BUFFER.
435 This function is not part of POSIX and therefore no official
436 cancellation point. But due to similarity with an POSIX interface
437 or due to the implementation it is a cancellation point and
438 therefore not marked with __THROW. */
439 extern int getnetgrent_r (char **__restrict __hostp,
440 char **__restrict __userp,
441 char **__restrict __domainp,
442 char *__restrict __buffer, size_t __buflen);
443 #endif /* UCLIBC_HAS_NETGROUP */
447 /* ruserpass - remote password check.
448 This function also exists in glibc but is undocumented */
449 extern int ruserpass(const char *host, const char **aname, const char **apass);
453 /* Call `rshd' at port RPORT on remote machine *AHOST to execute CMD.
454 The local user is LOCUSER, on the remote machine the command is
455 executed as REMUSER. In *FD2P the descriptor to the socket for the
456 connection is returned. The caller must have the right to use a
457 reserved port. When the function returns *AHOST contains the
460 This function is not part of POSIX and therefore no official
461 cancellation point. But due to similarity with an POSIX interface
462 or due to the implementation it is a cancellation point and
463 therefore not marked with __THROW. */
464 extern int rcmd (char **__restrict __ahost, unsigned short int __rport,
465 __const char *__restrict __locuser,
466 __const char *__restrict __remuser,
467 __const char *__restrict __cmd, int *__restrict __fd2p);
471 /* This is the equivalent function where the protocol can be selected
472 and which therefore can be used for IPv6.
474 This function is not part of POSIX and therefore no official
475 cancellation point. But due to similarity with an POSIX interface
476 or due to the implementation it is a cancellation point and
477 therefore not marked with __THROW. */
478 extern int rcmd_af (char **__restrict __ahost, unsigned short int __rport,
479 __const char *__restrict __locuser,
480 __const char *__restrict __remuser,
481 __const char *__restrict __cmd, int *__restrict __fd2p,
485 /* Call `rexecd' at port RPORT on remote machine *AHOST to execute
486 CMD. The process runs at the remote machine using the ID of user
487 NAME whose cleartext password is PASSWD. In *FD2P the descriptor
488 to the socket for the connection is returned. When the function
489 returns *AHOST contains the official host name.
491 This function is not part of POSIX and therefore no official
492 cancellation point. But due to similarity with an POSIX interface
493 or due to the implementation it is a cancellation point and
494 therefore not marked with __THROW. */
495 extern int rexec (char **__restrict __ahost, int __rport,
496 __const char *__restrict __name,
497 __const char *__restrict __pass,
498 __const char *__restrict __cmd, int *__restrict __fd2p);
500 /* This is the equivalent function where the protocol can be selected
501 and which therefore can be used for IPv6.
503 This function is not part of POSIX and therefore no official
504 cancellation point. But due to similarity with an POSIX interface
505 or due to the implementation it is a cancellation point and
506 therefore not marked with __THROW. */
507 extern int rexec_af (char **__restrict __ahost, int __rport,
508 __const char *__restrict __name,
509 __const char *__restrict __pass,
510 __const char *__restrict __cmd, int *__restrict __fd2p,
513 /* Check whether user REMUSER on system RHOST is allowed to login as LOCUSER.
514 If SUSER is not zero the user tries to become superuser. Return 0 if
517 This function is not part of POSIX and therefore no official
518 cancellation point. But due to similarity with an POSIX interface
519 or due to the implementation it is a cancellation point and
520 therefore not marked with __THROW. */
521 extern int ruserok (__const char *__rhost, int __suser,
522 __const char *__remuser, __const char *__locuser);
526 /* This is the equivalent function where the protocol can be selected
527 and which therefore can be used for IPv6.
529 This function is not part of POSIX and therefore no official
530 cancellation point. But due to similarity with an POSIX interface
531 or due to the implementation it is a cancellation point and
532 therefore not marked with __THROW. */
533 extern int ruserok_af (__const char *__rhost, int __suser,
534 __const char *__remuser, __const char *__locuser,
538 /* Try to allocate reserved port, returning a descriptor for a socket opened
539 at this port or -1 if unsuccessful. The search for an available port
540 will start at ALPORT and continues with lower numbers.
542 This function is not part of POSIX and therefore no official
543 cancellation point. But due to similarity with an POSIX interface
544 or due to the implementation it is a cancellation point and
545 therefore not marked with __THROW. */
546 extern int rresvport (int *__alport);
550 /* This is the equivalent function where the protocol can be selected
551 and which therefore can be used for IPv6.
553 This function is not part of POSIX and therefore no official
554 cancellation point. But due to similarity with an POSIX interface
555 or due to the implementation it is a cancellation point and
556 therefore not marked with __THROW. */
557 extern int rresvport_af (int *__alport, sa_family_t __af);
562 /* Extension from POSIX.1g. */
564 /* Structure to contain information about address of a service provider. */
567 int ai_flags; /* Input flags. */
568 int ai_family; /* Protocol family for socket. */
569 int ai_socktype; /* Socket type. */
570 int ai_protocol; /* Protocol for socket. */
571 socklen_t ai_addrlen; /* Length of socket address. */
572 struct sockaddr *ai_addr; /* Socket address for socket. */
573 char *ai_canonname; /* Canonical name for service location. */
574 struct addrinfo *ai_next; /* Pointer to next in list. */
577 /* Possible values for `ai_flags' field in `addrinfo' structure. */
578 # define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */
579 # define AI_CANONNAME 0x0002 /* Request for canonical name. */
580 # define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */
581 # define AI_V4MAPPED 0x0008 /* IPv4 mapped addresses are acceptable. */
582 # define AI_ALL 0x0010 /* Return IPv4 mapped and IPv6 addresses. */
583 # define AI_ADDRCONFIG 0x0020 /* Use configuration of this host to choose
584 returned address type.. */
586 # define AI_IDN 0x0040 /* IDN encode input (assuming it is encoded
587 in the current locale's character set)
588 before looking it up. */
589 # define AI_CANONIDN 0x0080 /* Translate canonical name from IDN format. */
590 # define AI_IDN_ALLOW_UNASSIGNED 0x0100 /* Don't reject unassigned Unicode
592 # define AI_IDN_USE_STD3_ASCII_RULES 0x0200 /* Validate strings according to
595 # define AI_NUMERICSERV 0x0400 /* Don't use name resolution. */
597 /* Error values for `getaddrinfo' function. */
598 # define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */
599 # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
600 # define EAI_AGAIN -3 /* Temporary failure in name resolution. */
601 # define EAI_FAIL -4 /* Non-recoverable failure in name res. */
602 # define EAI_NODATA -5 /* No address associated with NAME. */
603 # define EAI_FAMILY -6 /* `ai_family' not supported. */
604 # define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */
605 # define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
606 # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
607 # define EAI_MEMORY -10 /* Memory allocation failure. */
608 # define EAI_SYSTEM -11 /* System error returned in `errno'. */
609 # define EAI_OVERFLOW -12 /* Argument buffer overflow. */
611 # define EAI_INPROGRESS -100 /* Processing request in progress. */
612 # define EAI_CANCELED -101 /* Request canceled. */
613 # define EAI_NOTCANCELED -102 /* Request not canceled. */
614 # define EAI_ALLDONE -103 /* All requests done. */
615 # define EAI_INTR -104 /* Interrupted by a signal. */
616 # define EAI_IDN_ENCODE -105 /* IDN encoding failed. */
619 # define NI_MAXHOST 1025
620 # define NI_MAXSERV 32
622 # define NI_NUMERICHOST 1 /* Don't try to look up hostname. */
623 # define NI_NUMERICSERV 2 /* Don't convert port number to name. */
624 # define NI_NOFQDN 4 /* Only return nodename portion. */
625 # define NI_NAMEREQD 8 /* Don't return numeric addresses. */
626 # define NI_DGRAM 16 /* Look up UDP service rather than TCP. */
628 # define NI_IDN 32 /* Convert name from IDN format. */
629 # define NI_IDN_ALLOW_UNASSIGNED 64 /* Don't reject unassigned Unicode
631 # define NI_IDN_USE_STD3_ASCII_RULES 128 /* Validate strings according to
635 /* Translate name of a service location and/or a service name to set of
638 This function is a possible cancellation point and therefore not
639 marked with __THROW. */
640 extern int getaddrinfo (__const char *__restrict __name,
641 __const char *__restrict __service,
642 __const struct addrinfo *__restrict __req,
643 struct addrinfo **__restrict __pai);
645 /* Free `addrinfo' structure AI including associated storage. */
646 extern void freeaddrinfo (struct addrinfo *__ai) __THROW;
648 /* Convert error return from getaddrinfo() to a string. */
649 extern __const char *gai_strerror (int __ecode) __THROW;
651 /* Translate a socket address to a location and service name.
653 This function is a possible cancellation point and therefore not
654 marked with __THROW. */
655 extern int getnameinfo (__const struct sockaddr *__restrict __sa,
656 socklen_t __salen, char *__restrict __host,
657 socklen_t __hostlen, char *__restrict __serv,
658 socklen_t __servlen, unsigned int __flags);