1 /* Copyright (C) 1996-2002, 2003 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 #define h_errno (*__h_errno_location ())
60 /* Function to get address of global `h_errno' variable. */
61 extern int *__h_errno_location (void) __THROW
__attribute__ ((__const__
));
64 /* Possible values left in `h_errno'. */
65 #define NETDB_INTERNAL -1 /* See errno. */
66 #define NETDB_SUCCESS 0 /* No problem. */
67 #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found. */
68 #define TRY_AGAIN 2 /* Non-Authoritative Host not found,
70 #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED,
72 #define NO_DATA 4 /* Valid name, no data record of requested
74 #define NO_ADDRESS NO_DATA /* No address, look for MX record. */
77 /* Highest reserved Internet port number. */
78 # define IPPORT_RESERVED 1024
82 /* Scope delimiter for getaddrinfo(), getnameinfo(). */
83 # define SCOPE_DELIMITER '%'
86 /* Print error indicated by `h_errno' variable on standard error. STR
87 if non-null is printed before the error string. */
88 extern void herror (__const
char *__str
) __THROW
;
90 /* Return string associated with error ERR_NUM. */
91 extern __const
char *hstrerror (int __err_num
) __THROW
;
95 /* Description of data base entry for a single host. */
98 char *h_name
; /* Official name of host. */
99 char **h_aliases
; /* Alias list. */
100 int h_addrtype
; /* Host address type. */
101 int h_length
; /* Length of address. */
102 char **h_addr_list
; /* List of addresses from name server. */
103 #define h_addr h_addr_list[0] /* Address, for backward compatibility. */
106 /* Open host data base files and mark them as staying open even after
107 a later search if STAY_OPEN is non-zero.
109 This function is a possible cancellation point and therefore not
110 marked with __THROW. */
111 extern void sethostent (int __stay_open
);
113 /* Close host data base files and clear `stay open' flag.
115 This function is a possible cancellation point and therefore not
116 marked with __THROW. */
117 extern void endhostent (void);
119 /* Get next entry from host data base file. Open data base if
122 This function is a possible cancellation point and therefore not
123 marked with __THROW. */
124 extern struct hostent
*gethostent (void);
126 /* Return entry from host data base which address match ADDR with
127 length LEN and type TYPE.
129 This function is a possible cancellation point and therefore not
130 marked with __THROW. */
131 extern struct hostent
*gethostbyaddr (__const
void *__addr
, __socklen_t __len
,
134 /* Return entry from host data base for host with NAME.
136 This function is a possible cancellation point and therefore not
137 marked with __THROW. */
138 extern struct hostent
*gethostbyname (__const
char *__name
);
141 /* Return entry from host data base for host with NAME. AF must be
142 set to the address type which is `AF_INET' for IPv4 or `AF_INET6'
145 This function is not part of POSIX and therefore no official
146 cancellation point. But due to similarity with an POSIX interface
147 or due to the implementation it is a cancellation point and
148 therefore not marked with __THROW. */
149 extern struct hostent
*gethostbyname2 (__const
char *__name
, int __af
);
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.
157 These functions are not part of POSIX and therefore no official
158 cancellation point. But due to similarity with an POSIX interface
159 or due to the implementation they are cancellation points and
160 therefore not marked with __THROW. */
161 extern int gethostent_r (struct hostent
*__restrict __result_buf
,
162 char *__restrict __buf
, size_t __buflen
,
163 struct hostent
**__restrict __result
,
164 int *__restrict __h_errnop
);
166 extern int gethostbyaddr_r (__const
void *__restrict __addr
, __socklen_t __len
,
168 struct hostent
*__restrict __result_buf
,
169 char *__restrict __buf
, size_t __buflen
,
170 struct hostent
**__restrict __result
,
171 int *__restrict __h_errnop
);
173 extern int gethostbyname_r (__const
char *__restrict __name
,
174 struct hostent
*__restrict __result_buf
,
175 char *__restrict __buf
, size_t __buflen
,
176 struct hostent
**__restrict __result
,
177 int *__restrict __h_errnop
);
179 extern int gethostbyname2_r (__const
char *__restrict __name
, int __af
,
180 struct hostent
*__restrict __result_buf
,
181 char *__restrict __buf
, size_t __buflen
,
182 struct hostent
**__restrict __result
,
183 int *__restrict __h_errnop
);
187 /* Open network data base files and mark them as staying open even
188 after a later search if STAY_OPEN is non-zero.
190 This function is a possible cancellation point and therefore not
191 marked with __THROW. */
192 extern void setnetent (int __stay_open
);
194 /* Close network data base files and clear `stay open' flag.
196 This function is a possible cancellation point and therefore not
197 marked with __THROW. */
198 extern void endnetent (void);
200 /* Get next entry from network data base file. Open data base if
203 This function is a possible cancellation point and therefore not
204 marked with __THROW. */
205 extern struct netent
*getnetent (void);
207 /* Return entry from network data base which address match NET and
210 This function is a possible cancellation point and therefore not
211 marked with __THROW. */
212 extern struct netent
*getnetbyaddr (uint32_t __net
, int __type
);
214 /* Return entry from network data base for network with NAME.
216 This function is a possible cancellation point and therefore not
217 marked with __THROW. */
218 extern struct netent
*getnetbyname (__const
char *__name
);
221 /* Reentrant versions of the functions above. The additional
222 arguments specify a buffer of BUFLEN starting at BUF. The last
223 argument is a pointer to a variable which gets the value which
224 would be stored in the global variable `herrno' by the
225 non-reentrant functions.
227 These functions are not part of POSIX and therefore no official
228 cancellation point. But due to similarity with an POSIX interface
229 or due to the implementation they are cancellation points and
230 therefore not marked with __THROW. */
231 extern int getnetent_r (struct netent
*__restrict __result_buf
,
232 char *__restrict __buf
, size_t __buflen
,
233 struct netent
**__restrict __result
,
234 int *__restrict __h_errnop
);
236 extern int getnetbyaddr_r (uint32_t __net
, int __type
,
237 struct netent
*__restrict __result_buf
,
238 char *__restrict __buf
, size_t __buflen
,
239 struct netent
**__restrict __result
,
240 int *__restrict __h_errnop
);
242 extern int getnetbyname_r (__const
char *__restrict __name
,
243 struct netent
*__restrict __result_buf
,
244 char *__restrict __buf
, size_t __buflen
,
245 struct netent
**__restrict __result
,
246 int *__restrict __h_errnop
);
250 /* Description of data base entry for a single service. */
253 char *s_name
; /* Official service name. */
254 char **s_aliases
; /* Alias list. */
255 int s_port
; /* Port number. */
256 char *s_proto
; /* Protocol to use. */
259 /* Open service data base files and mark them as staying open even
260 after a later search if STAY_OPEN is non-zero.
262 This function is a possible cancellation point and therefore not
263 marked with __THROW. */
264 extern void setservent (int __stay_open
);
266 /* Close service data base files and clear `stay open' flag.
268 This function is a possible cancellation point and therefore not
269 marked with __THROW. */
270 extern void endservent (void);
272 /* Get next entry from service data base file. Open data base if
275 This function is a possible cancellation point and therefore not
276 marked with __THROW. */
277 extern struct servent
*getservent (void);
279 /* Return entry from network data base for network with NAME and
282 This function is a possible cancellation point and therefore not
283 marked with __THROW. */
284 extern struct servent
*getservbyname (__const
char *__name
,
285 __const
char *__proto
);
287 /* Return entry from service data base which matches port PORT and
290 This function is a possible cancellation point and therefore not
291 marked with __THROW. */
292 extern struct servent
*getservbyport (int __port
, __const
char *__proto
);
296 /* Reentrant versions of the functions above. The additional
297 arguments specify a buffer of BUFLEN starting at BUF.
299 These functions are not part of POSIX and therefore no official
300 cancellation point. But due to similarity with an POSIX interface
301 or due to the implementation they are cancellation points and
302 therefore not marked with __THROW. */
303 extern int getservent_r (struct servent
*__restrict __result_buf
,
304 char *__restrict __buf
, size_t __buflen
,
305 struct servent
**__restrict __result
);
307 extern int getservbyname_r (__const
char *__restrict __name
,
308 __const
char *__restrict __proto
,
309 struct servent
*__restrict __result_buf
,
310 char *__restrict __buf
, size_t __buflen
,
311 struct servent
**__restrict __result
);
313 extern int getservbyport_r (int __port
, __const
char *__restrict __proto
,
314 struct servent
*__restrict __result_buf
,
315 char *__restrict __buf
, size_t __buflen
,
316 struct servent
**__restrict __result
);
320 /* Description of data base entry for a single service. */
323 char *p_name
; /* Official protocol name. */
324 char **p_aliases
; /* Alias list. */
325 int p_proto
; /* Protocol number. */
328 /* Open protocol data base files and mark them as staying open even
329 after a later search if STAY_OPEN is non-zero.
331 This function is a possible cancellation point and therefore not
332 marked with __THROW. */
333 extern void setprotoent (int __stay_open
);
335 /* Close protocol data base files and clear `stay open' flag.
337 This function is a possible cancellation point and therefore not
338 marked with __THROW. */
339 extern void endprotoent (void);
341 /* Get next entry from protocol data base file. Open data base if
344 This function is a possible cancellation point and therefore not
345 marked with __THROW. */
346 extern struct protoent
*getprotoent (void);
348 /* Return entry from protocol data base for network with NAME.
350 This function is a possible cancellation point and therefore not
351 marked with __THROW. */
352 extern struct protoent
*getprotobyname (__const
char *__name
);
354 /* Return entry from protocol data base which number is PROTO.
356 This function is a possible cancellation point and therefore not
357 marked with __THROW. */
358 extern struct protoent
*getprotobynumber (int __proto
);
362 /* Reentrant versions of the functions above. The additional
363 arguments specify a buffer of BUFLEN starting at BUF.
365 These functions are not part of POSIX and therefore no official
366 cancellation point. But due to similarity with an POSIX interface
367 or due to the implementation they are cancellation points and
368 therefore not marked with __THROW. */
369 extern int getprotoent_r (struct protoent
*__restrict __result_buf
,
370 char *__restrict __buf
, size_t __buflen
,
371 struct protoent
**__restrict __result
);
373 extern int getprotobyname_r (__const
char *__restrict __name
,
374 struct protoent
*__restrict __result_buf
,
375 char *__restrict __buf
, size_t __buflen
,
376 struct protoent
**__restrict __result
);
378 extern int getprotobynumber_r (int __proto
,
379 struct protoent
*__restrict __result_buf
,
380 char *__restrict __buf
, size_t __buflen
,
381 struct protoent
**__restrict __result
);
384 /* Establish network group NETGROUP for enumeration.
386 This function is not part of POSIX and therefore no official
387 cancellation point. But due to similarity with an POSIX interface
388 or due to the implementation it is a cancellation point and
389 therefore not marked with __THROW. */
390 extern int setnetgrent (__const
char *__netgroup
);
392 /* Free all space allocated by previous `setnetgrent' call.
394 This function is not part of POSIX and therefore no official
395 cancellation point. But due to similarity with an POSIX interface
396 or due to the implementation it is a cancellation point and
397 therefore not marked with __THROW. */
398 extern void endnetgrent (void);
400 /* Get next member of netgroup established by last `setnetgrent' call
401 and return pointers to elements in HOSTP, USERP, and DOMAINP.
403 This function is not part of POSIX and therefore no official
404 cancellation point. But due to similarity with an POSIX interface
405 or due to the implementation it is a cancellation point and
406 therefore not marked with __THROW. */
407 extern int getnetgrent (char **__restrict __hostp
,
408 char **__restrict __userp
,
409 char **__restrict __domainp
);
412 /* Test whether NETGROUP contains the triple (HOST,USER,DOMAIN).
414 This function is not part of POSIX and therefore no official
415 cancellation point. But due to similarity with an POSIX interface
416 or due to the implementation it is a cancellation point and
417 therefore not marked with __THROW. */
418 extern int innetgr (__const
char *__netgroup
, __const
char *__host
,
419 __const
char *__user
, __const
char *domain
);
421 /* Reentrant version of `getnetgrent' where result is placed in BUFFER.
423 This function is not part of POSIX and therefore no official
424 cancellation point. But due to similarity with an POSIX interface
425 or due to the implementation it is a cancellation point and
426 therefore not marked with __THROW. */
427 extern int getnetgrent_r (char **__restrict __hostp
,
428 char **__restrict __userp
,
429 char **__restrict __domainp
,
430 char *__restrict __buffer
, size_t __buflen
);
435 /* Call `rshd' at port RPORT on remote machine *AHOST to execute CMD.
436 The local user is LOCUSER, on the remote machine the command is
437 executed as REMUSER. In *FD2P the descriptor to the socket for the
438 connection is returned. The caller must have the right to use a
439 reserved port. When the function returns *AHOST contains the
442 This function is not part of POSIX and therefore no official
443 cancellation point. But due to similarity with an POSIX interface
444 or due to the implementation it is a cancellation point and
445 therefore not marked with __THROW. */
446 extern int rcmd (char **__restrict __ahost
, unsigned short int __rport
,
447 __const
char *__restrict __locuser
,
448 __const
char *__restrict __remuser
,
449 __const
char *__restrict __cmd
, int *__restrict __fd2p
);
451 /* This is the equivalent function where the protocol can be selected
452 and which therefore can be used for IPv6.
454 This function is not part of POSIX and therefore no official
455 cancellation point. But due to similarity with an POSIX interface
456 or due to the implementation it is a cancellation point and
457 therefore not marked with __THROW. */
458 extern int rcmd_af (char **__restrict __ahost
, unsigned short int __rport
,
459 __const
char *__restrict __locuser
,
460 __const
char *__restrict __remuser
,
461 __const
char *__restrict __cmd
, int *__restrict __fd2p
,
464 /* Call `rexecd' at port RPORT on remote machine *AHOST to execute
465 CMD. The process runs at the remote machine using the ID of user
466 NAME whose cleartext password is PASSWD. In *FD2P the descriptor
467 to the socket for the connection is returned. When the function
468 returns *AHOST contains the official host name.
470 This function is not part of POSIX and therefore no official
471 cancellation point. But due to similarity with an POSIX interface
472 or due to the implementation it is a cancellation point and
473 therefore not marked with __THROW. */
474 extern int rexec (char **__restrict __ahost
, int __rport
,
475 __const
char *__restrict __name
,
476 __const
char *__restrict __pass
,
477 __const
char *__restrict __cmd
, int *__restrict __fd2p
);
479 /* This is the equivalent function where the protocol can be selected
480 and which therefore can be used for IPv6.
482 This function is not part of POSIX and therefore no official
483 cancellation point. But due to similarity with an POSIX interface
484 or due to the implementation it is a cancellation point and
485 therefore not marked with __THROW. */
486 extern int rexec_af (char **__restrict __ahost
, int __rport
,
487 __const
char *__restrict __name
,
488 __const
char *__restrict __pass
,
489 __const
char *__restrict __cmd
, int *__restrict __fd2p
,
492 /* Check whether user REMUSER on system RHOST is allowed to login as LOCUSER.
493 If SUSER is not zero the user tries to become superuser. Return 0 if
496 This function is not part of POSIX and therefore no official
497 cancellation point. But due to similarity with an POSIX interface
498 or due to the implementation it is a cancellation point and
499 therefore not marked with __THROW. */
500 extern int ruserok (__const
char *__rhost
, int __suser
,
501 __const
char *__remuser
, __const
char *__locuser
);
503 /* This is the equivalent function where the protocol can be selected
504 and which therefore can be used for IPv6.
506 This function is not part of POSIX and therefore no official
507 cancellation point. But due to similarity with an POSIX interface
508 or due to the implementation it is a cancellation point and
509 therefore not marked with __THROW. */
510 extern int ruserok_af (__const
char *__rhost
, int __suser
,
511 __const
char *__remuser
, __const
char *__locuser
,
514 /* Try to allocate reserved port, returning a descriptor for a socket opened
515 at this port or -1 if unsuccessful. The search for an available port
516 will start at ALPORT and continues with lower numbers.
518 This function is not part of POSIX and therefore no official
519 cancellation point. But due to similarity with an POSIX interface
520 or due to the implementation it is a cancellation point and
521 therefore not marked with __THROW. */
522 extern int rresvport (int *__alport
);
524 /* This is the equivalent function where the protocol can be selected
525 and which therefore can be used for IPv6.
527 This function is not part of POSIX and therefore no official
528 cancellation point. But due to similarity with an POSIX interface
529 or due to the implementation it is a cancellation point and
530 therefore not marked with __THROW. */
531 extern int rresvport_af (int *__alport
, sa_family_t __af
);
535 /* Extension from POSIX.1g. */
537 /* Structure to contain information about address of a service provider. */
540 int ai_flags
; /* Input flags. */
541 int ai_family
; /* Protocol family for socket. */
542 int ai_socktype
; /* Socket type. */
543 int ai_protocol
; /* Protocol for socket. */
544 socklen_t ai_addrlen
; /* Length of socket address. */
545 struct sockaddr
*ai_addr
; /* Socket address for socket. */
546 char *ai_canonname
; /* Canonical name for service location. */
547 struct addrinfo
*ai_next
; /* Pointer to next in list. */
551 /* Structure used as control block for asynchronous lookup. */
554 const char *ar_name
; /* Name to look up. */
555 const char *ar_service
; /* Service name. */
556 const struct addrinfo
*ar_request
; /* Additional request specification. */
557 struct addrinfo
*ar_result
; /* Pointer to result. */
558 /* The following are internal elements. */
565 # define GAI_NOWAIT 1
568 /* Possible values for `ai_flags' field in `addrinfo' structure. */
569 # define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */
570 # define AI_CANONNAME 0x0002 /* Request for canonical name. */
571 # define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */
573 /* Error values for `getaddrinfo' function. */
574 # define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */
575 # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
576 # define EAI_AGAIN -3 /* Temporary failure in name resolution. */
577 # define EAI_FAIL -4 /* Non-recoverable failure in name res. */
578 # define EAI_NODATA -5 /* No address associated with NAME. */
579 # define EAI_FAMILY -6 /* `ai_family' not supported. */
580 # define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */
581 # define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
582 # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
583 # define EAI_MEMORY -10 /* Memory allocation failure. */
584 # define EAI_SYSTEM -11 /* System error returned in `errno'. */
586 # define EAI_INPROGRESS -100 /* Processing request in progress. */
587 # define EAI_CANCELED -101 /* Request canceled. */
588 # define EAI_NOTCANCELED -102 /* Request not canceled. */
589 # define EAI_ALLDONE -103 /* All requests done. */
590 # define EAI_INTR -104 /* Interrupted by a signal. */
593 # define NI_MAXHOST 1025
594 # define NI_MAXSERV 32
596 # define NI_NUMERICHOST 1 /* Don't try to look up hostname. */
597 # define NI_NUMERICSERV 2 /* Don't convert port number to name. */
598 # define NI_NOFQDN 4 /* Only return nodename portion. */
599 # define NI_NAMEREQD 8 /* Don't return numeric addresses. */
600 # define NI_DGRAM 16 /* Look up UDP service rather than TCP. */
602 /* Translate name of a service location and/or a service name to set of
605 This function is a possible cancellation point and therefore not
606 marked with __THROW. */
607 extern int getaddrinfo (__const
char *__restrict __name
,
608 __const
char *__restrict __service
,
609 __const
struct addrinfo
*__restrict __req
,
610 struct addrinfo
**__restrict __pai
);
612 /* Free `addrinfo' structure AI including associated storage. */
613 extern void freeaddrinfo (struct addrinfo
*__ai
) __THROW
;
615 /* Convert error return from getaddrinfo() to a string. */
616 extern __const
char *gai_strerror (int __ecode
) __THROW
;
618 /* Translate a socket address to a location and service name.
620 This function is a possible cancellation point and therefore not
621 marked with __THROW. */
622 extern int getnameinfo (__const
struct sockaddr
*__restrict __sa
,
623 socklen_t __salen
, char *__restrict __host
,
624 socklen_t __hostlen
, char *__restrict __serv
,
625 socklen_t __servlen
, unsigned int __flags
);
629 /* Enqueue ENT requests from the LIST. If MODE is GAI_WAIT wait until all
630 requests are handled. If WAIT is GAI_NOWAIT return immediately after
631 queueing the requests and signal completion according to SIG.
633 This function is not part of POSIX and therefore no official
634 cancellation point. But due to similarity with an POSIX interface
635 or due to the implementation it is a cancellation point and
636 therefore not marked with __THROW. */
637 extern int getaddrinfo_a (int __mode
, struct gaicb
*__list
[__restrict_arr
],
638 int __ent
, struct sigevent
*__restrict __sig
);
640 /* Suspend execution of the thread until at least one of the ENT requests
641 in LIST is handled. If TIMEOUT is not a null pointer it specifies the
642 longest time the function keeps waiting before returning with an error.
644 This function is not part of POSIX and therefore no official
645 cancellation point. But due to similarity with an POSIX interface
646 or due to the implementation it is a cancellation point and
647 therefore not marked with __THROW. */
648 extern int gai_suspend (__const
struct gaicb
*__const __list
[], int __ent
,
649 __const
struct timespec
*__timeout
);
651 /* Get the error status of the request REQ. */
652 extern int gai_error (struct gaicb
*__req
) __THROW
;
654 /* Cancel the requests associated with GAICBP. */
655 extern int gai_cancel (struct gaicb
*__gaicbp
) __THROW
;