PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/ffi/ares.lua

http://github.com/malkia/ufo
Lua | 245 lines | 224 code | 21 blank | 0 comment | 0 complexity | 76da87519c30a8f32c69753e347bf0ec MD5 | raw file
Possible License(s): MIT, GPL-3.0, LGPL-3.0, BSD-2-Clause, BSD-3-Clause, Apache-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception
  1. enum {
  2. ARES_VERSION_MAJOR = 1,
  3. ARES_VERSION_MINOR = 7,
  4. ARES_VERSION_PATCH = 5,
  5. ARES_VERSION = (ARES_VERSION_MAJOR<<16) | (ARES_VERSION_MINOR<<8) | (ARES_VERSION_PATCH)
  6. // ARES_COPYRIGHT = "2004 - 2010 Daniel Stenberg, <daniel@haxx.se>."
  7. // ARES_VERSION_STR = "1.7.5-DEV"
  8. ARES_SUCCESS 0
  9. ARES_ENODATA 1
  10. ARES_EFORMERR 2
  11. ARES_ESERVFAIL 3
  12. ARES_ENOTFOUND 4
  13. ARES_ENOTIMP 5
  14. ARES_EREFUSED 6
  15. ARES_EBADQUERY 7
  16. ARES_EBADNAME 8
  17. ARES_EBADFAMILY 9
  18. ARES_EBADRESP 10
  19. ARES_ECONNREFUSED 11
  20. ARES_ETIMEOUT 12
  21. ARES_EOF 13
  22. ARES_EFILE 14
  23. ARES_ENOMEM 15
  24. ARES_EDESTRUCTION 16
  25. ARES_EBADSTR 17
  26. ARES_EBADFLAGS 18
  27. ARES_ENONAME 19
  28. ARES_EBADHINTS 20
  29. ARES_ENOTINITIALIZED 21 /* introduced in 1.7.0 */
  30. ARES_ELOADIPHLPAPI 22 /* introduced in 1.7.0 */
  31. ARES_EADDRGETNETWORKPARAMS 23 /* introduced in 1.7.0 */
  32. ARES_ECANCELLED 24 /* introduced in 1.7.0 */
  33. ARES_FLAG_USEVC (1 << 0)
  34. ARES_FLAG_PRIMARY (1 << 1)
  35. ARES_FLAG_IGNTC (1 << 2)
  36. ARES_FLAG_NORECURSE (1 << 3)
  37. ARES_FLAG_STAYOPEN (1 << 4)
  38. ARES_FLAG_NOSEARCH (1 << 5)
  39. ARES_FLAG_NOALIASES (1 << 6)
  40. ARES_FLAG_NOCHECKRESP (1 << 7)
  41. ARES_OPT_FLAGS (1 << 0)
  42. ARES_OPT_TIMEOUT (1 << 1)
  43. ARES_OPT_TRIES (1 << 2)
  44. ARES_OPT_NDOTS (1 << 3)
  45. ARES_OPT_UDP_PORT (1 << 4)
  46. ARES_OPT_TCP_PORT (1 << 5)
  47. ARES_OPT_SERVERS (1 << 6)
  48. ARES_OPT_DOMAINS (1 << 7)
  49. ARES_OPT_LOOKUPS (1 << 8)
  50. ARES_OPT_SOCK_STATE_CB (1 << 9)
  51. ARES_OPT_SORTLIST (1 << 10)
  52. ARES_OPT_SOCK_SNDBUF (1 << 11)
  53. ARES_OPT_SOCK_RCVBUF (1 << 12)
  54. ARES_OPT_TIMEOUTMS (1 << 13)
  55. ARES_OPT_ROTATE (1 << 14)
  56. ARES_NI_NOFQDN (1 << 0)
  57. ARES_NI_NUMERICHOST (1 << 1)
  58. ARES_NI_NAMEREQD (1 << 2)
  59. ARES_NI_NUMERICSERV (1 << 3)
  60. ARES_NI_DGRAM (1 << 4)
  61. ARES_NI_TCP 0
  62. ARES_NI_UDP ARES_NI_DGRAM
  63. ARES_NI_SCTP (1 << 5)
  64. ARES_NI_DCCP (1 << 6)
  65. ARES_NI_NUMERICSCOPE (1 << 7)
  66. ARES_NI_LOOKUPHOST (1 << 8)
  67. ARES_NI_LOOKUPSERVICE (1 << 9)
  68. ARES_NI_IDN (1 << 10)
  69. ARES_NI_IDN_ALLOW_UNASSIGNED (1 << 11)
  70. ARES_NI_IDN_USE_STD3_ASCII_RULES (1 << 12)
  71. ARES_AI_CANONNAME (1 << 0)
  72. ARES_AI_NUMERICHOST (1 << 1)
  73. ARES_AI_PASSIVE (1 << 2)
  74. ARES_AI_NUMERICSERV (1 << 3)
  75. ARES_AI_V4MAPPED (1 << 4)
  76. ARES_AI_ALL (1 << 5)
  77. ARES_AI_ADDRCONFIG (1 << 6)
  78. ARES_AI_IDN (1 << 10)
  79. ARES_AI_IDN_ALLOW_UNASSIGNED (1 << 11)
  80. ARES_AI_IDN_USE_STD3_ASCII_RULES (1 << 12)
  81. ARES_AI_CANONIDN (1 << 13)
  82. ARES_AI_MASK (ARES_AI_CANONNAME|ARES_AI_NUMERICHOST|ARES_AI_PASSIVE| \
  83. ARES_AI_NUMERICSERV|ARES_AI_V4MAPPED|ARES_AI_ALL| \
  84. ARES_AI_ADDRCONFIG)
  85. ARES_GETSOCK_MAXNUM 16 /* ares_getsock() can return info about this
  86. many sockets */
  87. ARES_GETSOCK_READABLE(bits,num) (bits & (1<< (num)))
  88. ARES_GETSOCK_WRITABLE(bits,num) (bits & (1 << ((num) + \
  89. ARES_GETSOCK_MAXNUM)))
  90. ARES_LIB_INIT_NONE (0)
  91. ARES_LIB_INIT_WIN32 (1 << 0)
  92. ARES_LIB_INIT_ALL (ARES_LIB_INIT_WIN32)
  93. }
  94. /*
  95. * Typedef our socket type
  96. */
  97. #ifndef ares_socket_typedef
  98. #ifdef WIN32
  99. typedef SOCKET ares_socket_t;
  100. ARES_SOCKET_BAD INVALID_SOCKET
  101. #else
  102. typedef int ares_socket_t;
  103. ARES_SOCKET_BAD -1
  104. #endif
  105. ares_socket_typedef
  106. #endif /* ares_socket_typedef */
  107. typedef void (*ares_sock_state_cb)(void *data,
  108. ares_socket_t socket_fd,
  109. int readable,
  110. int writable);
  111. struct apattern;
  112. typedef struct ares_options {
  113. int flags;
  114. int timeout; /* in seconds or milliseconds, depending on options */
  115. int tries;
  116. int ndots;
  117. unsigned short udp_port;
  118. unsigned short tcp_port;
  119. int socket_send_buffer_size;
  120. int socket_receive_buffer_size;
  121. struct in_addr *servers;
  122. int nservers;
  123. char **domains;
  124. int ndomains;
  125. char *lookups;
  126. ares_sock_state_cb sock_state_cb;
  127. void *sock_state_cb_data;
  128. struct apattern *sortlist;
  129. int nsort;
  130. } ares_options;
  131. struct hostent;
  132. struct timeval;
  133. struct sockaddr;
  134. struct ares_channeldata;
  135. typedef struct ares_channeldata *ares_channel;
  136. typedef void (* ares_callback )( void *arg, int status, int timeouts, unsigned char *abuf, int alen);
  137. typedef void (* ares_host_callback )( void *arg, int status, int timeouts, struct hostent *hostent);
  138. typedef void (* ares_nameinfo_callback )( void *arg, int status, int timeouts, char *node, char *service);
  139. typedef int (* ares_sock_create_callback )( ares_socket_t socket_fd, int type, void *data);
  140. struct ares_in6_addr {
  141. union {
  142. unsigned char _S6_u8[16];
  143. } _S6_un;
  144. };
  145. struct ares_addrttl {
  146. struct in_addr ipaddr;
  147. int ttl;
  148. };
  149. typedef struct ares_addr6ttl {
  150. struct ares_in6_addr ip6addr;
  151. int ttl;
  152. } ares_addr6ttl;
  153. typedef struct ares_srv_reply {
  154. struct ares_srv_reply *next;
  155. char *host;
  156. unsigned short priority;
  157. unsigned short weight;
  158. unsigned short port;
  159. } ares_srv_reply;
  160. typedef struct ares_mx_reply {
  161. struct ares_mx_reply *next;
  162. char *host;
  163. unsigned short priority;
  164. } ares_mx_reply;
  165. typedef struct {
  166. struct ares_txt_reply *next;
  167. unsigned char *txt;
  168. size_t length; /* length excludes null termination */
  169. } arex_txt_reply;
  170. /* TODO: Hold port here as well. */
  171. struct ares_addr_node {
  172. struct ares_addr_node *next;
  173. int family;
  174. union {
  175. struct in_addr addr4;
  176. struct ares_in6_addr addr6;
  177. } addr;
  178. };
  179. typedef struct ares_timeval {
  180. int balh;
  181. } ares_timeval;
  182. int ares_library_init( int flags );
  183. void ares_library_cleanup( );
  184. const char* ares_version( int* version );
  185. int ares_init( ares_channel* );
  186. int ares_init_options( ares_channel*, ares_options* options, int optmask );
  187. int ares_save_options( ares_channel, ares_options* options, int* optmask );
  188. void ares_destroy_options( ares_options* options );
  189. int ares_dup( ares_channel*, ares_channel src );
  190. void ares_destroy( ares_channel );
  191. void ares_cancel( ares_channel );
  192. void ares_set_local_ip4( ares_channel, unsigned int local_ip );
  193. void ares_set_local_ip6( ares_channel, const unsigned char* local_ip6 );
  194. void ares_set_local_dev( ares_channel, const char* local_dev_name);
  195. void ares_set_socket_callback( ares_channel, ares_sock_create_callback callback, void *user_data );
  196. void ares_send( ares_channel, const unsigned char *qbuf, int qlen, ares_callback callback, void *arg );
  197. void ares_query( ares_channel, const char *name, int dnsclass, int type, ares_callback callback, void *arg );
  198. void ares_search( ares_channel, const char *name, int dnsclass, int type, ares_callback callback, void *arg);
  199. void ares_gethostbyname( ares_channel, const char *name, int family, ares_host_callback callback, void *arg );
  200. int ares_gethostbyname_file( ares_channel, const char *name, int family, struct hostent **host );
  201. void ares_gethostbyaddr( ares_channel, const void *addr, int addrlen, int family, ares_host_callback callback, void *arg);
  202. void ares_getnameinfo( ares_channel, const struct sockaddr *sa, ares_socklen_t salen, int flags, ares_nameinfo_callback callback, void *arg);
  203. int ares_fds( ares_channel, fd_set *read_fds, fd_set *write_fds );
  204. int ares_getsock( ares_channel, ares_socket_t *socks, int numsocks );
  205. ares_timeval* ares_timeout( ares_channel, ares_timeval* maxtv, ares_timeval* tv );
  206. void ares_process( ares_channel, fd_set *read_fds, fd_set *write_fds );
  207. void ares_process_fd( ares_channel, ares_socket_t read_fd, ares_socket_t write_fd );
  208. int ares_mkquery( const char *name, int dnsclass, int type, unsigned short id, int rd, unsigned char **buf, int *buflen );
  209. int ares_expand_name( const unsigned char *encoded, const unsigned char *abuf, int alen, char **s, long *enclen );
  210. int ares_expand_string( const unsigned char *encoded, const unsigned char *abuf, int alen, unsigned char **s, long *enclen );
  211. int ares_parse_a_reply( const unsigned char *abuf, int alen, struct hostent **host, struct ares_addrttl *addrttls, int *naddrttls );
  212. int ares_parse_aaaa_reply( const unsigned char *abuf, int alen, struct hostent **host, struct ares_addr6ttl *addrttls, int *naddrttls );
  213. int ares_parse_ptr_reply( const unsigned char *abuf, int alen, const void *addr, int addrlen, int family, struct hostent **host );
  214. int ares_parse_ns_reply( const unsigned char *abuf, int alen, struct hostent **host );
  215. int ares_parse_srv_reply( const unsigned char* abuf, int alen, struct ares_srv_reply** srv_out );
  216. int ares_parse_mx_reply( const unsigned char* abuf, int alen, struct ares_mx_reply** mx_out );
  217. int ares_parse_txt_reply( const unsigned char* abuf, int alen, struct ares_txt_reply** txt_out );
  218. void ares_free_string( void* str );
  219. void ares_free_hostent( struct hostent* host );
  220. void ares_free_data( void* dataptr );
  221. const char* ares_strerror( int code );
  222. int ares_set_servers( ares_channel, struct ares_addr_node *servers );
  223. int ares_set_servers_csv( ares_channel, const char* servers );
  224. int ares_get_servers( ares_channel, struct ares_addr_node **servers );