netdb.in.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /* Provide a netdb.h header file for systems lacking it (read: MinGW).
  2. Copyright (C) 2008-2010 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 _GL_NETDB_H
  19. #if __GNUC__ >= 3
  20. @PRAGMA_SYSTEM_HEADER@
  21. #endif
  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 _GL_NETDB_H
  27. #define _GL_NETDB_H
  28. /* Get netdb.h definitions such as struct hostent for MinGW. */
  29. #include <sys/socket.h>
  30. /* The definition of _GL_ARG_NONNULL is copied here. */
  31. /* The definition of _GL_WARN_ON_USE is copied here. */
  32. /* Declarations for a platform that lacks <netdb.h>, or where it is
  33. incomplete. */
  34. #if @GNULIB_GETADDRINFO@
  35. # if !@HAVE_STRUCT_ADDRINFO@
  36. /* Structure to contain information about address of a service provider. */
  37. struct addrinfo
  38. {
  39. int ai_flags; /* Input flags. */
  40. int ai_family; /* Protocol family for socket. */
  41. int ai_socktype; /* Socket type. */
  42. int ai_protocol; /* Protocol for socket. */
  43. socklen_t ai_addrlen; /* Length of socket address. */
  44. struct sockaddr *ai_addr; /* Socket address for socket. */
  45. char *ai_canonname; /* Canonical name for service location. */
  46. struct addrinfo *ai_next; /* Pointer to next in list. */
  47. };
  48. # endif
  49. /* Possible values for `ai_flags' field in `addrinfo' structure. */
  50. # ifndef AI_PASSIVE
  51. # define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */
  52. # endif
  53. # ifndef AI_CANONNAME
  54. # define AI_CANONNAME 0x0002 /* Request for canonical name. */
  55. # endif
  56. # ifndef AI_NUMERICSERV
  57. # define AI_NUMERICSERV 0x0400 /* Don't use name resolution. */
  58. # endif
  59. # if 0
  60. # define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */
  61. # endif
  62. /* These symbolic constants are required to be present by POSIX, but
  63. our getaddrinfo replacement doesn't use them (yet). Setting them
  64. to 0 on systems that doesn't have them avoids causing problems for
  65. system getaddrinfo implementations that would be confused by
  66. unknown values. */
  67. # ifndef AI_V4MAPPED
  68. # define AI_V4MAPPED 0 /* 0x0008: IPv4 mapped addresses are acceptable. */
  69. # endif
  70. # ifndef AI_ALL
  71. # define AI_ALL 0 /* 0x0010: Return IPv4 mapped and IPv6 addresses. */
  72. # endif
  73. # ifndef AI_ADDRCONFIG
  74. # define AI_ADDRCONFIG 0 /* 0x0020: Use configuration of this host to choose
  75. returned address type. */
  76. # endif
  77. /* Error values for `getaddrinfo' function. */
  78. # ifndef EAI_BADFLAGS
  79. # define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */
  80. # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
  81. # define EAI_AGAIN -3 /* Temporary failure in name resolution. */
  82. # define EAI_FAIL -4 /* Non-recoverable failure in name res. */
  83. # define EAI_NODATA -5 /* No address associated with NAME. */
  84. # define EAI_FAMILY -6 /* `ai_family' not supported. */
  85. # define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */
  86. # define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
  87. # define EAI_MEMORY -10 /* Memory allocation failure. */
  88. # endif
  89. /* Since EAI_NODATA is deprecated by RFC3493, some systems (at least
  90. FreeBSD, which does define EAI_BADFLAGS) have removed the definition
  91. in favor of EAI_NONAME. */
  92. # if !defined EAI_NODATA && defined EAI_NONAME
  93. # define EAI_NODATA EAI_NONAME
  94. # endif
  95. # ifndef EAI_OVERFLOW
  96. /* Not defined on mingw32 and Haiku. */
  97. # define EAI_OVERFLOW -12 /* Argument buffer overflow. */
  98. # endif
  99. # ifndef EAI_ADDRFAMILY
  100. /* Not defined on mingw32. */
  101. # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
  102. # endif
  103. # ifndef EAI_SYSTEM
  104. /* Not defined on mingw32. */
  105. # define EAI_SYSTEM -11 /* System error returned in `errno'. */
  106. # endif
  107. # if 0
  108. /* The commented out definitions below are not yet implemented in the
  109. GNULIB getaddrinfo() replacement, so are not yet needed.
  110. If they are restored, be sure to protect the definitions with #ifndef. */
  111. # ifndef EAI_INPROGRESS
  112. # define EAI_INPROGRESS -100 /* Processing request in progress. */
  113. # define EAI_CANCELED -101 /* Request canceled. */
  114. # define EAI_NOTCANCELED -102 /* Request not canceled. */
  115. # define EAI_ALLDONE -103 /* All requests done. */
  116. # define EAI_INTR -104 /* Interrupted by a signal. */
  117. # define EAI_IDN_ENCODE -105 /* IDN encoding failed. */
  118. # endif
  119. # endif
  120. # if !@HAVE_DECL_GETADDRINFO@
  121. /* Translate name of a service location and/or a service name to set of
  122. socket addresses.
  123. For more details, see the POSIX:2001 specification
  124. <http://www.opengroup.org/susv3xsh/getaddrinfo.html>. */
  125. extern int getaddrinfo (const char *restrict nodename,
  126. const char *restrict servname,
  127. const struct addrinfo *restrict hints,
  128. struct addrinfo **restrict res)
  129. _GL_ARG_NONNULL ((4));
  130. # endif
  131. # if !@HAVE_DECL_FREEADDRINFO@
  132. /* Free `addrinfo' structure AI including associated storage.
  133. For more details, see the POSIX:2001 specification
  134. <http://www.opengroup.org/susv3xsh/getaddrinfo.html>. */
  135. extern void freeaddrinfo (struct addrinfo *ai) _GL_ARG_NONNULL ((1));
  136. # endif
  137. # if !@HAVE_DECL_GAI_STRERROR@
  138. /* Convert error return from getaddrinfo() to a string.
  139. For more details, see the POSIX:2001 specification
  140. <http://www.opengroup.org/susv3xsh/gai_strerror.html>. */
  141. extern const char *gai_strerror (int ecode);
  142. # endif
  143. # if !@HAVE_DECL_GETNAMEINFO@
  144. /* Convert socket address to printable node and service names.
  145. For more details, see the POSIX:2001 specification
  146. <http://www.opengroup.org/susv3xsh/getnameinfo.html>. */
  147. extern int getnameinfo (const struct sockaddr *restrict sa, socklen_t salen,
  148. char *restrict node, socklen_t nodelen,
  149. char *restrict service, socklen_t servicelen,
  150. int flags)
  151. _GL_ARG_NONNULL ((1));
  152. # endif
  153. /* Possible flags for getnameinfo. */
  154. # ifndef NI_NUMERICHOST
  155. # define NI_NUMERICHOST 1
  156. # endif
  157. # ifndef NI_NUMERICSERV
  158. # define NI_NUMERICSERV 2
  159. # endif
  160. #elif defined GNULIB_POSIXCHECK
  161. # undef getaddrinfo
  162. # if HAVE_RAW_DECL_GETADDRINFO
  163. _GL_WARN_ON_USE (getaddrinfo, "getaddrinfo is unportable - "
  164. "use gnulib module getaddrinfo for portability");
  165. # endif
  166. # undef freeaddrinfo
  167. # if HAVE_RAW_DECL_FREEADDRINFO
  168. _GL_WARN_ON_USE (freeaddrinfo, "freeaddrinfo is unportable - "
  169. "use gnulib module getaddrinfo for portability");
  170. # endif
  171. # undef gai_strerror
  172. # if HAVE_RAW_DECL_GAI_STRERROR
  173. _GL_WARN_ON_USE (gai_strerror, "gai_strerror is unportable - "
  174. "use gnulib module getaddrinfo for portability");
  175. # endif
  176. # undef getnameinfo
  177. # if HAVE_RAW_DECL_GETNAMEINFO
  178. _GL_WARN_ON_USE (getnameinfo, "getnameinfo is unportable - "
  179. "use gnulib module getaddrinfo for portability");
  180. # endif
  181. #endif
  182. #endif /* _GL_NETDB_H */
  183. #endif /* _GL_NETDB_H */