netdb.in.h 7.0 KB

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