netdb.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. /* Copyright (C) 1996-2004, 2009, 2010 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. #if defined __USE_MISC || !defined __USE_XOPEN2K8
  44. /* Error status for non-reentrant lookup functions.
  45. We use a macro to access always the thread-specific `h_errno' variable. */
  46. # define h_errno (*__h_errno_location ())
  47. /* Function to get address of global `h_errno' variable. */
  48. extern int *__h_errno_location (void) __THROW __attribute__ ((__const__));
  49. /* Possible values left in `h_errno'. */
  50. # define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found. */
  51. # define TRY_AGAIN 2 /* Non-Authoritative Host not found,
  52. or SERVERFAIL. */
  53. # define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED,
  54. NOTIMP. */
  55. # define NO_DATA 4 /* Valid name, no data record of requested
  56. type. */
  57. #endif
  58. #if defined __USE_MISC || defined __USE_GNU
  59. # define NETDB_INTERNAL -1 /* See errno. */
  60. # define NETDB_SUCCESS 0 /* No problem. */
  61. # define NO_ADDRESS NO_DATA /* No address, look for MX record. */
  62. #endif
  63. #ifdef __USE_XOPEN2K
  64. /* Highest reserved Internet port number. */
  65. # define IPPORT_RESERVED 1024
  66. #endif
  67. #ifdef __USE_GNU
  68. /* Scope delimiter for getaddrinfo(), getnameinfo(). */
  69. # define SCOPE_DELIMITER '%'
  70. #endif
  71. #ifdef __USE_MISC
  72. /* Print error indicated by `h_errno' variable on standard error. STR
  73. if non-null is printed before the error string. */
  74. extern void herror (__const char *__str) __THROW;
  75. /* Return string associated with error ERR_NUM. */
  76. extern __const char *hstrerror (int __err_num) __THROW;
  77. #endif
  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. #if defined __USE_MISC || defined __USE_GNU
  87. # define h_addr h_addr_list[0] /* Address, for backward compatibility.*/
  88. #endif
  89. };
  90. /* Open host data base files and mark them as staying open even after
  91. a later search if STAY_OPEN is non-zero.
  92. This function is a possible cancellation point and therefore not
  93. marked with __THROW. */
  94. extern void sethostent (int __stay_open);
  95. /* Close host data base files and clear `stay open' flag.
  96. This function is a possible cancellation point and therefore not
  97. marked with __THROW. */
  98. extern void endhostent (void);
  99. /* Get next entry from host data base file. Open data base if
  100. necessary.
  101. This function is a possible cancellation point and therefore not
  102. marked with __THROW. */
  103. extern struct hostent *gethostent (void);
  104. /* Return entry from host data base which address match ADDR with
  105. length LEN and type TYPE.
  106. This function is a possible cancellation point and therefore not
  107. marked with __THROW. */
  108. extern struct hostent *gethostbyaddr (__const void *__addr, __socklen_t __len,
  109. int __type);
  110. /* Return entry from host data base for host with NAME.
  111. This function is a possible cancellation point and therefore not
  112. marked with __THROW. */
  113. extern struct hostent *gethostbyname (__const char *__name);
  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. This function is not part of POSIX and therefore no official
  119. cancellation point. But due to similarity with an POSIX interface
  120. or due to the implementation it is a cancellation point and
  121. therefore not marked with __THROW. */
  122. extern struct hostent *gethostbyname2 (__const char *__name, int __af);
  123. /* Reentrant versions of the functions above. The additional
  124. arguments specify a buffer of BUFLEN starting at BUF. The last
  125. argument is a pointer to a variable which gets the value which
  126. would be stored in the global variable `herrno' by the
  127. non-reentrant functions.
  128. These functions are not part of POSIX and therefore no official
  129. cancellation point. But due to similarity with an POSIX interface
  130. or due to the implementation they are cancellation points and
  131. therefore not marked with __THROW. */
  132. extern int gethostent_r (struct hostent *__restrict __result_buf,
  133. char *__restrict __buf, size_t __buflen,
  134. struct hostent **__restrict __result,
  135. int *__restrict __h_errnop);
  136. extern int gethostbyaddr_r (__const void *__restrict __addr, __socklen_t __len,
  137. int __type,
  138. struct hostent *__restrict __result_buf,
  139. char *__restrict __buf, size_t __buflen,
  140. struct hostent **__restrict __result,
  141. int *__restrict __h_errnop);
  142. extern int gethostbyname_r (__const char *__restrict __name,
  143. struct hostent *__restrict __result_buf,
  144. char *__restrict __buf, size_t __buflen,
  145. struct hostent **__restrict __result,
  146. int *__restrict __h_errnop);
  147. extern int gethostbyname2_r (__const char *__restrict __name, int __af,
  148. struct hostent *__restrict __result_buf,
  149. char *__restrict __buf, size_t __buflen,
  150. struct hostent **__restrict __result,
  151. int *__restrict __h_errnop);
  152. #endif /* misc */
  153. /* Open network data base files and mark them as staying open even
  154. after a later search if STAY_OPEN is non-zero.
  155. This function is a possible cancellation point and therefore not
  156. marked with __THROW. */
  157. extern void setnetent (int __stay_open);
  158. /* Close network data base files and clear `stay open' flag.
  159. This function is a possible cancellation point and therefore not
  160. marked with __THROW. */
  161. extern void endnetent (void);
  162. /* Get next entry from network data base file. Open data base if
  163. necessary.
  164. This function is a possible cancellation point and therefore not
  165. marked with __THROW. */
  166. extern struct netent *getnetent (void);
  167. /* Return entry from network data base which address match NET and
  168. type TYPE.
  169. This function is a possible cancellation point and therefore not
  170. marked with __THROW. */
  171. extern struct netent *getnetbyaddr (uint32_t __net, int __type);
  172. /* Return entry from network data base for network with NAME.
  173. This function is a possible cancellation point and therefore not
  174. marked with __THROW. */
  175. extern struct netent *getnetbyname (__const char *__name);
  176. #ifdef __USE_MISC
  177. /* Reentrant versions of the functions above. The additional
  178. arguments specify a buffer of BUFLEN starting at BUF. The last
  179. argument is a pointer to a variable which gets the value which
  180. would be stored in the global variable `herrno' by the
  181. non-reentrant functions.
  182. These functions are not part of POSIX and therefore no official
  183. cancellation point. But due to similarity with an POSIX interface
  184. or due to the implementation they are cancellation points and
  185. therefore not marked with __THROW. */
  186. extern int getnetent_r (struct netent *__restrict __result_buf,
  187. char *__restrict __buf, size_t __buflen,
  188. struct netent **__restrict __result,
  189. int *__restrict __h_errnop);
  190. extern int getnetbyaddr_r (uint32_t __net, int __type,
  191. struct netent *__restrict __result_buf,
  192. char *__restrict __buf, size_t __buflen,
  193. struct netent **__restrict __result,
  194. int *__restrict __h_errnop);
  195. extern int getnetbyname_r (__const char *__restrict __name,
  196. struct netent *__restrict __result_buf,
  197. char *__restrict __buf, size_t __buflen,
  198. struct netent **__restrict __result,
  199. int *__restrict __h_errnop);
  200. #endif /* misc */
  201. /* Description of data base entry for a single service. */
  202. struct servent
  203. {
  204. char *s_name; /* Official service name. */
  205. char **s_aliases; /* Alias list. */
  206. int s_port; /* Port number. */
  207. char *s_proto; /* Protocol to use. */
  208. };
  209. /* Open service data base files and mark them as staying open even
  210. after a later search if STAY_OPEN is non-zero.
  211. This function is a possible cancellation point and therefore not
  212. marked with __THROW. */
  213. extern void setservent (int __stay_open);
  214. /* Close service data base files and clear `stay open' flag.
  215. This function is a possible cancellation point and therefore not
  216. marked with __THROW. */
  217. extern void endservent (void);
  218. /* Get next entry from service data base file. Open data base if
  219. necessary.
  220. This function is a possible cancellation point and therefore not
  221. marked with __THROW. */
  222. extern struct servent *getservent (void);
  223. /* Return entry from network data base for network with NAME and
  224. protocol PROTO.
  225. This function is a possible cancellation point and therefore not
  226. marked with __THROW. */
  227. extern struct servent *getservbyname (__const char *__name,
  228. __const char *__proto);
  229. /* Return entry from service data base which matches port PORT and
  230. protocol PROTO.
  231. This function is a possible cancellation point and therefore not
  232. marked with __THROW. */
  233. extern struct servent *getservbyport (int __port, __const char *__proto);
  234. #ifdef __USE_MISC
  235. /* Reentrant versions of the functions above. The additional
  236. arguments specify a buffer of BUFLEN starting at BUF.
  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 getservent_r (struct servent *__restrict __result_buf,
  242. char *__restrict __buf, size_t __buflen,
  243. struct servent **__restrict __result);
  244. extern int getservbyname_r (__const char *__restrict __name,
  245. __const char *__restrict __proto,
  246. struct servent *__restrict __result_buf,
  247. char *__restrict __buf, size_t __buflen,
  248. struct servent **__restrict __result);
  249. extern int getservbyport_r (int __port, __const char *__restrict __proto,
  250. struct servent *__restrict __result_buf,
  251. char *__restrict __buf, size_t __buflen,
  252. struct servent **__restrict __result);
  253. #endif /* misc */
  254. /* Description of data base entry for a single service. */
  255. struct protoent
  256. {
  257. char *p_name; /* Official protocol name. */
  258. char **p_aliases; /* Alias list. */
  259. int p_proto; /* Protocol number. */
  260. };
  261. /* Open protocol data base files and mark them as staying open even
  262. after a later search if STAY_OPEN is non-zero.
  263. This function is a possible cancellation point and therefore not
  264. marked with __THROW. */
  265. extern void setprotoent (int __stay_open);
  266. /* Close protocol data base files and clear `stay open' flag.
  267. This function is a possible cancellation point and therefore not
  268. marked with __THROW. */
  269. extern void endprotoent (void);
  270. /* Get next entry from protocol data base file. Open data base if
  271. necessary.
  272. This function is a possible cancellation point and therefore not
  273. marked with __THROW. */
  274. extern struct protoent *getprotoent (void);
  275. /* Return entry from protocol data base for network with NAME.
  276. This function is a possible cancellation point and therefore not
  277. marked with __THROW. */
  278. extern struct protoent *getprotobyname (__const char *__name);
  279. /* Return entry from protocol data base which number is PROTO.
  280. This function is a possible cancellation point and therefore not
  281. marked with __THROW. */
  282. extern struct protoent *getprotobynumber (int __proto);
  283. #ifdef __USE_MISC
  284. /* Reentrant versions of the functions above. The additional
  285. arguments specify a buffer of BUFLEN starting at BUF.
  286. These functions are not part of POSIX and therefore no official
  287. cancellation point. But due to similarity with an POSIX interface
  288. or due to the implementation they are cancellation points and
  289. therefore not marked with __THROW. */
  290. extern int getprotoent_r (struct protoent *__restrict __result_buf,
  291. char *__restrict __buf, size_t __buflen,
  292. struct protoent **__restrict __result);
  293. extern int getprotobyname_r (__const char *__restrict __name,
  294. struct protoent *__restrict __result_buf,
  295. char *__restrict __buf, size_t __buflen,
  296. struct protoent **__restrict __result);
  297. extern int getprotobynumber_r (int __proto,
  298. struct protoent *__restrict __result_buf,
  299. char *__restrict __buf, size_t __buflen,
  300. struct protoent **__restrict __result);
  301. /* Establish network group NETGROUP for enumeration.
  302. This function is not part of POSIX and therefore no official
  303. cancellation point. But due to similarity with an POSIX interface
  304. or due to the implementation it is a cancellation point and
  305. therefore not marked with __THROW. */
  306. extern int setnetgrent (__const char *__netgroup);
  307. /* Free all space allocated by previous `setnetgrent' call.
  308. This function is not part of POSIX and therefore no official
  309. cancellation point. But due to similarity with an POSIX interface
  310. or due to the implementation it is a cancellation point and
  311. therefore not marked with __THROW. */
  312. extern void endnetgrent (void);
  313. /* Get next member of netgroup established by last `setnetgrent' call
  314. and return pointers to elements in HOSTP, USERP, and DOMAINP.
  315. This function is not part of POSIX and therefore no official
  316. cancellation point. But due to similarity with an POSIX interface
  317. or due to the implementation it is a cancellation point and
  318. therefore not marked with __THROW. */
  319. extern int getnetgrent (char **__restrict __hostp,
  320. char **__restrict __userp,
  321. char **__restrict __domainp);
  322. /* Test whether NETGROUP contains the triple (HOST,USER,DOMAIN).
  323. This function is not part of POSIX and therefore no official
  324. cancellation point. But due to similarity with an POSIX interface
  325. or due to the implementation it is a cancellation point and
  326. therefore not marked with __THROW. */
  327. extern int innetgr (__const char *__netgroup, __const char *__host,
  328. __const char *__user, __const char *__domain);
  329. /* Reentrant version of `getnetgrent' where result is placed in BUFFER.
  330. This function is not part of POSIX and therefore no official
  331. cancellation point. But due to similarity with an POSIX interface
  332. or due to the implementation it is a cancellation point and
  333. therefore not marked with __THROW. */
  334. extern int getnetgrent_r (char **__restrict __hostp,
  335. char **__restrict __userp,
  336. char **__restrict __domainp,
  337. char *__restrict __buffer, size_t __buflen);
  338. #endif /* misc */
  339. #ifdef __USE_BSD
  340. /* Call `rshd' at port RPORT on remote machine *AHOST to execute CMD.
  341. The local user is LOCUSER, on the remote machine the command is
  342. executed as REMUSER. In *FD2P the descriptor to the socket for the
  343. connection is returned. The caller must have the right to use a
  344. reserved port. When the function returns *AHOST contains the
  345. official host name.
  346. This function is not part of POSIX and therefore no official
  347. cancellation point. But due to similarity with an POSIX interface
  348. or due to the implementation it is a cancellation point and
  349. therefore not marked with __THROW. */
  350. extern int rcmd (char **__restrict __ahost, unsigned short int __rport,
  351. __const char *__restrict __locuser,
  352. __const char *__restrict __remuser,
  353. __const char *__restrict __cmd, int *__restrict __fd2p);
  354. /* This is the equivalent function where the protocol can be selected
  355. and which therefore can be used for IPv6.
  356. This function is not part of POSIX and therefore no official
  357. cancellation point. But due to similarity with an POSIX interface
  358. or due to the implementation it is a cancellation point and
  359. therefore not marked with __THROW. */
  360. extern int rcmd_af (char **__restrict __ahost, unsigned short int __rport,
  361. __const char *__restrict __locuser,
  362. __const char *__restrict __remuser,
  363. __const char *__restrict __cmd, int *__restrict __fd2p,
  364. sa_family_t __af);
  365. /* Call `rexecd' at port RPORT on remote machine *AHOST to execute
  366. CMD. The process runs at the remote machine using the ID of user
  367. NAME whose cleartext password is PASSWD. In *FD2P the descriptor
  368. to the socket for the connection is returned. When the function
  369. returns *AHOST contains the official host name.
  370. This function is not part of POSIX and therefore no official
  371. cancellation point. But due to similarity with an POSIX interface
  372. or due to the implementation it is a cancellation point and
  373. therefore not marked with __THROW. */
  374. extern int rexec (char **__restrict __ahost, int __rport,
  375. __const char *__restrict __name,
  376. __const char *__restrict __pass,
  377. __const char *__restrict __cmd, int *__restrict __fd2p);
  378. /* This is the equivalent function where the protocol can be selected
  379. and which therefore can be used for IPv6.
  380. This function is not part of POSIX and therefore no official
  381. cancellation point. But due to similarity with an POSIX interface
  382. or due to the implementation it is a cancellation point and
  383. therefore not marked with __THROW. */
  384. extern int rexec_af (char **__restrict __ahost, int __rport,
  385. __const char *__restrict __name,
  386. __const char *__restrict __pass,
  387. __const char *__restrict __cmd, int *__restrict __fd2p,
  388. sa_family_t __af);
  389. /* Check whether user REMUSER on system RHOST is allowed to login as LOCUSER.
  390. If SUSER is not zero the user tries to become superuser. Return 0 if
  391. it is possible.
  392. This function is not part of POSIX and therefore no official
  393. cancellation point. But due to similarity with an POSIX interface
  394. or due to the implementation it is a cancellation point and
  395. therefore not marked with __THROW. */
  396. extern int ruserok (__const char *__rhost, int __suser,
  397. __const char *__remuser, __const char *__locuser);
  398. /* This is the equivalent function where the protocol can be selected
  399. and which therefore can be used for IPv6.
  400. This function is not part of POSIX and therefore no official
  401. cancellation point. But due to similarity with an POSIX interface
  402. or due to the implementation it is a cancellation point and
  403. therefore not marked with __THROW. */
  404. extern int ruserok_af (__const char *__rhost, int __suser,
  405. __const char *__remuser, __const char *__locuser,
  406. sa_family_t __af);
  407. /* Check whether user REMUSER on system indicated by IPv4 address
  408. RADDR is allowed to login as LOCUSER. Non-IPv4 (e.g., IPv6) are
  409. not supported. If SUSER is not zero the user tries to become
  410. superuser. Return 0 if it is possible.
  411. This function is not part of POSIX and therefore no official
  412. cancellation point. But due to similarity with an POSIX interface
  413. or due to the implementation it is a cancellation point and
  414. therefore not marked with __THROW. */
  415. extern int iruserok (uint32_t __raddr, int __suser,
  416. __const char *__remuser, __const char *__locuser);
  417. /* This is the equivalent function where the pfamiliy if the address
  418. pointed to by RADDR is determined by the value of AF. It therefore
  419. can be used for IPv6
  420. This function is not part of POSIX and therefore no official
  421. cancellation point. But due to similarity with an POSIX interface
  422. or due to the implementation it is a cancellation point and
  423. therefore not marked with __THROW. */
  424. extern int iruserok_af (__const void *__raddr, int __suser,
  425. __const char *__remuser, __const char *__locuser,
  426. sa_family_t __af);
  427. /* Try to allocate reserved port, returning a descriptor for a socket opened
  428. at this port or -1 if unsuccessful. The search for an available port
  429. will start at ALPORT and continues with lower numbers.
  430. This function is not part of POSIX and therefore no official
  431. cancellation point. But due to similarity with an POSIX interface
  432. or due to the implementation it is a cancellation point and
  433. therefore not marked with __THROW. */
  434. extern int rresvport (int *__alport);
  435. /* This is the equivalent function where the protocol can be selected
  436. and which therefore can be used for IPv6.
  437. This function is not part of POSIX and therefore no official
  438. cancellation point. But due to similarity with an POSIX interface
  439. or due to the implementation it is a cancellation point and
  440. therefore not marked with __THROW. */
  441. extern int rresvport_af (int *__alport, sa_family_t __af);
  442. #endif
  443. /* Extension from POSIX.1g. */
  444. #ifdef __USE_POSIX
  445. /* Structure to contain information about address of a service provider. */
  446. struct addrinfo
  447. {
  448. int ai_flags; /* Input flags. */
  449. int ai_family; /* Protocol family for socket. */
  450. int ai_socktype; /* Socket type. */
  451. int ai_protocol; /* Protocol for socket. */
  452. socklen_t ai_addrlen; /* Length of socket address. */
  453. struct sockaddr *ai_addr; /* Socket address for socket. */
  454. char *ai_canonname; /* Canonical name for service location. */
  455. struct addrinfo *ai_next; /* Pointer to next in list. */
  456. };
  457. # ifdef __USE_GNU
  458. /* Structure used as control block for asynchronous lookup. */
  459. struct gaicb
  460. {
  461. const char *ar_name; /* Name to look up. */
  462. const char *ar_service; /* Service name. */
  463. const struct addrinfo *ar_request; /* Additional request specification. */
  464. struct addrinfo *ar_result; /* Pointer to result. */
  465. /* The following are internal elements. */
  466. int __return;
  467. int __unused[5];
  468. };
  469. /* Lookup mode. */
  470. # define GAI_WAIT 0
  471. # define GAI_NOWAIT 1
  472. # endif
  473. /* Possible values for `ai_flags' field in `addrinfo' structure. */
  474. # define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */
  475. # define AI_CANONNAME 0x0002 /* Request for canonical name. */
  476. # define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */
  477. # define AI_V4MAPPED 0x0008 /* IPv4 mapped addresses are acceptable. */
  478. # define AI_ALL 0x0010 /* Return IPv4 mapped and IPv6 addresses. */
  479. # define AI_ADDRCONFIG 0x0020 /* Use configuration of this host to choose
  480. returned address type.. */
  481. # ifdef __USE_GNU
  482. # define AI_IDN 0x0040 /* IDN encode input (assuming it is encoded
  483. in the current locale's character set)
  484. before looking it up. */
  485. # define AI_CANONIDN 0x0080 /* Translate canonical name from IDN format. */
  486. # define AI_IDN_ALLOW_UNASSIGNED 0x0100 /* Don't reject unassigned Unicode
  487. code points. */
  488. # define AI_IDN_USE_STD3_ASCII_RULES 0x0200 /* Validate strings according to
  489. STD3 rules. */
  490. # endif
  491. # define AI_NUMERICSERV 0x0400 /* Don't use name resolution. */
  492. /* Error values for `getaddrinfo' function. */
  493. # define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */
  494. # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
  495. # define EAI_AGAIN -3 /* Temporary failure in name resolution. */
  496. # define EAI_FAIL -4 /* Non-recoverable failure in name res. */
  497. # define EAI_FAMILY -6 /* `ai_family' not supported. */
  498. # define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */
  499. # define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
  500. # define EAI_MEMORY -10 /* Memory allocation failure. */
  501. # define EAI_SYSTEM -11 /* System error returned in `errno'. */
  502. # define EAI_OVERFLOW -12 /* Argument buffer overflow. */
  503. # ifdef __USE_GNU
  504. # define EAI_NODATA -5 /* No address associated with NAME. */
  505. # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
  506. # define EAI_INPROGRESS -100 /* Processing request in progress. */
  507. # define EAI_CANCELED -101 /* Request canceled. */
  508. # define EAI_NOTCANCELED -102 /* Request not canceled. */
  509. # define EAI_ALLDONE -103 /* All requests done. */
  510. # define EAI_INTR -104 /* Interrupted by a signal. */
  511. # define EAI_IDN_ENCODE -105 /* IDN encoding failed. */
  512. # endif
  513. # ifdef __USE_MISC
  514. # define NI_MAXHOST 1025
  515. # define NI_MAXSERV 32
  516. # endif
  517. # define NI_NUMERICHOST 1 /* Don't try to look up hostname. */
  518. # define NI_NUMERICSERV 2 /* Don't convert port number to name. */
  519. # define NI_NOFQDN 4 /* Only return nodename portion. */
  520. # define NI_NAMEREQD 8 /* Don't return numeric addresses. */
  521. # define NI_DGRAM 16 /* Look up UDP service rather than TCP. */
  522. # ifdef __USE_GNU
  523. # define NI_IDN 32 /* Convert name from IDN format. */
  524. # define NI_IDN_ALLOW_UNASSIGNED 64 /* Don't reject unassigned Unicode
  525. code points. */
  526. # define NI_IDN_USE_STD3_ASCII_RULES 128 /* Validate strings according to
  527. STD3 rules. */
  528. # endif
  529. /* Translate name of a service location and/or a service name to set of
  530. socket addresses.
  531. This function is a possible cancellation point and therefore not
  532. marked with __THROW. */
  533. extern int getaddrinfo (__const char *__restrict __name,
  534. __const char *__restrict __service,
  535. __const struct addrinfo *__restrict __req,
  536. struct addrinfo **__restrict __pai);
  537. /* Free `addrinfo' structure AI including associated storage. */
  538. extern void freeaddrinfo (struct addrinfo *__ai) __THROW;
  539. /* Convert error return from getaddrinfo() to a string. */
  540. extern __const char *gai_strerror (int __ecode) __THROW;
  541. /* Translate a socket address to a location and service name.
  542. This function is a possible cancellation point and therefore not
  543. marked with __THROW. */
  544. extern int getnameinfo (__const struct sockaddr *__restrict __sa,
  545. socklen_t __salen, char *__restrict __host,
  546. socklen_t __hostlen, char *__restrict __serv,
  547. socklen_t __servlen, unsigned int __flags);
  548. #endif /* POSIX */
  549. #ifdef __USE_GNU
  550. /* Enqueue ENT requests from the LIST. If MODE is GAI_WAIT wait until all
  551. requests are handled. If WAIT is GAI_NOWAIT return immediately after
  552. queueing the requests and signal completion according to SIG.
  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 getaddrinfo_a (int __mode, struct gaicb *__list[__restrict_arr],
  558. int __ent, struct sigevent *__restrict __sig);
  559. /* Suspend execution of the thread until at least one of the ENT requests
  560. in LIST is handled. If TIMEOUT is not a null pointer it specifies the
  561. longest time the function keeps waiting before returning with an error.
  562. This function is not part of POSIX and therefore no official
  563. cancellation point. But due to similarity with an POSIX interface
  564. or due to the implementation it is a cancellation point and
  565. therefore not marked with __THROW. */
  566. extern int gai_suspend (__const struct gaicb *__const __list[], int __ent,
  567. __const struct timespec *__timeout);
  568. /* Get the error status of the request REQ. */
  569. extern int gai_error (struct gaicb *__req) __THROW;
  570. /* Cancel the requests associated with GAICBP. */
  571. extern int gai_cancel (struct gaicb *__gaicbp) __THROW;
  572. #endif /* GNU */
  573. __END_DECLS
  574. #endif /* netdb.h */