PageRenderTime 51ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/netdb.in.h

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