netdb.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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. extern int h_errno;
  45. /* Function to get address of global `h_errno' variable. */
  46. extern int *__h_errno_location (void) __THROW __attribute__ ((__const__));
  47. #ifdef _LIBC
  48. # define __set_h_errno(x) (h_errno = (x))
  49. #endif
  50. #if defined __UCLIBC_HAS_THREADS__
  51. /* Use a macro to access always the thread specific `h_errno' variable. */
  52. # define h_errno (*__h_errno_location ())
  53. #endif
  54. /* Possible values left in `h_errno'. */
  55. #define NETDB_INTERNAL -1 /* See errno. */
  56. #define NETDB_SUCCESS 0 /* No problem. */
  57. #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found. */
  58. #define TRY_AGAIN 2 /* Non-Authoritative Host not found,
  59. or SERVERFAIL. */
  60. #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED,
  61. NOTIMP. */
  62. #define NO_DATA 4 /* Valid name, no data record of requested
  63. type. */
  64. #define NO_ADDRESS NO_DATA /* No address, look for MX record. */
  65. #ifdef __USE_XOPEN2K
  66. /* Highest reserved Internet port number. */
  67. # define IPPORT_RESERVED 1024
  68. #endif
  69. #ifdef __USE_GNU
  70. /* Scope delimiter for getaddrinfo(), getnameinfo(). */
  71. # define SCOPE_DELIMITER '%'
  72. #endif
  73. /* Print error indicated by `h_errno' variable on standard error. STR
  74. if non-null is printed before the error string. */
  75. extern void herror (__const char *__str) __THROW;
  76. /* Return string associated with error ERR_NUM. */
  77. extern __const char *hstrerror (int __err_num) __THROW;
  78. /* Description of data base entry for a single host. */
  79. struct hostent
  80. {
  81. char *h_name; /* Official name of host. */
  82. char **h_aliases; /* Alias list. */
  83. int h_addrtype; /* Host address type. */
  84. int h_length; /* Length of address. */
  85. char **h_addr_list; /* List of addresses from name server. */
  86. #define h_addr h_addr_list[0] /* Address, for backward compatibility. */
  87. };
  88. /* Open host data base files and mark them as staying open even after
  89. a later search if STAY_OPEN is non-zero. */
  90. extern void sethostent (int __stay_open) __THROW;
  91. /* Close host data base files and clear `stay open' flag. */
  92. extern void endhostent (void) __THROW;
  93. /* Get next entry from host data base file. Open data base if
  94. necessary. */
  95. extern struct hostent *gethostent (void) __THROW;
  96. /* Return entry from host data base which address match ADDR with
  97. length LEN and type TYPE. */
  98. extern struct hostent *gethostbyaddr (__const void *__addr, __socklen_t __len,
  99. int __type) __THROW;
  100. /* Return entry from host data base for host with NAME. */
  101. extern struct hostent *gethostbyname (__const char *__name) __THROW;
  102. #ifdef __USE_MISC
  103. /* Return entry from host data base for host with NAME. AF must be
  104. set to the address type which is `AF_INET' for IPv4 or `AF_INET6'
  105. for IPv6. */
  106. extern struct hostent *gethostbyname2 (__const char *__name, int __af) __THROW;
  107. /* Reentrant versions of the functions above. The additional
  108. arguments specify a buffer of BUFLEN starting at BUF. The last
  109. argument is a pointer to a variable which gets the value which
  110. would be stored in the global variable `herrno' by the
  111. non-reentrant functions. */
  112. extern int gethostent_r (struct hostent *__restrict __result_buf,
  113. char *__restrict __buf, size_t __buflen,
  114. struct hostent **__restrict __result,
  115. int *__restrict __h_errnop) __THROW;
  116. extern int gethostbyaddr_r (__const void *__restrict __addr, __socklen_t __len,
  117. int __type,
  118. struct hostent *__restrict __result_buf,
  119. char *__restrict __buf, size_t __buflen,
  120. struct hostent **__restrict __result,
  121. int *__restrict __h_errnop) __THROW;
  122. extern int gethostbyname_r (__const char *__restrict __name,
  123. struct hostent *__restrict __result_buf,
  124. char *__restrict __buf, size_t __buflen,
  125. struct hostent **__restrict __result,
  126. int *__restrict __h_errnop) __THROW;
  127. extern int gethostbyname2_r (__const char *__restrict __name, int __af,
  128. struct hostent *__restrict __result_buf,
  129. char *__restrict __buf, size_t __buflen,
  130. struct hostent **__restrict __result,
  131. int *__restrict __h_errnop) __THROW;
  132. #endif /* misc */
  133. /* Open network data base files and mark them as staying open even
  134. after a later search if STAY_OPEN is non-zero. */
  135. extern void setnetent (int __stay_open) __THROW;
  136. /* Close network data base files and clear `stay open' flag. */
  137. extern void endnetent (void) __THROW;
  138. /* Get next entry from network data base file. Open data base if
  139. necessary. */
  140. extern struct netent *getnetent (void) __THROW;
  141. /* Return entry from network data base which address match NET and
  142. type TYPE. */
  143. extern struct netent *getnetbyaddr (uint32_t __net, int __type)
  144. __THROW;
  145. /* Return entry from network data base for network with NAME. */
  146. extern struct netent *getnetbyname (__const char *__name) __THROW;
  147. #if 0
  148. /* FIXME */
  149. #ifdef __USE_MISC
  150. /* Reentrant versions of the functions above. The additional
  151. arguments specify a buffer of BUFLEN starting at BUF. The last
  152. argument is a pointer to a variable which gets the value which
  153. would be stored in the global variable `herrno' by the
  154. non-reentrant functions. */
  155. extern int getnetent_r (struct netent *__restrict __result_buf,
  156. char *__restrict __buf, size_t __buflen,
  157. struct netent **__restrict __result,
  158. int *__restrict __h_errnop) __THROW;
  159. extern int getnetbyaddr_r (uint32_t __net, int __type,
  160. struct netent *__restrict __result_buf,
  161. char *__restrict __buf, size_t __buflen,
  162. struct netent **__restrict __result,
  163. int *__restrict __h_errnop) __THROW;
  164. extern int getnetbyname_r (__const char *__restrict __name,
  165. struct netent *__restrict __result_buf,
  166. char *__restrict __buf, size_t __buflen,
  167. struct netent **__restrict __result,
  168. int *__restrict __h_errnop) __THROW;
  169. #endif /* misc */
  170. #endif
  171. /* Description of data base entry for a single service. */
  172. struct servent
  173. {
  174. char *s_name; /* Official service name. */
  175. char **s_aliases; /* Alias list. */
  176. int s_port; /* Port number. */
  177. char *s_proto; /* Protocol to use. */
  178. };
  179. /* Open service data base files and mark them as staying open even
  180. after a later search if STAY_OPEN is non-zero. */
  181. extern void setservent (int __stay_open) __THROW;
  182. /* Close service data base files and clear `stay open' flag. */
  183. extern void endservent (void) __THROW;
  184. /* Get next entry from service data base file. Open data base if
  185. necessary. */
  186. extern struct servent *getservent (void) __THROW;
  187. /* Return entry from network data base for network with NAME and
  188. protocol PROTO. */
  189. extern struct servent *getservbyname (__const char *__name,
  190. __const char *__proto) __THROW;
  191. /* Return entry from service data base which matches port PORT and
  192. protocol PROTO. */
  193. extern struct servent *getservbyport (int __port, __const char *__proto)
  194. __THROW;
  195. #ifdef __USE_MISC
  196. /* Reentrant versions of the functions above. The additional
  197. arguments specify a buffer of BUFLEN starting at BUF. */
  198. extern int getservent_r (struct servent *__restrict __result_buf,
  199. char *__restrict __buf, size_t __buflen,
  200. struct servent **__restrict __result) __THROW;
  201. extern int getservbyname_r (__const char *__restrict __name,
  202. __const char *__restrict __proto,
  203. struct servent *__restrict __result_buf,
  204. char *__restrict __buf, size_t __buflen,
  205. struct servent **__restrict __result) __THROW;
  206. extern int getservbyport_r (int __port, __const char *__restrict __proto,
  207. struct servent *__restrict __result_buf,
  208. char *__restrict __buf, size_t __buflen,
  209. struct servent **__restrict __result) __THROW;
  210. #endif /* misc */
  211. /* Description of data base entry for a single service. */
  212. struct protoent
  213. {
  214. char *p_name; /* Official protocol name. */
  215. char **p_aliases; /* Alias list. */
  216. int p_proto; /* Protocol number. */
  217. };
  218. /* Open protocol data base files and mark them as staying open even
  219. after a later search if STAY_OPEN is non-zero. */
  220. extern void setprotoent (int __stay_open) __THROW;
  221. /* Close protocol data base files and clear `stay open' flag. */
  222. extern void endprotoent (void) __THROW;
  223. /* Get next entry from protocol data base file. Open data base if
  224. necessary. */
  225. extern struct protoent *getprotoent (void) __THROW;
  226. /* Return entry from protocol data base for network with NAME. */
  227. extern struct protoent *getprotobyname (__const char *__name) __THROW;
  228. /* Return entry from protocol data base which number is PROTO. */
  229. extern struct protoent *getprotobynumber (int __proto) __THROW;
  230. #ifdef __USE_MISC
  231. /* Reentrant versions of the functions above. The additional
  232. arguments specify a buffer of BUFLEN starting at BUF. */
  233. extern int getprotoent_r (struct protoent *__restrict __result_buf,
  234. char *__restrict __buf, size_t __buflen,
  235. struct protoent **__restrict __result) __THROW;
  236. extern int getprotobyname_r (__const char *__restrict __name,
  237. struct protoent *__restrict __result_buf,
  238. char *__restrict __buf, size_t __buflen,
  239. struct protoent **__restrict __result) __THROW;
  240. extern int getprotobynumber_r (int __proto,
  241. struct protoent *__restrict __result_buf,
  242. char *__restrict __buf, size_t __buflen,
  243. struct protoent **__restrict __result) __THROW;
  244. #endif /* misc */
  245. #ifdef __USE_BSD
  246. /* Call `rshd' at port RPORT on remote machine *AHOST to execute CMD.
  247. The local user is LOCUSER, on the remote machine the command is
  248. executed as REMUSER. In *FD2P the descriptor to the socket for the
  249. connection is returned. The caller must have the right to use a
  250. reserved port. When the function returns *AHOST contains the
  251. official host name. */
  252. extern int rcmd (char **__restrict __ahost, unsigned short int __rport,
  253. __const char *__restrict __locuser,
  254. __const char *__restrict __remuser,
  255. __const char *__restrict __cmd, int *__restrict __fd2p)
  256. __THROW;
  257. #if 0
  258. /* FIXME */
  259. /* This is the equivalent function where the protocol can be selected
  260. and which therefore can be used for IPv6. */
  261. extern int rcmd_af (char **__restrict __ahost, unsigned short int __rport,
  262. __const char *__restrict __locuser,
  263. __const char *__restrict __remuser,
  264. __const char *__restrict __cmd, int *__restrict __fd2p,
  265. sa_family_t __af) __THROW;
  266. #endif
  267. /* Call `rexecd' at port RPORT on remote machine *AHOST to execute
  268. CMD. The process runs at the remote machine using the ID of user
  269. NAME whose cleartext password is PASSWD. In *FD2P the descriptor
  270. to the socket for the connection is returned. When the function
  271. returns *AHOST contains the official host name. */
  272. extern int rexec (char **__restrict __ahost, int __rport,
  273. __const char *__restrict __name,
  274. __const char *__restrict __pass,
  275. __const char *__restrict __cmd, int *__restrict __fd2p)
  276. __THROW;
  277. /* This is the equivalent function where the protocol can be selected
  278. and which therefore can be used for IPv6. */
  279. extern int rexec_af (char **__restrict __ahost, int __rport,
  280. __const char *__restrict __name,
  281. __const char *__restrict __pass,
  282. __const char *__restrict __cmd, int *__restrict __fd2p,
  283. sa_family_t __af) __THROW;
  284. /* Check whether user REMUSER on system RHOST is allowed to login as LOCUSER.
  285. If SUSER is not zero the user tries to become superuser. Return 0 if
  286. it is possible. */
  287. extern int ruserok (__const char *__rhost, int __suser,
  288. __const char *__remuser, __const char *__locuser) __THROW;
  289. #if 0
  290. /* FIXME */
  291. /* This is the equivalent function where the protocol can be selected
  292. and which therefore can be used for IPv6. */
  293. extern int ruserok_af (__const char *__rhost, int __suser,
  294. __const char *__remuser, __const char *__locuser,
  295. sa_family_t __af) __THROW;
  296. #endif
  297. /* Try to allocate reserved port, returning a descriptor for a socket opened
  298. at this port or -1 if unsuccessful. The search for an available port
  299. will start at ALPORT and continues with lower numbers. */
  300. extern int rresvport (int *__alport) __THROW;
  301. #if 0
  302. /* FIXME */
  303. /* This is the equivalent function where the protocol can be selected
  304. and which therefore can be used for IPv6. */
  305. extern int rresvport_af (int *__alport, sa_family_t __af) __THROW;
  306. #endif
  307. #endif
  308. /* Extension from POSIX.1g. */
  309. #ifdef __USE_POSIX
  310. /* Structure to contain information about address of a service provider. */
  311. struct addrinfo
  312. {
  313. int ai_flags; /* Input flags. */
  314. int ai_family; /* Protocol family for socket. */
  315. int ai_socktype; /* Socket type. */
  316. int ai_protocol; /* Protocol for socket. */
  317. socklen_t ai_addrlen; /* Length of socket address. */
  318. struct sockaddr *ai_addr; /* Socket address for socket. */
  319. char *ai_canonname; /* Canonical name for service location. */
  320. struct addrinfo *ai_next; /* Pointer to next in list. */
  321. };
  322. /* Possible values for `ai_flags' field in `addrinfo' structure. */
  323. # define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */
  324. # define AI_CANONNAME 0x0002 /* Request for canonical name. */
  325. # define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */
  326. /* Error values for `getaddrinfo' function. */
  327. # define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */
  328. # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
  329. # define EAI_AGAIN -3 /* Temporary failure in name resolution. */
  330. # define EAI_FAIL -4 /* Non-recoverable failure in name res. */
  331. # define EAI_NODATA -5 /* No address associated with NAME. */
  332. # define EAI_FAMILY -6 /* `ai_family' not supported. */
  333. # define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */
  334. # define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
  335. # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
  336. # define EAI_MEMORY -10 /* Memory allocation failure. */
  337. # define EAI_SYSTEM -11 /* System error returned in `errno'. */
  338. # ifdef __USE_GNU
  339. # define EAI_INPROGRESS -100 /* Processing request in progress. */
  340. # define EAI_CANCELED -101 /* Request canceled. */
  341. # define EAI_NOTCANCELED -102 /* Request not canceled. */
  342. # define EAI_ALLDONE -103 /* All requests done. */
  343. # define EAI_INTR -104 /* Interrupted by a signal. */
  344. # endif
  345. # define NI_MAXHOST 1025
  346. # define NI_MAXSERV 32
  347. # define NI_NUMERICHOST 1 /* Don't try to look up hostname. */
  348. # define NI_NUMERICSERV 2 /* Don't convert port number to name. */
  349. # define NI_NOFQDN 4 /* Only return nodename portion. */
  350. # define NI_NAMEREQD 8 /* Don't return numeric addresses. */
  351. # define NI_DGRAM 16 /* Look up UDP service rather than TCP. */
  352. /* Translate name of a service location and/or a service name to set of
  353. socket addresses. */
  354. extern int getaddrinfo (__const char *__restrict __name,
  355. __const char *__restrict __service,
  356. __const struct addrinfo *__restrict __req,
  357. struct addrinfo **__restrict __pai) __THROW;
  358. /* Free `addrinfo' structure AI including associated storage. */
  359. extern void freeaddrinfo (struct addrinfo *__ai) __THROW;
  360. /* Convert error return from getaddrinfo() to a string. */
  361. extern __const char *gai_strerror (int __ecode) __THROW;
  362. /* Translate a socket address to a location and service name. */
  363. extern int getnameinfo (__const struct sockaddr *__restrict __sa,
  364. socklen_t __salen, char *__restrict __host,
  365. socklen_t __hostlen, char *__restrict __serv,
  366. socklen_t __servlen, unsigned int __flags) __THROW;
  367. #endif /* POSIX */
  368. __END_DECLS
  369. #endif /* netdb.h */