netdb.in.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /* Provide a netdb.h header file for systems lacking it (read: MinGW).
  2. Copyright (C) 2008-2012 Free Software Foundation, Inc.
  3. Written by Simon Josefsson.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with this program; if not, write to the Free Software Foundation,
  14. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
  15. /* This file is supposed to be used on platforms that lack <netdb.h>.
  16. It is intended to provide definitions and prototypes needed by an
  17. application. */
  18. #ifndef _@GUARD_PREFIX@_NETDB_H
  19. #if __GNUC__ >= 3
  20. @PRAGMA_SYSTEM_HEADER@
  21. #endif
  22. @PRAGMA_COLUMNS@
  23. #if @HAVE_NETDB_H@
  24. /* The include_next requires a split double-inclusion guard. */
  25. # @INCLUDE_NEXT@ @NEXT_NETDB_H@
  26. #endif
  27. #ifndef _@GUARD_PREFIX@_NETDB_H
  28. #define _@GUARD_PREFIX@_NETDB_H
  29. /* Get <netdb.h> definitions such as 'socklen_t' on IRIX 6.5 and OSF/1 4.0 and
  30. 'struct hostent' on MinGW. */
  31. #include <sys/socket.h>
  32. /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
  33. /* The definition of _GL_ARG_NONNULL is copied here. */
  34. /* The definition of _GL_WARN_ON_USE is copied here. */
  35. /* Declarations for a platform that lacks <netdb.h>, or where it is
  36. incomplete. */
  37. #if @GNULIB_GETADDRINFO@
  38. # if !@HAVE_STRUCT_ADDRINFO@
  39. # ifdef __cplusplus
  40. extern "C" {
  41. # endif
  42. # if !GNULIB_defined_struct_addrinfo
  43. /* Structure to contain information about address of a service provider. */
  44. struct addrinfo
  45. {
  46. int ai_flags; /* Input flags. */
  47. int ai_family; /* Protocol family for socket. */
  48. int ai_socktype; /* Socket type. */
  49. int ai_protocol; /* Protocol for socket. */
  50. socklen_t ai_addrlen; /* Length of socket address. */
  51. struct sockaddr *ai_addr; /* Socket address for socket. */
  52. char *ai_canonname; /* Canonical name for service location. */
  53. struct addrinfo *ai_next; /* Pointer to next in list. */
  54. };
  55. # define GNULIB_defined_struct_addrinfo 1
  56. # endif
  57. # ifdef __cplusplus
  58. }
  59. # endif
  60. # endif
  61. /* Possible values for 'ai_flags' field in 'addrinfo' structure. */
  62. # ifndef AI_PASSIVE
  63. # define AI_PASSIVE 0x0001 /* Socket address is intended for 'bind'. */
  64. # endif
  65. # ifndef AI_CANONNAME
  66. # define AI_CANONNAME 0x0002 /* Request for canonical name. */
  67. # endif
  68. # ifndef AI_NUMERICSERV
  69. # define AI_NUMERICSERV 0x0400 /* Don't use name resolution. */
  70. # endif
  71. # if 0
  72. # define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */
  73. # endif
  74. /* These symbolic constants are required to be present by POSIX, but
  75. our getaddrinfo replacement doesn't use them (yet). Setting them
  76. to 0 on systems that doesn't have them avoids causing problems for
  77. system getaddrinfo implementations that would be confused by
  78. unknown values. */
  79. # ifndef AI_V4MAPPED
  80. # define AI_V4MAPPED 0 /* 0x0008: IPv4 mapped addresses are acceptable. */
  81. # endif
  82. # ifndef AI_ALL
  83. # define AI_ALL 0 /* 0x0010: Return IPv4 mapped and IPv6 addresses. */
  84. # endif
  85. # ifndef AI_ADDRCONFIG
  86. # define AI_ADDRCONFIG 0 /* 0x0020: Use configuration of this host to choose
  87. returned address type. */
  88. # endif
  89. /* Error values for 'getaddrinfo' function. */
  90. # ifndef EAI_BADFLAGS
  91. # define EAI_BADFLAGS -1 /* Invalid value for 'ai_flags' field. */
  92. # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
  93. # define EAI_AGAIN -3 /* Temporary failure in name resolution. */
  94. # define EAI_FAIL -4 /* Non-recoverable failure in name res. */
  95. # define EAI_NODATA -5 /* No address associated with NAME. */
  96. # define EAI_FAMILY -6 /* 'ai_family' not supported. */
  97. # define EAI_SOCKTYPE -7 /* 'ai_socktype' not supported. */
  98. # define EAI_SERVICE -8 /* SERVICE not supported for 'ai_socktype'. */
  99. # define EAI_MEMORY -10 /* Memory allocation failure. */
  100. # endif
  101. /* Since EAI_NODATA is deprecated by RFC3493, some systems (at least
  102. FreeBSD, which does define EAI_BADFLAGS) have removed the definition
  103. in favor of EAI_NONAME. */
  104. # if !defined EAI_NODATA && defined EAI_NONAME
  105. # define EAI_NODATA EAI_NONAME
  106. # endif
  107. # ifndef EAI_OVERFLOW
  108. /* Not defined on mingw32 and Haiku. */
  109. # define EAI_OVERFLOW -12 /* Argument buffer overflow. */
  110. # endif
  111. # ifndef EAI_ADDRFAMILY
  112. /* Not defined on mingw32. */
  113. # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
  114. # endif
  115. # ifndef EAI_SYSTEM
  116. /* Not defined on mingw32. */
  117. # define EAI_SYSTEM -11 /* System error returned in 'errno'. */
  118. # endif
  119. # if 0
  120. /* The commented out definitions below are not yet implemented in the
  121. GNULIB getaddrinfo() replacement, so are not yet needed.
  122. If they are restored, be sure to protect the definitions with #ifndef. */
  123. # ifndef EAI_INPROGRESS
  124. # define EAI_INPROGRESS -100 /* Processing request in progress. */
  125. # define EAI_CANCELED -101 /* Request canceled. */
  126. # define EAI_NOTCANCELED -102 /* Request not canceled. */
  127. # define EAI_ALLDONE -103 /* All requests done. */
  128. # define EAI_INTR -104 /* Interrupted by a signal. */
  129. # define EAI_IDN_ENCODE -105 /* IDN encoding failed. */
  130. # endif
  131. # endif
  132. # if !@HAVE_DECL_GETADDRINFO@
  133. /* Translate name of a service location and/or a service name to set of
  134. socket addresses.
  135. For more details, see the POSIX:2001 specification
  136. <http://www.opengroup.org/susv3xsh/getaddrinfo.html>. */
  137. _GL_FUNCDECL_SYS (getaddrinfo, int,
  138. (const char *restrict nodename,
  139. const char *restrict servname,
  140. const struct addrinfo *restrict hints,
  141. struct addrinfo **restrict res)
  142. _GL_ARG_NONNULL ((4)));
  143. # endif
  144. _GL_CXXALIAS_SYS (getaddrinfo, int,
  145. (const char *restrict nodename,
  146. const char *restrict servname,
  147. const struct addrinfo *restrict hints,
  148. struct addrinfo **restrict res));
  149. _GL_CXXALIASWARN (getaddrinfo);
  150. # if !@HAVE_DECL_FREEADDRINFO@
  151. /* Free 'addrinfo' structure AI including associated storage.
  152. For more details, see the POSIX:2001 specification
  153. <http://www.opengroup.org/susv3xsh/getaddrinfo.html>. */
  154. _GL_FUNCDECL_SYS (freeaddrinfo, void, (struct addrinfo *ai)
  155. _GL_ARG_NONNULL ((1)));
  156. # endif
  157. _GL_CXXALIAS_SYS (freeaddrinfo, void, (struct addrinfo *ai));
  158. _GL_CXXALIASWARN (freeaddrinfo);
  159. # if @REPLACE_GAI_STRERROR@
  160. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  161. # undef gai_strerror
  162. # define gai_strerror rpl_gai_strerror
  163. # endif
  164. _GL_FUNCDECL_RPL (gai_strerror, const char *, (int ecode));
  165. _GL_CXXALIAS_RPL (gai_strerror, const char *, (int ecode));
  166. # else
  167. # if !@HAVE_DECL_GAI_STRERROR@
  168. /* Convert error return from getaddrinfo() to a string.
  169. For more details, see the POSIX:2001 specification
  170. <http://www.opengroup.org/susv3xsh/gai_strerror.html>. */
  171. _GL_FUNCDECL_SYS (gai_strerror, const char *, (int ecode));
  172. # endif
  173. _GL_CXXALIAS_SYS (gai_strerror, const char *, (int ecode));
  174. # endif
  175. _GL_CXXALIASWARN (gai_strerror);
  176. # if !@HAVE_DECL_GETNAMEINFO@
  177. /* Convert socket address to printable node and service names.
  178. For more details, see the POSIX:2001 specification
  179. <http://www.opengroup.org/susv3xsh/getnameinfo.html>. */
  180. _GL_FUNCDECL_SYS (getnameinfo, int,
  181. (const struct sockaddr *restrict sa, socklen_t salen,
  182. char *restrict node, socklen_t nodelen,
  183. char *restrict service, socklen_t servicelen,
  184. int flags)
  185. _GL_ARG_NONNULL ((1)));
  186. # endif
  187. /* Need to cast, because on glibc systems, the seventh parameter is
  188. unsigned int flags. */
  189. _GL_CXXALIAS_SYS_CAST (getnameinfo, int,
  190. (const struct sockaddr *restrict sa, socklen_t salen,
  191. char *restrict node, socklen_t nodelen,
  192. char *restrict service, socklen_t servicelen,
  193. int flags));
  194. _GL_CXXALIASWARN (getnameinfo);
  195. /* Possible flags for getnameinfo. */
  196. # ifndef NI_NUMERICHOST
  197. # define NI_NUMERICHOST 1
  198. # endif
  199. # ifndef NI_NUMERICSERV
  200. # define NI_NUMERICSERV 2
  201. # endif
  202. #elif defined GNULIB_POSIXCHECK
  203. # undef getaddrinfo
  204. # if HAVE_RAW_DECL_GETADDRINFO
  205. _GL_WARN_ON_USE (getaddrinfo, "getaddrinfo is unportable - "
  206. "use gnulib module getaddrinfo for portability");
  207. # endif
  208. # undef freeaddrinfo
  209. # if HAVE_RAW_DECL_FREEADDRINFO
  210. _GL_WARN_ON_USE (freeaddrinfo, "freeaddrinfo is unportable - "
  211. "use gnulib module getaddrinfo for portability");
  212. # endif
  213. # undef gai_strerror
  214. # if HAVE_RAW_DECL_GAI_STRERROR
  215. _GL_WARN_ON_USE (gai_strerror, "gai_strerror is unportable - "
  216. "use gnulib module getaddrinfo for portability");
  217. # endif
  218. # undef getnameinfo
  219. # if HAVE_RAW_DECL_GETNAMEINFO
  220. _GL_WARN_ON_USE (getnameinfo, "getnameinfo is unportable - "
  221. "use gnulib module getaddrinfo for portability");
  222. # endif
  223. #endif
  224. #endif /* _@GUARD_PREFIX@_NETDB_H */
  225. #endif /* _@GUARD_PREFIX@_NETDB_H */