netdb.in.h 6.4 KB

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