netdb.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. /* Copyright (C) 1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. /* All data returned by the network data base library are supplied in
  16. host order and returned in network order (suitable for use in
  17. system calls). */
  18. #ifndef _NETDB_H
  19. #define _NETDB_H 1
  20. #include <features.h>
  21. #include <netinet/in.h>
  22. #include <stdint.h>
  23. #ifdef __USE_MISC
  24. /* This is necessary to make this include file properly replace the
  25. Sun version. */
  26. # include <rpc/netdb.h>
  27. #endif
  28. #ifdef __USE_GNU
  29. # define __need_sigevent_t
  30. # include <bits/siginfo.h>
  31. # define __need_timespec
  32. # include <time.h>
  33. #endif
  34. #include <bits/netdb.h>
  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"
  42. __BEGIN_DECLS
  43. /* Error status for non-reentrant lookup functions.
  44. * NOTE: uClibc reuses errno for h_errno. */
  45. #include <errno.h>
  46. #define h_errno errno
  47. #if 0
  48. /* Function to get address of global `h_errno' variable. */
  49. extern int *__h_errno_location (void) __THROW __attribute__ ((__const__));
  50. #ifdef _LIBC
  51. # ifdef _LIBC_REENTRANT
  52. static inline int
  53. __set_h_errno (int __err)
  54. {
  55. return *__h_errno_location () = __err;
  56. }
  57. # else
  58. # define __set_h_errno(x) (h_errno = (x))
  59. # endif /* _LIBC_REENTRANT */
  60. #endif /* _LIBC */
  61. #if !defined _LIBC || defined _LIBC_REENTRANT
  62. /* Use a macro to access always the thread specific `h_errno' variable. */
  63. # define h_errno (*__h_errno_location ())
  64. #endif
  65. #endif
  66. /* Possible values left in `h_errno'. */
  67. #define NETDB_INTERNAL -1 /* See errno. */
  68. #define NETDB_SUCCESS 0 /* No problem. */
  69. #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found. */
  70. #define TRY_AGAIN 2 /* Non-Authoritative Host not found,
  71. or SERVERFAIL. */
  72. #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED,
  73. NOTIMP. */
  74. #define NO_DATA 4 /* Valid name, no data record of requested
  75. type. */
  76. #define NO_ADDRESS NO_DATA /* No address, look for MX record. */
  77. #ifdef __USE_XOPEN2K
  78. /* Highest reserved Internet port number. */
  79. # define IPPORT_RESERVED 1024
  80. #endif
  81. #ifdef __USE_GNU
  82. /* Scope delimiter for getaddrinfo(), getnameinfo(). */
  83. # define SCOPE_DELIMITER '%'
  84. #endif
  85. /* Print error indicated by `h_errno' variable on standard error. STR
  86. if non-null is printed before the error string. */
  87. extern void herror (__const char *__str) __THROW;
  88. /* Return string associated with error ERR_NUM. */
  89. extern __const char *hstrerror (int __err_num) __THROW;
  90. /* Description of data base entry for a single host. */
  91. struct hostent
  92. {
  93. char *h_name; /* Official name of host. */
  94. char **h_aliases; /* Alias list. */
  95. int h_addrtype; /* Host address type. */
  96. int h_length; /* Length of address. */
  97. char **h_addr_list; /* List of addresses from name server. */
  98. #define h_addr h_addr_list[0] /* Address, for backward compatibility. */
  99. };
  100. /* Open host data base files and mark them as staying open even after
  101. a later search if STAY_OPEN is non-zero. */
  102. extern void sethostent (int __stay_open) __THROW;
  103. /* Close host data base files and clear `stay open' flag. */
  104. extern void endhostent (void) __THROW;
  105. /* Get next entry from host data base file. Open data base if
  106. necessary. */
  107. extern struct hostent *gethostent (void) __THROW;
  108. /* Return entry from host data base which address match ADDR with
  109. length LEN and type TYPE. */
  110. extern struct hostent *gethostbyaddr (__const void *__addr, __socklen_t __len,
  111. int __type) __THROW;
  112. /* Return entry from host data base for host with NAME. */
  113. extern struct hostent *gethostbyname (__const char *__name) __THROW;
  114. #ifdef __USE_MISC
  115. /* Return entry from host data base for host with NAME. AF must be
  116. set to the address type which is `AF_INET' for IPv4 or `AF_INET6'
  117. for IPv6. */
  118. extern struct hostent *gethostbyname2 (__const char *__name, int __af) __THROW;
  119. /* Reentrant versions of the functions above. The additional
  120. arguments specify a buffer of BUFLEN starting at BUF. The last
  121. argument is a pointer to a variable which gets the value which
  122. would be stored in the global variable `herrno' by the
  123. non-reentrant functions. */
  124. extern int gethostent_r (struct hostent *__restrict __result_buf,
  125. char *__restrict __buf, size_t __buflen,
  126. struct hostent **__restrict __result,
  127. int *__restrict __h_errnop) __THROW;
  128. extern int gethostbyaddr_r (__const void *__restrict __addr, __socklen_t __len,
  129. int __type,
  130. struct hostent *__restrict __result_buf,
  131. char *__restrict __buf, size_t __buflen,
  132. struct hostent **__restrict __result,
  133. int *__restrict __h_errnop) __THROW;
  134. extern int gethostbyname_r (__const char *__restrict __name,
  135. struct hostent *__restrict __result_buf,
  136. char *__restrict __buf, size_t __buflen,
  137. struct hostent **__restrict __result,
  138. int *__restrict __h_errnop) __THROW;
  139. extern int gethostbyname2_r (__const char *__restrict __name, int __af,
  140. struct hostent *__restrict __result_buf,
  141. char *__restrict __buf, size_t __buflen,
  142. struct hostent **__restrict __result,
  143. int *__restrict __h_errnop) __THROW;
  144. #endif /* misc */
  145. /* Open network data base files and mark them as staying open even
  146. after a later search if STAY_OPEN is non-zero. */
  147. extern void setnetent (int __stay_open) __THROW;
  148. /* Close network data base files and clear `stay open' flag. */
  149. extern void endnetent (void) __THROW;
  150. /* Get next entry from network data base file. Open data base if
  151. necessary. */
  152. extern struct netent *getnetent (void) __THROW;
  153. /* Return entry from network data base which address match NET and
  154. type TYPE. */
  155. extern struct netent *getnetbyaddr (uint32_t __net, int __type)
  156. __THROW;
  157. /* Return entry from network data base for network with NAME. */
  158. extern struct netent *getnetbyname (__const char *__name) __THROW;
  159. #ifdef __USE_MISC
  160. /* Reentrant versions of the functions above. The additional
  161. arguments specify a buffer of BUFLEN starting at BUF. The last
  162. argument is a pointer to a variable which gets the value which
  163. would be stored in the global variable `herrno' by the
  164. non-reentrant functions. */
  165. extern int getnetent_r (struct netent *__restrict __result_buf,
  166. char *__restrict __buf, size_t __buflen,
  167. struct netent **__restrict __result,
  168. int *__restrict __h_errnop) __THROW;
  169. extern int getnetbyaddr_r (uint32_t __net, int __type,
  170. struct netent *__restrict __result_buf,
  171. char *__restrict __buf, size_t __buflen,
  172. struct netent **__restrict __result,
  173. int *__restrict __h_errnop) __THROW;
  174. extern int getnetbyname_r (__const char *__restrict __name,
  175. struct netent *__restrict __result_buf,
  176. char *__restrict __buf, size_t __buflen,
  177. struct netent **__restrict __result,
  178. int *__restrict __h_errnop) __THROW;
  179. #endif /* misc */
  180. /* Description of data base entry for a single service. */
  181. struct servent
  182. {
  183. char *s_name; /* Official service name. */
  184. char **s_aliases; /* Alias list. */
  185. int s_port; /* Port number. */
  186. char *s_proto; /* Protocol to use. */
  187. };
  188. /* Open service data base files and mark them as staying open even
  189. after a later search if STAY_OPEN is non-zero. */
  190. extern void setservent (int __stay_open) __THROW;
  191. /* Close service data base files and clear `stay open' flag. */
  192. extern void endservent (void) __THROW;
  193. /* Get next entry from service data base file. Open data base if
  194. necessary. */
  195. extern struct servent *getservent (void) __THROW;
  196. /* Return entry from network data base for network with NAME and
  197. protocol PROTO. */
  198. extern struct servent *getservbyname (__const char *__name,
  199. __const char *__proto) __THROW;
  200. /* Return entry from service data base which matches port PORT and
  201. protocol PROTO. */
  202. extern struct servent *getservbyport (int __port, __const char *__proto)
  203. __THROW;
  204. #ifdef __USE_MISC
  205. /* Reentrant versions of the functions above. The additional
  206. arguments specify a buffer of BUFLEN starting at BUF. */
  207. extern int getservent_r (struct servent *__restrict __result_buf,
  208. char *__restrict __buf, size_t __buflen,
  209. struct servent **__restrict __result) __THROW;
  210. extern int getservbyname_r (__const char *__restrict __name,
  211. __const char *__restrict __proto,
  212. struct servent *__restrict __result_buf,
  213. char *__restrict __buf, size_t __buflen,
  214. struct servent **__restrict __result) __THROW;
  215. extern int getservbyport_r (int __port, __const char *__restrict __proto,
  216. struct servent *__restrict __result_buf,
  217. char *__restrict __buf, size_t __buflen,
  218. struct servent **__restrict __result) __THROW;
  219. #endif /* misc */
  220. /* Description of data base entry for a single service. */
  221. struct protoent
  222. {
  223. char *p_name; /* Official protocol name. */
  224. char **p_aliases; /* Alias list. */
  225. int p_proto; /* Protocol number. */
  226. };
  227. /* Open protocol data base files and mark them as staying open even
  228. after a later search if STAY_OPEN is non-zero. */
  229. extern void setprotoent (int __stay_open) __THROW;
  230. /* Close protocol data base files and clear `stay open' flag. */
  231. extern void endprotoent (void) __THROW;
  232. /* Get next entry from protocol data base file. Open data base if
  233. necessary. */
  234. extern struct protoent *getprotoent (void) __THROW;
  235. /* Return entry from protocol data base for network with NAME. */
  236. extern struct protoent *getprotobyname (__const char *__name) __THROW;
  237. /* Return entry from protocol data base which number is PROTO. */
  238. extern struct protoent *getprotobynumber (int __proto) __THROW;
  239. #ifdef __USE_MISC
  240. /* Reentrant versions of the functions above. The additional
  241. arguments specify a buffer of BUFLEN starting at BUF. */
  242. extern int getprotoent_r (struct protoent *__restrict __result_buf,
  243. char *__restrict __buf, size_t __buflen,
  244. struct protoent **__restrict __result) __THROW;
  245. extern int getprotobyname_r (__const char *__restrict __name,
  246. struct protoent *__restrict __result_buf,
  247. char *__restrict __buf, size_t __buflen,
  248. struct protoent **__restrict __result) __THROW;
  249. extern int getprotobynumber_r (int __proto,
  250. struct protoent *__restrict __result_buf,
  251. char *__restrict __buf, size_t __buflen,
  252. struct protoent **__restrict __result) __THROW;
  253. #endif /* misc */
  254. /* Establish network group NETGROUP for enumeration. */
  255. extern int setnetgrent (__const char *__netgroup) __THROW;
  256. /* Free all space allocated by previous `setnetgrent' call. */
  257. extern void endnetgrent (void) __THROW;
  258. /* Get next member of netgroup established by last `setnetgrent' call
  259. and return pointers to elements in HOSTP, USERP, and DOMAINP. */
  260. extern int getnetgrent (char **__restrict __hostp,
  261. char **__restrict __userp,
  262. char **__restrict __domainp) __THROW;
  263. #ifdef __USE_MISC
  264. /* Test whether NETGROUP contains the triple (HOST,USER,DOMAIN). */
  265. extern int innetgr (__const char *__netgroup, __const char *__host,
  266. __const char *__user, __const char *domain) __THROW;
  267. /* Reentrant version of `getnetgrent' where result is placed in BUFFER. */
  268. extern int getnetgrent_r (char **__restrict __hostp,
  269. char **__restrict __userp,
  270. char **__restrict __domainp,
  271. char *__restrict __buffer, size_t __buflen) __THROW;
  272. #endif /* misc */
  273. #ifdef __USE_BSD
  274. /* Call `rshd' at port RPORT on remote machine *AHOST to execute CMD.
  275. The local user is LOCUSER, on the remote machine the command is
  276. executed as REMUSER. In *FD2P the descriptor to the socket for the
  277. connection is returned. The caller must have the right to use a
  278. reserved port. When the function returns *AHOST contains the
  279. official host name. */
  280. extern int rcmd (char **__restrict __ahost, unsigned short int __rport,
  281. __const char *__restrict __locuser,
  282. __const char *__restrict __remuser,
  283. __const char *__restrict __cmd, int *__restrict __fd2p)
  284. __THROW;
  285. /* This is the equivalent function where the protocol can be selected
  286. and which therefore can be used for IPv6. */
  287. extern int rcmd_af (char **__restrict __ahost, unsigned short int __rport,
  288. __const char *__restrict __locuser,
  289. __const char *__restrict __remuser,
  290. __const char *__restrict __cmd, int *__restrict __fd2p,
  291. sa_family_t __af) __THROW;
  292. /* Call `rexecd' at port RPORT on remote machine *AHOST to execute
  293. CMD. The process runs at the remote machine using the ID of user
  294. NAME whose cleartext password is PASSWD. In *FD2P the descriptor
  295. to the socket for the connection is returned. When the function
  296. returns *AHOST contains the official host name. */
  297. extern int rexec (char **__restrict __ahost, int __rport,
  298. __const char *__restrict __name,
  299. __const char *__restrict __pass,
  300. __const char *__restrict __cmd, int *__restrict __fd2p)
  301. __THROW;
  302. /* This is the equivalent function where the protocol can be selected
  303. and which therefore can be used for IPv6. */
  304. extern int rexec_af (char **__restrict __ahost, int __rport,
  305. __const char *__restrict __name,
  306. __const char *__restrict __pass,
  307. __const char *__restrict __cmd, int *__restrict __fd2p,
  308. sa_family_t __af) __THROW;
  309. /* Check whether user REMUSER on system RHOST is allowed to login as LOCUSER.
  310. If SUSER is not zero the user tries to become superuser. Return 0 if
  311. it is possible. */
  312. extern int ruserok (__const char *__rhost, int __suser,
  313. __const char *__remuser, __const char *__locuser) __THROW;
  314. /* This is the equivalent function where the protocol can be selected
  315. and which therefore can be used for IPv6. */
  316. extern int ruserok_af (__const char *__rhost, int __suser,
  317. __const char *__remuser, __const char *__locuser,
  318. sa_family_t __af) __THROW;
  319. /* Try to allocate reserved port, returning a descriptor for a socket opened
  320. at this port or -1 if unsuccessful. The search for an available port
  321. will start at ALPORT and continues with lower numbers. */
  322. extern int rresvport (int *__alport) __THROW;
  323. /* This is the equivalent function where the protocol can be selected
  324. and which therefore can be used for IPv6. */
  325. extern int rresvport_af (int *__alport, sa_family_t __af) __THROW;
  326. #endif
  327. /* Extension from POSIX.1g. */
  328. #ifdef __USE_POSIX
  329. /* Structure to contain information about address of a service provider. */
  330. struct addrinfo
  331. {
  332. int ai_flags; /* Input flags. */
  333. int ai_family; /* Protocol family for socket. */
  334. int ai_socktype; /* Socket type. */
  335. int ai_protocol; /* Protocol for socket. */
  336. socklen_t ai_addrlen; /* Length of socket address. */
  337. struct sockaddr *ai_addr; /* Socket address for socket. */
  338. char *ai_canonname; /* Canonical name for service location. */
  339. struct addrinfo *ai_next; /* Pointer to next in list. */
  340. };
  341. # ifdef __USE_GNU
  342. /* Structure used as control block for asynchronous lookup. */
  343. struct gaicb
  344. {
  345. const char *ar_name; /* Name to look up. */
  346. const char *ar_service; /* Service name. */
  347. const struct addrinfo *ar_request; /* Additional request specification. */
  348. struct addrinfo *ar_result; /* Pointer to result. */
  349. /* The following are internal elements. */
  350. int __return;
  351. int __unused[5];
  352. };
  353. /* Lookup mode. */
  354. # define GAI_WAIT 0
  355. # define GAI_NOWAIT 1
  356. # endif
  357. /* Possible values for `ai_flags' field in `addrinfo' structure. */
  358. # define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */
  359. # define AI_CANONNAME 0x0002 /* Request for canonical name. */
  360. # define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */
  361. /* Error values for `getaddrinfo' function. */
  362. # define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */
  363. # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
  364. # define EAI_AGAIN -3 /* Temporary failure in name resolution. */
  365. # define EAI_FAIL -4 /* Non-recoverable failure in name res. */
  366. # define EAI_NODATA -5 /* No address associated with NAME. */
  367. # define EAI_FAMILY -6 /* `ai_family' not supported. */
  368. # define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */
  369. # define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
  370. # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
  371. # define EAI_MEMORY -10 /* Memory allocation failure. */
  372. # define EAI_SYSTEM -11 /* System error returned in `errno'. */
  373. # ifdef __USE_GNU
  374. # define EAI_INPROGRESS -100 /* Processing request in progress. */
  375. # define EAI_CANCELED -101 /* Request canceled. */
  376. # define EAI_NOTCANCELED -102 /* Request not canceled. */
  377. # define EAI_ALLDONE -103 /* All requests done. */
  378. # define EAI_INTR -104 /* Interrupted by a signal. */
  379. # endif
  380. # define NI_MAXHOST 1025
  381. # define NI_MAXSERV 32
  382. # define NI_NUMERICHOST 1 /* Don't try to look up hostname. */
  383. # define NI_NUMERICSERV 2 /* Don't convert port number to name. */
  384. # define NI_NOFQDN 4 /* Only return nodename portion. */
  385. # define NI_NAMEREQD 8 /* Don't return numeric addresses. */
  386. # define NI_DGRAM 16 /* Look up UDP service rather than TCP. */
  387. /* Translate name of a service location and/or a service name to set of
  388. socket addresses. */
  389. extern int getaddrinfo (__const char *__restrict __name,
  390. __const char *__restrict __service,
  391. __const struct addrinfo *__restrict __req,
  392. struct addrinfo **__restrict __pai) __THROW;
  393. /* Free `addrinfo' structure AI including associated storage. */
  394. extern void freeaddrinfo (struct addrinfo *__ai) __THROW;
  395. /* Convert error return from getaddrinfo() to a string. */
  396. extern __const char *gai_strerror (int __ecode) __THROW;
  397. /* Translate a socket address to a location and service name. */
  398. extern int getnameinfo (__const struct sockaddr *__restrict __sa,
  399. socklen_t __salen, char *__restrict __host,
  400. socklen_t __hostlen, char *__restrict __serv,
  401. socklen_t __servlen, unsigned int __flags) __THROW;
  402. # ifdef __USE_GNU
  403. /* Enqueue ENT requests from the LIST. If MODE is GAI_WAIT wait until all
  404. requests are handled. If WAIT is GAI_NOWAIT return immediately after
  405. queueing the requests and signal completion according to SIG. */
  406. extern int getaddrinfo_a (int __mode, struct gaicb *__list[__restrict_arr],
  407. int __ent, struct sigevent *__restrict __sig)
  408. __THROW;
  409. /* Suspend execution of the thread until at least one of the ENT requests
  410. in LIST is handled. If TIMEOUT is not a null pointer it specifies the
  411. longest time the function keeps waiting before returning with an error. */
  412. extern int gai_suspend (__const struct gaicb *__const __list[], int __ent,
  413. __const struct timespec *__timeout) __THROW;
  414. /* Get the error status of the request REQ. */
  415. extern int gai_error (struct gaicb *__req) __THROW;
  416. /* Cancel the requests associated with GAICBP. */
  417. extern int gai_cancel (struct gaicb *__gaicbp) __THROW;
  418. # endif /* GNU */
  419. #endif /* POSIX */
  420. __END_DECLS
  421. #endif /* netdb.h */