PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/bzflag/src/other/ares/ares.h

https://github.com/szakats/bzflag_mirror
C Header | 291 lines | 217 code | 32 blank | 42 comment | 5 complexity | a0552f3fc77af3b45b379ab549fd2b39 MD5 | raw file
Possible License(s): GPL-3.0, MPL-2.0-no-copyleft-exception, GPL-2.0, LGPL-2.1, LGPL-2.0, AGPL-1.0
  1. /* $Id$ */
  2. /* Copyright 1998 by the Massachusetts Institute of Technology.
  3. *
  4. * Permission to use, copy, modify, and distribute this
  5. * software and its documentation for any purpose and without
  6. * fee is hereby granted, provided that the above copyright
  7. * notice appear in all copies and that both that copyright
  8. * notice and this permission notice appear in supporting
  9. * documentation, and that the name of M.I.T. not be used in
  10. * advertising or publicity pertaining to distribution of the
  11. * software without specific, written prior permission.
  12. * M.I.T. makes no representations about the suitability of
  13. * this software for any purpose. It is provided "as is"
  14. * without express or implied warranty.
  15. */
  16. #ifndef ARES__H
  17. #define ARES__H
  18. /*
  19. * Define WIN32 when build target is Win32 API
  20. */
  21. #if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
  22. #define WIN32
  23. #endif
  24. #include <sys/types.h>
  25. #if defined(_AIX) || (defined(NETWARE) && defined(__NOVELL_LIBC__))
  26. /* HP-UX systems version 9, 10 and 11 lack sys/select.h and so does oldish
  27. libc5-based Linux systems. Only include it on system that are known to
  28. require it! */
  29. #include <sys/select.h>
  30. #endif
  31. #if (defined(NETWARE) && !defined(__NOVELL_LIBC__))
  32. #include <sys/bsdskt.h>
  33. #endif
  34. #if defined(WATT32)
  35. #include <netinet/in.h>
  36. #include <sys/socket.h>
  37. #include <tcp.h>
  38. #elif defined(WIN32)
  39. # ifndef WIN32_LEAN_AND_MEAN
  40. # define WIN32_LEAN_AND_MEAN
  41. # endif
  42. # include <windows.h>
  43. # include <winsock2.h>
  44. # include <ws2tcpip.h>
  45. #else
  46. #include <netinet/in.h>
  47. #include <sys/socket.h>
  48. #endif
  49. #ifdef __cplusplus
  50. extern "C" {
  51. #endif
  52. #define ARES_SUCCESS 0
  53. /* Server error codes (ARES_ENODATA indicates no relevant answer) */
  54. #define ARES_ENODATA 1
  55. #define ARES_EFORMERR 2
  56. #define ARES_ESERVFAIL 3
  57. #define ARES_ENOTFOUND 4
  58. #define ARES_ENOTIMP 5
  59. #define ARES_EREFUSED 6
  60. /* Locally generated error codes */
  61. #define ARES_EBADQUERY 7
  62. #define ARES_EBADNAME 8
  63. #define ARES_EBADFAMILY 9
  64. #define ARES_EBADRESP 10
  65. #define ARES_ECONNREFUSED 11
  66. #define ARES_ETIMEOUT 12
  67. #define ARES_EOF 13
  68. #define ARES_EFILE 14
  69. #define ARES_ENOMEM 15
  70. #define ARES_EDESTRUCTION 16
  71. #define ARES_EBADSTR 17
  72. /* ares_getnameinfo error codes */
  73. #define ARES_EBADFLAGS 18
  74. /* ares_getaddrinfo error codes */
  75. #define ARES_ENONAME 19
  76. #define ARES_EBADHINTS 20
  77. /* Flag values */
  78. #define ARES_FLAG_USEVC (1 << 0)
  79. #define ARES_FLAG_PRIMARY (1 << 1)
  80. #define ARES_FLAG_IGNTC (1 << 2)
  81. #define ARES_FLAG_NORECURSE (1 << 3)
  82. #define ARES_FLAG_STAYOPEN (1 << 4)
  83. #define ARES_FLAG_NOSEARCH (1 << 5)
  84. #define ARES_FLAG_NOALIASES (1 << 6)
  85. #define ARES_FLAG_NOCHECKRESP (1 << 7)
  86. /* Option mask values */
  87. #define ARES_OPT_FLAGS (1 << 0)
  88. #define ARES_OPT_TIMEOUT (1 << 1)
  89. #define ARES_OPT_TRIES (1 << 2)
  90. #define ARES_OPT_NDOTS (1 << 3)
  91. #define ARES_OPT_UDP_PORT (1 << 4)
  92. #define ARES_OPT_TCP_PORT (1 << 5)
  93. #define ARES_OPT_SERVERS (1 << 6)
  94. #define ARES_OPT_DOMAINS (1 << 7)
  95. #define ARES_OPT_LOOKUPS (1 << 8)
  96. #define ARES_OPT_SOCK_STATE_CB (1 << 9)
  97. #define ARES_OPT_SORTLIST (1 << 10)
  98. #define ARES_OPT_SOCK_SNDBUF (1 << 11)
  99. #define ARES_OPT_SOCK_RCVBUF (1 << 12)
  100. /* Nameinfo flag values */
  101. #define ARES_NI_NOFQDN (1 << 0)
  102. #define ARES_NI_NUMERICHOST (1 << 1)
  103. #define ARES_NI_NAMEREQD (1 << 2)
  104. #define ARES_NI_NUMERICSERV (1 << 3)
  105. #define ARES_NI_DGRAM (1 << 4)
  106. #define ARES_NI_TCP 0
  107. #define ARES_NI_UDP ARES_NI_DGRAM
  108. #define ARES_NI_SCTP (1 << 5)
  109. #define ARES_NI_DCCP (1 << 6)
  110. #define ARES_NI_NUMERICSCOPE (1 << 7)
  111. #define ARES_NI_LOOKUPHOST (1 << 8)
  112. #define ARES_NI_LOOKUPSERVICE (1 << 9)
  113. /* Reserved for future use */
  114. #define ARES_NI_IDN (1 << 10)
  115. #define ARES_NI_IDN_ALLOW_UNASSIGNED (1 << 11)
  116. #define ARES_NI_IDN_USE_STD3_ASCII_RULES (1 << 12)
  117. /* Addrinfo flag values */
  118. #define ARES_AI_CANONNAME (1 << 0)
  119. #define ARES_AI_NUMERICHOST (1 << 1)
  120. #define ARES_AI_PASSIVE (1 << 2)
  121. #define ARES_AI_NUMERICSERV (1 << 3)
  122. #define ARES_AI_V4MAPPED (1 << 4)
  123. #define ARES_AI_ALL (1 << 5)
  124. #define ARES_AI_ADDRCONFIG (1 << 6)
  125. /* Reserved for future use */
  126. #define ARES_AI_IDN (1 << 10)
  127. #define ARES_AI_IDN_ALLOW_UNASSIGNED (1 << 11)
  128. #define ARES_AI_IDN_USE_STD3_ASCII_RULES (1 << 12)
  129. #define ARES_AI_CANONIDN (1 << 13)
  130. #define ARES_AI_MASK (ARES_AI_CANONNAME|ARES_AI_NUMERICHOST|ARES_AI_PASSIVE| \
  131. ARES_AI_NUMERICSERV|ARES_AI_V4MAPPED|ARES_AI_ALL| \
  132. ARES_AI_ADDRCONFIG)
  133. #define ARES_GETSOCK_MAXNUM 16 /* ares_getsock() can return info about this
  134. many sockets */
  135. #define ARES_GETSOCK_READABLE(bits,num) (bits & (1<< (num)))
  136. #define ARES_GETSOCK_WRITABLE(bits,num) (bits & (1 << ((num) + \
  137. ARES_GETSOCK_MAXNUM)))
  138. /*
  139. * Typedef our socket type
  140. */
  141. #ifndef ares_socket_typedef
  142. #ifdef WIN32
  143. typedef SOCKET ares_socket_t;
  144. #define ARES_SOCKET_BAD INVALID_SOCKET
  145. #else
  146. typedef int ares_socket_t;
  147. #define ARES_SOCKET_BAD -1
  148. #endif
  149. #define ares_socket_typedef
  150. #endif /* ares_socket_typedef */
  151. typedef void (*ares_sock_state_cb)(void *data,
  152. ares_socket_t socket_fd,
  153. int readable,
  154. int writable);
  155. struct apattern;
  156. struct ares_options {
  157. int flags;
  158. int timeout;
  159. int tries;
  160. int ndots;
  161. unsigned short udp_port;
  162. unsigned short tcp_port;
  163. int socket_send_buffer_size;
  164. int socket_receive_buffer_size;
  165. struct in_addr *servers;
  166. int nservers;
  167. char **domains;
  168. int ndomains;
  169. char *lookups;
  170. ares_sock_state_cb sock_state_cb;
  171. void *sock_state_cb_data;
  172. struct apattern *sortlist;
  173. int nsort;
  174. };
  175. struct hostent;
  176. struct timeval;
  177. struct sockaddr;
  178. struct ares_channeldata;
  179. typedef struct ares_channeldata *ares_channel;
  180. typedef void (*ares_callback)(void *arg, int status, int timeouts,
  181. unsigned char *abuf, int alen);
  182. typedef void (*ares_host_callback)(void *arg, int status, int timeouts,
  183. struct hostent *hostent);
  184. typedef void (*ares_nameinfo_callback)(void *arg, int status, int timeouts,
  185. char *node, char *service);
  186. int ares_init(ares_channel *channelptr);
  187. int ares_init_options(ares_channel *channelptr, struct ares_options *options,
  188. int optmask);
  189. int ares_save_options(ares_channel channel, struct ares_options *options, int *optmask);
  190. void ares_destroy_options(struct ares_options *options);
  191. void ares_destroy(ares_channel channel);
  192. void ares_cancel(ares_channel channel);
  193. void ares_send(ares_channel channel, const unsigned char *qbuf, int qlen,
  194. ares_callback callback, void *arg);
  195. void ares_query(ares_channel channel, const char *name, int dnsclass,
  196. int type, ares_callback callback, void *arg);
  197. void ares_search(ares_channel channel, const char *name, int dnsclass,
  198. int type, ares_callback callback, void *arg);
  199. void ares_gethostbyname(ares_channel channel, const char *name, int family,
  200. ares_host_callback callback, void *arg);
  201. void ares_gethostbyaddr(ares_channel channel, const void *addr, int addrlen,
  202. int family, ares_host_callback callback, void *arg);
  203. void ares_getnameinfo(ares_channel channel, const struct sockaddr *sa,
  204. socklen_t salen, int flags,
  205. ares_nameinfo_callback callback,
  206. void *arg);
  207. int ares_fds(ares_channel channel, fd_set *read_fds, fd_set *write_fds);
  208. int ares_getsock(ares_channel channel, int *socks, int numsocks);
  209. struct timeval *ares_timeout(ares_channel channel, struct timeval *maxtv,
  210. struct timeval *tv);
  211. void ares_process(ares_channel channel, fd_set *read_fds, fd_set *write_fds);
  212. void ares_process_fd(ares_channel channel, ares_socket_t read_fd,
  213. ares_socket_t write_fd);
  214. int ares_mkquery(const char *name, int dnsclass, int type, unsigned short id,
  215. int rd, unsigned char **buf, int *buflen);
  216. int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
  217. int alen, char **s, long *enclen);
  218. int ares_expand_string(const unsigned char *encoded, const unsigned char *abuf,
  219. int alen, unsigned char **s, long *enclen);
  220. #ifndef s6_addr
  221. struct in6_addr {
  222. union {
  223. unsigned char _S6_u8[16];
  224. } _S6_un;
  225. };
  226. #define s6_addr _S6_un._S6_u8
  227. #endif
  228. struct addrttl {
  229. struct in_addr ipaddr;
  230. int ttl;
  231. };
  232. struct addr6ttl {
  233. struct in6_addr ip6addr;
  234. int ttl;
  235. };
  236. /*
  237. ** Parse the buffer, starting at *abuf and of length alen bytes, previously
  238. ** obtained from an ares_search call. Put the results in *host, if nonnull.
  239. ** Also, if addrttls is nonnull, put up to *naddrttls IPv4 addresses along with
  240. ** their TTLs in that array, and set *naddrttls to the number of addresses
  241. ** so written.
  242. */
  243. int ares_parse_a_reply(const unsigned char *abuf, int alen,
  244. struct hostent **host,
  245. struct addrttl *addrttls, int *naddrttls);
  246. int ares_parse_aaaa_reply(const unsigned char *abuf, int alen,
  247. struct hostent **host,
  248. struct addr6ttl *addrttls, int *naddrttls);
  249. int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
  250. int addrlen, int family, struct hostent **host);
  251. int ares_parse_ns_reply(const unsigned char *abuf, int alen,
  252. struct hostent **host);
  253. void ares_free_string(void *str);
  254. void ares_free_hostent(struct hostent *host);
  255. const char *ares_strerror(int code);
  256. #ifdef __cplusplus
  257. }
  258. #endif
  259. #endif /* ARES__H */