/fake-ares/ares.h

https://github.com/gamemaster101gr/libcurl · C Header · 190 lines · 137 code · 38 blank · 15 comment · 0 complexity · f82704153651cdcd28a2db7262a41853 MD5 · raw file

  1. #ifndef __ARES_H__
  2. #define __ARES_H__
  3. #include <netdb.h>
  4. #include <sys/select.h>
  5. #include <time.h>
  6. #include <ares_version.h>
  7. #define CARES_EXTERN
  8. #define ARES_SUCCESS 0
  9. /* Server error codes (ARES_ENODATA indicates no relevant answer) */
  10. #define ARES_ENODATA 1
  11. #define ARES_EFORMERR 2
  12. #define ARES_ESERVFAIL 3
  13. #define ARES_ENOTFOUND 4
  14. #define ARES_ENOTIMP 5
  15. #define ARES_EREFUSED 6
  16. /* Locally generated error codes */
  17. #define ARES_EBADQUERY 7
  18. #define ARES_EBADNAME 8
  19. #define ARES_EBADFAMILY 9
  20. #define ARES_EBADRESP 10
  21. #define ARES_ECONNREFUSED 11
  22. #define ARES_ETIMEOUT 12
  23. #define ARES_EOF 13
  24. #define ARES_EFILE 14
  25. #define ARES_ENOMEM 15
  26. #define ARES_EDESTRUCTION 16
  27. #define ARES_EBADSTR 17
  28. /* ares_getnameinfo error codes */
  29. #define ARES_EBADFLAGS 18
  30. /* ares_getaddrinfo error codes */
  31. #define ARES_ENONAME 19
  32. #define ARES_EBADHINTS 20
  33. /* Uninitialized library error code */
  34. #define ARES_ENOTINITIALIZED 21 /* introduced in 1.7.0 */
  35. /* ares_library_init error codes */
  36. #define ARES_ELOADIPHLPAPI 22 /* introduced in 1.7.0 */
  37. #define ARES_EADDRGETNETWORKPARAMS 23 /* introduced in 1.7.0 */
  38. /* More error codes */
  39. #define ARES_ECANCELLED 24 /* introduced in 1.7.0 */
  40. /* Flag values */
  41. #define ARES_FLAG_USEVC (1 << 0)
  42. #define ARES_FLAG_PRIMARY (1 << 1)
  43. #define ARES_FLAG_IGNTC (1 << 2)
  44. #define ARES_FLAG_NORECURSE (1 << 3)
  45. #define ARES_FLAG_STAYOPEN (1 << 4)
  46. #define ARES_FLAG_NOSEARCH (1 << 5)
  47. #define ARES_FLAG_NOALIASES (1 << 6)
  48. #define ARES_FLAG_NOCHECKRESP (1 << 7)
  49. /* Option mask values */
  50. #define ARES_OPT_FLAGS (1 << 0)
  51. #define ARES_OPT_TIMEOUT (1 << 1)
  52. #define ARES_OPT_TRIES (1 << 2)
  53. #define ARES_OPT_NDOTS (1 << 3)
  54. #define ARES_OPT_UDP_PORT (1 << 4)
  55. #define ARES_OPT_TCP_PORT (1 << 5)
  56. #define ARES_OPT_SERVERS (1 << 6)
  57. #define ARES_OPT_DOMAINS (1 << 7)
  58. #define ARES_OPT_LOOKUPS (1 << 8)
  59. #define ARES_OPT_SOCK_STATE_CB (1 << 9)
  60. #define ARES_OPT_SORTLIST (1 << 10)
  61. #define ARES_OPT_SOCK_SNDBUF (1 << 11)
  62. #define ARES_OPT_SOCK_RCVBUF (1 << 12)
  63. #define ARES_OPT_TIMEOUTMS (1 << 13)
  64. #define ARES_OPT_ROTATE (1 << 14)
  65. /* Nameinfo flag values */
  66. #define ARES_NI_NOFQDN (1 << 0)
  67. #define ARES_NI_NUMERICHOST (1 << 1)
  68. #define ARES_NI_NAMEREQD (1 << 2)
  69. #define ARES_NI_NUMERICSERV (1 << 3)
  70. #define ARES_NI_DGRAM (1 << 4)
  71. #define ARES_NI_TCP 0
  72. #define ARES_NI_UDP ARES_NI_DGRAM
  73. #define ARES_NI_SCTP (1 << 5)
  74. #define ARES_NI_DCCP (1 << 6)
  75. #define ARES_NI_NUMERICSCOPE (1 << 7)
  76. #define ARES_NI_LOOKUPHOST (1 << 8)
  77. #define ARES_NI_LOOKUPSERVICE (1 << 9)
  78. /* Reserved for future use */
  79. #define ARES_NI_IDN (1 << 10)
  80. #define ARES_NI_IDN_ALLOW_UNASSIGNED (1 << 11)
  81. #define ARES_NI_IDN_USE_STD3_ASCII_RULES (1 << 12)
  82. /* Addrinfo flag values */
  83. #define ARES_AI_CANONNAME (1 << 0)
  84. #define ARES_AI_NUMERICHOST (1 << 1)
  85. #define ARES_AI_PASSIVE (1 << 2)
  86. #define ARES_AI_NUMERICSERV (1 << 3)
  87. #define ARES_AI_V4MAPPED (1 << 4)
  88. #define ARES_AI_ALL (1 << 5)
  89. #define ARES_AI_ADDRCONFIG (1 << 6)
  90. /* Reserved for future use */
  91. #define ARES_AI_IDN (1 << 10)
  92. #define ARES_AI_IDN_ALLOW_UNASSIGNED (1 << 11)
  93. #define ARES_AI_IDN_USE_STD3_ASCII_RULES (1 << 12)
  94. #define ARES_AI_CANONIDN (1 << 13)
  95. #define ARES_AI_MASK (ARES_AI_CANONNAME|ARES_AI_NUMERICHOST|ARES_AI_PASSIVE| \
  96. ARES_AI_NUMERICSERV|ARES_AI_V4MAPPED|ARES_AI_ALL| \
  97. ARES_AI_ADDRCONFIG)
  98. #define ARES_GETSOCK_MAXNUM 16 /* ares_getsock() can return info about this
  99. many sockets */
  100. #define ARES_GETSOCK_READABLE(bits,num) (bits & (1<< (num)))
  101. #define ARES_GETSOCK_WRITABLE(bits,num) (bits & (1 << ((num) + \
  102. ARES_GETSOCK_MAXNUM)))
  103. /* c-ares library initialization flag values */
  104. #define ARES_LIB_INIT_NONE (0)
  105. #define ARES_LIB_INIT_WIN32 (1 << 0)
  106. #define ARES_LIB_INIT_ALL (ARES_LIB_INIT_WIN32)
  107. typedef void *ares_channel;
  108. typedef int ares_socket_t;
  109. #define ARES_SOCKET_BAD -1
  110. typedef void (*ares_host_callback)(void *arg,
  111. int status,
  112. int timeouts,
  113. struct hostent *hostent);
  114. #ifdef __cplusplus
  115. extern "C" {
  116. #endif
  117. CARES_EXTERN void ares_cancel(ares_channel channel);
  118. CARES_EXTERN void ares_destroy(ares_channel channel);
  119. CARES_EXTERN int ares_dup(ares_channel *dest,
  120. ares_channel src);
  121. CARES_EXTERN void ares_gethostbyaddr(ares_channel channel,
  122. const void *addr,
  123. int addrlen,
  124. int family,
  125. ares_host_callback callback,
  126. void *arg);
  127. CARES_EXTERN void ares_gethostbyname(ares_channel channel,
  128. const char *name,
  129. int family,
  130. ares_host_callback callback,
  131. void *arg);
  132. CARES_EXTERN int ares_getsock(ares_channel channel,
  133. ares_socket_t *socks,
  134. int numsocks);
  135. CARES_EXTERN int ares_init(ares_channel *channelptr);
  136. CARES_EXTERN void ares_library_cleanup(void);
  137. CARES_EXTERN int ares_library_init(int flags);
  138. CARES_EXTERN void ares_process(ares_channel channel,
  139. fd_set *read_fds,
  140. fd_set *write_fds);
  141. CARES_EXTERN void ares_process_fd(ares_channel channel,
  142. ares_socket_t read_fd,
  143. ares_socket_t write_fd);
  144. CARES_EXTERN const char *ares_strerror(int code);
  145. CARES_EXTERN struct timeval *ares_timeout(ares_channel channel,
  146. struct timeval *maxtv,
  147. struct timeval *tv);
  148. CARES_EXTERN const char *ares_version(int *version);
  149. #ifdef __cplusplus
  150. }
  151. #endif
  152. #endif