PageRenderTime 25ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/src/getaddrinfo.h

https://github.com/joelimome/aria2
C Header | 276 lines | 195 code | 24 blank | 57 comment | 2 complexity | c52d5862a640be66407a1d5ab111740a MD5 | raw file
  1. /*
  2. * Copyright (c) 2001, 02 Motoyuki Kasahara
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * 3. Neither the name of the project nor the names of its contributors
  13. * may be used to endorse or promote products derived from this software
  14. * without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
  17. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
  20. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  22. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  23. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  24. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  25. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  26. * SUCH DAMAGE.
  27. */
  28. #ifndef _D_GETADDRINFO_H
  29. #define _D_GETADDRINFO_H
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif /* __cplusplus */
  33. #ifdef __MINGW32__
  34. # undef SIZE_MAX
  35. #endif // __MINGW32__
  36. #ifdef HAVE_CONFIG_H
  37. # include "config.h"
  38. #endif // HAVE_CONFIG_H
  39. #ifdef __MINGW32__
  40. # ifndef _WIN32_WINNT
  41. # define _WIN32_WINNT 0x501
  42. # endif // _WIN32_WINNT
  43. # include <winsock2.h>
  44. # undef ERROR
  45. # include <ws2tcpip.h>
  46. #endif // __MINGW32__
  47. #ifdef HAVE_SYS_SOCKET_H
  48. # include <sys/socket.h>
  49. #endif // HAVE_SYS_SOCKET_H
  50. #ifdef HAVE_NETDB_H
  51. # include <netdb.h>
  52. #endif // HAVE_NETDB_H
  53. #include <sys/types.h>
  54. /********************************************************************/
  55. /*
  56. * Undefine all the macros.
  57. * <netdb.h> might defines some of them.
  58. */
  59. #ifdef EAI_ADDRFAMILY
  60. #undef EAI_ADDRFAMILY
  61. #endif
  62. #ifdef EAI_AGAIN
  63. #undef EAI_AGAIN
  64. #endif
  65. #ifdef EAI_BADFLAGS
  66. #undef EAI_BADFLAGS
  67. #endif
  68. #ifdef EAI_FAIL
  69. #undef EAI_FAIL
  70. #endif
  71. #ifdef EAI_FAMILY
  72. #undef EAI_FAMILY
  73. #endif
  74. #ifdef EAI_MEMORY
  75. #undef EAI_MEMORY
  76. #endif
  77. #ifdef EAI_NONAME
  78. #undef EAI_NONAME
  79. #endif
  80. #ifdef EAI_OVERFLOW
  81. #undef EAI_OVERFLOW
  82. #endif
  83. #ifdef EAI_SERVICE
  84. #undef EAI_SERVICE
  85. #endif
  86. #ifdef EAI_SOCKTYPE
  87. #undef EAI_SOCKTYPE
  88. #endif
  89. #ifdef EAI_SYSTEM
  90. #undef EAI_SYSTEM
  91. #endif
  92. #ifdef AI_PASSIVE
  93. #undef AI_PASSIVE
  94. #endif
  95. #ifdef AI_CANONNAME
  96. #undef AI_CANONNAME
  97. #endif
  98. #ifdef AI_NUMERICHOST
  99. #undef AI_NUMERICHOST
  100. #endif
  101. #ifdef AI_NUMERICSERV
  102. #undef AI_NUMERICSERV
  103. #endif
  104. #ifdef AI_V4MAPPED
  105. #undef AI_V4MAPPED
  106. #endif
  107. #ifdef AI_ALL
  108. #undef AI_ALL
  109. #endif
  110. #ifdef AI_ADDRCONFIG
  111. #undef AI_ADDRCONFIG
  112. #endif
  113. #ifdef AI_DEFAULT
  114. #undef AI_DEFAULT
  115. #endif
  116. #ifdef NI_NOFQDN
  117. #undef NI_NOFQDN
  118. #endif
  119. #ifdef NI_NUMERICHOST
  120. #undef NI_NUMERICHOST
  121. #endif
  122. #ifdef NI_NAMEREQD
  123. #undef NI_NAMEREQD
  124. #endif
  125. #ifdef NI_NUMERICSERV
  126. #undef NI_NUMERICSERV
  127. #endif
  128. #ifdef NI_NUMERICSCOPE
  129. #undef NI_NUMERICSCOPE
  130. #endif
  131. #ifdef NI_DGRAM
  132. #undef NI_DGRAM
  133. #endif
  134. #ifdef NI_MAXHOST
  135. #undef NI_MAXHOST
  136. #endif
  137. #ifdef NI_MAXSERV
  138. #undef NI_MAXSERV
  139. #endif
  140. /*
  141. * Fake struct and function names.
  142. * <netdb.h> might declares all or some of them.
  143. */
  144. #if defined(HAVE_GETADDRINFO) || defined(HAVE_GETNAMEINFO)
  145. #define addrinfo my_addrinfo
  146. #define gai_strerror my_gai_strerror
  147. #define freeaddrinfo my_freeaddrinfo
  148. #define getaddrinfo my_getaddrinfo
  149. #define getnameinfo my_getnameinfo
  150. #endif
  151. /* <from linux's netdb.h> */
  152. /* Possible values for `ai_flags' field in `addrinfo' structure. */
  153. # define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */
  154. # define AI_CANONNAME 0x0002 /* Request for canonical name. */
  155. # define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */
  156. # define AI_V4MAPPED 0x0008 /* IPv4 mapped addresses are acceptable. */
  157. # define AI_ALL 0x0010 /* Return IPv4 mapped and IPv6 addresses. */
  158. # define AI_ADDRCONFIG 0x0020 /* Use configuration of this host to choose
  159. returned address type.. */
  160. # ifdef __USE_GNU
  161. # define AI_IDN 0x0040 /* IDN encode input (assuming it is encoded
  162. in the current locale's character set)
  163. before looking it up. */
  164. # define AI_CANONIDN 0x0080 /* Translate canonical name from IDN format. */
  165. # define AI_IDN_ALLOW_UNASSIGNED 0x0100 /* Don't reject unassigned Unicode
  166. code points. */
  167. # define AI_IDN_USE_STD3_ASCII_RULES 0x0200 /* Validate strings according to
  168. STD3 rules. */
  169. # endif
  170. # define AI_NUMERICSERV 0x0400 /* Don't use name resolution. */
  171. /* Error values for `getaddrinfo' function. */
  172. # define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */
  173. # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
  174. # define EAI_AGAIN -3 /* Temporary failure in name resolution. */
  175. # define EAI_FAIL -4 /* Non-recoverable failure in name res. */
  176. # define EAI_NODATA -5 /* No address associated with NAME. */
  177. # define EAI_FAMILY -6 /* `ai_family' not supported. */
  178. # define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */
  179. # define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
  180. # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
  181. # define EAI_MEMORY -10 /* Memory allocation failure. */
  182. # define EAI_SYSTEM -11 /* System error returned in `errno'. */
  183. # define EAI_OVERFLOW -12 /* Argument buffer overflow. */
  184. # ifdef __USE_GNU
  185. # define EAI_INPROGRESS -100 /* Processing request in progress. */
  186. # define EAI_CANCELED -101 /* Request canceled. */
  187. # define EAI_NOTCANCELED -102 /* Request not canceled. */
  188. # define EAI_ALLDONE -103 /* All requests done. */
  189. # define EAI_INTR -104 /* Interrupted by a signal. */
  190. # define EAI_IDN_ENCODE -105 /* IDN encoding failed. */
  191. # endif
  192. #define NI_MAXHOST 1025
  193. #define NI_MAXSERV 32
  194. # define NI_NUMERICHOST 1 /* Don't try to look up hostname. */
  195. # define NI_NUMERICSERV 2 /* Don't convert port number to name. */
  196. # define NI_NOFQDN 4 /* Only return nodename portion. */
  197. # define NI_NAMEREQD 8 /* Don't return numeric addresses. */
  198. # define NI_DGRAM 16 /* Look up UDP service rather than TCP. */
  199. # ifdef __USE_GNU
  200. # define NI_IDN 32 /* Convert name from IDN format. */
  201. # define NI_IDN_ALLOW_UNASSIGNED 64 /* Don't reject unassigned Unicode
  202. code points. */
  203. # define NI_IDN_USE_STD3_ASCII_RULES 128 /* Validate strings according to
  204. STD3 rules. */
  205. # endif
  206. /* </from linux's netdb.h> */
  207. #define AI_DEFAULT (AI_V4MAPPED | AI_ADDRCONFIG)
  208. /*
  209. * Address families and Protocol families.
  210. */
  211. #ifndef AF_UNSPEC
  212. #define AF_UNSPEC AF_INET
  213. #endif
  214. #ifndef PF_UNSPEC
  215. #define PF_UNSPEC PF_INET
  216. #endif
  217. /* Nexenta OS(GNU/Solaris OS) defines `struct addrinfo' in netdb.h */
  218. #if !defined( __MINGW32__ ) && !defined( __sun )
  219. /*
  220. * struct addrinfo.
  221. */
  222. struct addrinfo {
  223. int ai_flags;
  224. int ai_family;
  225. int ai_socktype;
  226. int ai_protocol;
  227. socklen_t ai_addrlen;
  228. char *ai_canonname;
  229. struct sockaddr *ai_addr;
  230. struct addrinfo *ai_next;
  231. };
  232. #endif // !__MINGW32__ && !__sun
  233. /*
  234. * Functions.
  235. */
  236. #ifdef __STDC__
  237. const char *gai_strerror(int);
  238. void freeaddrinfo(struct addrinfo *);
  239. int getaddrinfo(const char *, const char *, const struct addrinfo *,
  240. struct addrinfo **);
  241. int getnameinfo(const struct sockaddr *, socklen_t, char *,
  242. socklen_t, char *, socklen_t, int);
  243. #else
  244. const char *gai_strerror();
  245. void freeaddrinfo();
  246. int getaddrinfo();
  247. int getnameinfo();
  248. #endif
  249. #ifdef __cplusplus
  250. };
  251. #endif /* __cplusplus */
  252. #endif /* not _D_GETADDRINFO_H */