noderb 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (424) hide show
  1. data/LICENSE +19 -0
  2. data/README.md +25 -0
  3. data/ext/noderb_extension/extconf.rb +11 -0
  4. data/ext/noderb_extension/libuv/AUTHORS +11 -0
  5. data/ext/noderb_extension/libuv/LICENSE +48 -0
  6. data/ext/noderb_extension/libuv/Makefile +119 -0
  7. data/ext/noderb_extension/libuv/README +45 -0
  8. data/ext/noderb_extension/libuv/build/all.gyp +254 -0
  9. data/ext/noderb_extension/libuv/build/common.gypi +13 -0
  10. data/ext/noderb_extension/libuv/build/gyp_uv +43 -0
  11. data/ext/noderb_extension/libuv/config-mingw.mk +67 -0
  12. data/ext/noderb_extension/libuv/config-unix.mk +121 -0
  13. data/ext/noderb_extension/libuv/create-msvs-files.bat +14 -0
  14. data/ext/noderb_extension/libuv/deps/pthread-win32/ANNOUNCE +482 -0
  15. data/ext/noderb_extension/libuv/deps/pthread-win32/BUGS +141 -0
  16. data/ext/noderb_extension/libuv/deps/pthread-win32/Bmakefile +268 -0
  17. data/ext/noderb_extension/libuv/deps/pthread-win32/CONTRIBUTORS +140 -0
  18. data/ext/noderb_extension/libuv/deps/pthread-win32/COPYING +150 -0
  19. data/ext/noderb_extension/libuv/deps/pthread-win32/COPYING.LIB +504 -0
  20. data/ext/noderb_extension/libuv/deps/pthread-win32/ChangeLog +5194 -0
  21. data/ext/noderb_extension/libuv/deps/pthread-win32/FAQ +451 -0
  22. data/ext/noderb_extension/libuv/deps/pthread-win32/GNUmakefile +593 -0
  23. data/ext/noderb_extension/libuv/deps/pthread-win32/MAINTAINERS +4 -0
  24. data/ext/noderb_extension/libuv/deps/pthread-win32/Makefile +516 -0
  25. data/ext/noderb_extension/libuv/deps/pthread-win32/NEWS +1245 -0
  26. data/ext/noderb_extension/libuv/deps/pthread-win32/Nmakefile +24 -0
  27. data/ext/noderb_extension/libuv/deps/pthread-win32/Nmakefile.tests +260 -0
  28. data/ext/noderb_extension/libuv/deps/pthread-win32/PROGRESS +4 -0
  29. data/ext/noderb_extension/libuv/deps/pthread-win32/README +601 -0
  30. data/ext/noderb_extension/libuv/deps/pthread-win32/README.Borland +57 -0
  31. data/ext/noderb_extension/libuv/deps/pthread-win32/README.CV +3036 -0
  32. data/ext/noderb_extension/libuv/deps/pthread-win32/README.NONPORTABLE +783 -0
  33. data/ext/noderb_extension/libuv/deps/pthread-win32/README.Watcom +62 -0
  34. data/ext/noderb_extension/libuv/deps/pthread-win32/README.WinCE +6 -0
  35. data/ext/noderb_extension/libuv/deps/pthread-win32/TODO +7 -0
  36. data/ext/noderb_extension/libuv/deps/pthread-win32/WinCE-PORT +222 -0
  37. data/ext/noderb_extension/libuv/deps/pthread-win32/attr.c +53 -0
  38. data/ext/noderb_extension/libuv/deps/pthread-win32/autostatic.c +69 -0
  39. data/ext/noderb_extension/libuv/deps/pthread-win32/barrier.c +47 -0
  40. data/ext/noderb_extension/libuv/deps/pthread-win32/build/all.gyp +207 -0
  41. data/ext/noderb_extension/libuv/deps/pthread-win32/builddmc.bat +9 -0
  42. data/ext/noderb_extension/libuv/deps/pthread-win32/cancel.c +44 -0
  43. data/ext/noderb_extension/libuv/deps/pthread-win32/cleanup.c +148 -0
  44. data/ext/noderb_extension/libuv/deps/pthread-win32/condvar.c +50 -0
  45. data/ext/noderb_extension/libuv/deps/pthread-win32/config.h +153 -0
  46. data/ext/noderb_extension/libuv/deps/pthread-win32/context.h +74 -0
  47. data/ext/noderb_extension/libuv/deps/pthread-win32/create.c +308 -0
  48. data/ext/noderb_extension/libuv/deps/pthread-win32/dll.c +92 -0
  49. data/ext/noderb_extension/libuv/deps/pthread-win32/errno.c +94 -0
  50. data/ext/noderb_extension/libuv/deps/pthread-win32/exit.c +44 -0
  51. data/ext/noderb_extension/libuv/deps/pthread-win32/fork.c +39 -0
  52. data/ext/noderb_extension/libuv/deps/pthread-win32/global.c +107 -0
  53. data/ext/noderb_extension/libuv/deps/pthread-win32/implement.h +944 -0
  54. data/ext/noderb_extension/libuv/deps/pthread-win32/misc.c +50 -0
  55. data/ext/noderb_extension/libuv/deps/pthread-win32/mutex.c +62 -0
  56. data/ext/noderb_extension/libuv/deps/pthread-win32/need_errno.h +145 -0
  57. data/ext/noderb_extension/libuv/deps/pthread-win32/nonportable.c +47 -0
  58. data/ext/noderb_extension/libuv/deps/pthread-win32/private.c +54 -0
  59. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread.c +66 -0
  60. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread.dsp +142 -0
  61. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread.dsw +29 -0
  62. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread.h +1368 -0
  63. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_destroy.c +79 -0
  64. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_getdetachstate.c +86 -0
  65. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_getinheritsched.c +51 -0
  66. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_getschedparam.c +52 -0
  67. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_getschedpolicy.c +61 -0
  68. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_getscope.c +54 -0
  69. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_getstackaddr.c +97 -0
  70. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_getstacksize.c +100 -0
  71. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_init.c +117 -0
  72. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_setdetachstate.c +91 -0
  73. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_setinheritsched.c +57 -0
  74. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_setschedparam.c +63 -0
  75. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_setschedpolicy.c +55 -0
  76. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_setscope.c +62 -0
  77. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_setstackaddr.c +97 -0
  78. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_setstacksize.c +110 -0
  79. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_barrier_destroy.c +103 -0
  80. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_barrier_init.c +69 -0
  81. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_barrier_wait.c +104 -0
  82. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_barrierattr_destroy.c +83 -0
  83. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_barrierattr_getpshared.c +95 -0
  84. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_barrierattr_init.c +85 -0
  85. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_barrierattr_setpshared.c +119 -0
  86. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_cancel.c +189 -0
  87. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_cond_destroy.c +253 -0
  88. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_cond_init.c +167 -0
  89. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_cond_signal.c +231 -0
  90. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_cond_wait.c +567 -0
  91. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_condattr_destroy.c +86 -0
  92. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_condattr_getpshared.c +97 -0
  93. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_condattr_init.c +87 -0
  94. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_condattr_setpshared.c +117 -0
  95. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_delay_np.c +172 -0
  96. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_detach.c +136 -0
  97. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_equal.c +76 -0
  98. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_exit.c +106 -0
  99. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_getconcurrency.c +45 -0
  100. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_getschedparam.c +75 -0
  101. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_getspecific.c +87 -0
  102. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_getunique_np.c +47 -0
  103. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_getw32threadhandle_np.c +65 -0
  104. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_join.c +157 -0
  105. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_key_create.c +108 -0
  106. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_key_delete.c +125 -0
  107. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_kill.c +105 -0
  108. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutex_consistent.c +187 -0
  109. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutex_destroy.c +148 -0
  110. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutex_init.c +130 -0
  111. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutex_lock.c +269 -0
  112. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutex_timedlock.c +324 -0
  113. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutex_trylock.c +154 -0
  114. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutex_unlock.c +175 -0
  115. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutexattr_destroy.c +83 -0
  116. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutexattr_getkind_np.c +44 -0
  117. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutexattr_getpshared.c +95 -0
  118. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutexattr_getrobust.c +113 -0
  119. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutexattr_gettype.c +56 -0
  120. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutexattr_init.c +86 -0
  121. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutexattr_setkind_np.c +44 -0
  122. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutexattr_setpshared.c +119 -0
  123. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutexattr_setrobust.c +119 -0
  124. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutexattr_settype.c +143 -0
  125. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_num_processors_np.c +56 -0
  126. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_once.c +79 -0
  127. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_rwlock_destroy.c +143 -0
  128. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_rwlock_init.c +109 -0
  129. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_rwlock_rdlock.c +102 -0
  130. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_rwlock_timedrdlock.c +109 -0
  131. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_rwlock_timedwrlock.c +139 -0
  132. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_rwlock_tryrdlock.c +102 -0
  133. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_rwlock_trywrlock.c +122 -0
  134. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_rwlock_unlock.c +93 -0
  135. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_rwlock_wrlock.c +133 -0
  136. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_rwlockattr_destroy.c +84 -0
  137. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_rwlockattr_getpshared.c +97 -0
  138. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_rwlockattr_init.c +83 -0
  139. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_rwlockattr_setpshared.c +120 -0
  140. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_self.c +141 -0
  141. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_setcancelstate.c +125 -0
  142. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_setcanceltype.c +126 -0
  143. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_setconcurrency.c +53 -0
  144. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_setschedparam.c +123 -0
  145. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_setspecific.c +167 -0
  146. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_spin_destroy.c +111 -0
  147. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_spin_init.c +123 -0
  148. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_spin_lock.c +80 -0
  149. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_spin_trylock.c +77 -0
  150. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_spin_unlock.c +71 -0
  151. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_testcancel.c +103 -0
  152. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_timechange_handler_np.c +108 -0
  153. data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_win32_attach_detach_np.c +258 -0
  154. data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_MCS_lock.c +278 -0
  155. data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_callUserDestroyRoutines.c +232 -0
  156. data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_calloc.c +56 -0
  157. data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_cond_check_need_init.c +78 -0
  158. data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_getprocessors.c +91 -0
  159. data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_is_attr.c +47 -0
  160. data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_mutex_check_need_init.c +92 -0
  161. data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_new.c +94 -0
  162. data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_processInitialize.c +92 -0
  163. data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_processTerminate.c +105 -0
  164. data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_relmillisecs.c +132 -0
  165. data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_reuse.c +151 -0
  166. data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_rwlock_cancelwrwait.c +50 -0
  167. data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_rwlock_check_need_init.c +77 -0
  168. data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_semwait.c +135 -0
  169. data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_spinlock_check_need_init.c +78 -0
  170. data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_threadDestroy.c +79 -0
  171. data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_threadStart.c +357 -0
  172. data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_throw.c +189 -0
  173. data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_timespec.c +83 -0
  174. data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_tkAssocCreate.c +118 -0
  175. data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_tkAssocDestroy.c +114 -0
  176. data/ext/noderb_extension/libuv/deps/pthread-win32/rwlock.c +51 -0
  177. data/ext/noderb_extension/libuv/deps/pthread-win32/sched.c +53 -0
  178. data/ext/noderb_extension/libuv/deps/pthread-win32/sched.h +183 -0
  179. data/ext/noderb_extension/libuv/deps/pthread-win32/sched_get_priority_max.c +134 -0
  180. data/ext/noderb_extension/libuv/deps/pthread-win32/sched_get_priority_min.c +135 -0
  181. data/ext/noderb_extension/libuv/deps/pthread-win32/sched_getscheduler.c +71 -0
  182. data/ext/noderb_extension/libuv/deps/pthread-win32/sched_setscheduler.c +83 -0
  183. data/ext/noderb_extension/libuv/deps/pthread-win32/sched_yield.c +71 -0
  184. data/ext/noderb_extension/libuv/deps/pthread-win32/sem_close.c +58 -0
  185. data/ext/noderb_extension/libuv/deps/pthread-win32/sem_destroy.c +144 -0
  186. data/ext/noderb_extension/libuv/deps/pthread-win32/sem_getvalue.c +110 -0
  187. data/ext/noderb_extension/libuv/deps/pthread-win32/sem_init.c +169 -0
  188. data/ext/noderb_extension/libuv/deps/pthread-win32/sem_open.c +58 -0
  189. data/ext/noderb_extension/libuv/deps/pthread-win32/sem_post.c +128 -0
  190. data/ext/noderb_extension/libuv/deps/pthread-win32/sem_post_multiple.c +142 -0
  191. data/ext/noderb_extension/libuv/deps/pthread-win32/sem_timedwait.c +238 -0
  192. data/ext/noderb_extension/libuv/deps/pthread-win32/sem_trywait.c +117 -0
  193. data/ext/noderb_extension/libuv/deps/pthread-win32/sem_unlink.c +58 -0
  194. data/ext/noderb_extension/libuv/deps/pthread-win32/sem_wait.c +187 -0
  195. data/ext/noderb_extension/libuv/deps/pthread-win32/semaphore.c +69 -0
  196. data/ext/noderb_extension/libuv/deps/pthread-win32/semaphore.h +169 -0
  197. data/ext/noderb_extension/libuv/deps/pthread-win32/signal.c +179 -0
  198. data/ext/noderb_extension/libuv/deps/pthread-win32/spin.c +46 -0
  199. data/ext/noderb_extension/libuv/deps/pthread-win32/sync.c +43 -0
  200. data/ext/noderb_extension/libuv/deps/pthread-win32/tsd.c +44 -0
  201. data/ext/noderb_extension/libuv/deps/pthread-win32/version.rc +388 -0
  202. data/ext/noderb_extension/libuv/deps/pthread-win32/w32_CancelableWait.c +161 -0
  203. data/ext/noderb_extension/libuv/doc/desired-api.md +159 -0
  204. data/ext/noderb_extension/libuv/doc/iocp-links.html +574 -0
  205. data/ext/noderb_extension/libuv/include/ares.h +582 -0
  206. data/ext/noderb_extension/libuv/include/ares_version.h +24 -0
  207. data/ext/noderb_extension/libuv/include/eio.h +376 -0
  208. data/ext/noderb_extension/libuv/include/ev.h +835 -0
  209. data/ext/noderb_extension/libuv/include/ngx-queue.h +102 -0
  210. data/ext/noderb_extension/libuv/include/tree.h +762 -0
  211. data/ext/noderb_extension/libuv/include/uv-unix.h +138 -0
  212. data/ext/noderb_extension/libuv/include/uv-win.h +187 -0
  213. data/ext/noderb_extension/libuv/include/uv.h +635 -0
  214. data/ext/noderb_extension/libuv/src/ares/AUTHORS +37 -0
  215. data/ext/noderb_extension/libuv/src/ares/CHANGES +1198 -0
  216. data/ext/noderb_extension/libuv/src/ares/CMakeLists.txt +22 -0
  217. data/ext/noderb_extension/libuv/src/ares/NEWS +21 -0
  218. data/ext/noderb_extension/libuv/src/ares/README +60 -0
  219. data/ext/noderb_extension/libuv/src/ares/README.cares +13 -0
  220. data/ext/noderb_extension/libuv/src/ares/README.msvc +118 -0
  221. data/ext/noderb_extension/libuv/src/ares/README.node +21 -0
  222. data/ext/noderb_extension/libuv/src/ares/RELEASE-NOTES +25 -0
  223. data/ext/noderb_extension/libuv/src/ares/TODO +23 -0
  224. data/ext/noderb_extension/libuv/src/ares/ares__close_sockets.c +66 -0
  225. data/ext/noderb_extension/libuv/src/ares/ares__get_hostent.c +263 -0
  226. data/ext/noderb_extension/libuv/src/ares/ares__read_line.c +71 -0
  227. data/ext/noderb_extension/libuv/src/ares/ares__timeval.c +111 -0
  228. data/ext/noderb_extension/libuv/src/ares/ares_cancel.c +63 -0
  229. data/ext/noderb_extension/libuv/src/ares/ares_data.c +190 -0
  230. data/ext/noderb_extension/libuv/src/ares/ares_data.h +65 -0
  231. data/ext/noderb_extension/libuv/src/ares/ares_destroy.c +105 -0
  232. data/ext/noderb_extension/libuv/src/ares/ares_dns.h +90 -0
  233. data/ext/noderb_extension/libuv/src/ares/ares_expand_name.c +193 -0
  234. data/ext/noderb_extension/libuv/src/ares/ares_expand_string.c +75 -0
  235. data/ext/noderb_extension/libuv/src/ares/ares_fds.c +62 -0
  236. data/ext/noderb_extension/libuv/src/ares/ares_free_hostent.c +39 -0
  237. data/ext/noderb_extension/libuv/src/ares/ares_free_string.c +25 -0
  238. data/ext/noderb_extension/libuv/src/ares/ares_gethostbyaddr.c +292 -0
  239. data/ext/noderb_extension/libuv/src/ares/ares_gethostbyname.c +515 -0
  240. data/ext/noderb_extension/libuv/src/ares/ares_getnameinfo.c +426 -0
  241. data/ext/noderb_extension/libuv/src/ares/ares_getopt.c +122 -0
  242. data/ext/noderb_extension/libuv/src/ares/ares_getopt.h +53 -0
  243. data/ext/noderb_extension/libuv/src/ares/ares_getsock.c +72 -0
  244. data/ext/noderb_extension/libuv/src/ares/ares_init.c +1665 -0
  245. data/ext/noderb_extension/libuv/src/ares/ares_ipv6.h +78 -0
  246. data/ext/noderb_extension/libuv/src/ares/ares_library_init.c +132 -0
  247. data/ext/noderb_extension/libuv/src/ares/ares_library_init.h +39 -0
  248. data/ext/noderb_extension/libuv/src/ares/ares_llist.c +86 -0
  249. data/ext/noderb_extension/libuv/src/ares/ares_llist.h +42 -0
  250. data/ext/noderb_extension/libuv/src/ares/ares_mkquery.c +195 -0
  251. data/ext/noderb_extension/libuv/src/ares/ares_nowarn.c +59 -0
  252. data/ext/noderb_extension/libuv/src/ares/ares_nowarn.h +24 -0
  253. data/ext/noderb_extension/libuv/src/ares/ares_options.c +253 -0
  254. data/ext/noderb_extension/libuv/src/ares/ares_parse_a_reply.c +260 -0
  255. data/ext/noderb_extension/libuv/src/ares/ares_parse_aaaa_reply.c +256 -0
  256. data/ext/noderb_extension/libuv/src/ares/ares_parse_mx_reply.c +170 -0
  257. data/ext/noderb_extension/libuv/src/ares/ares_parse_ns_reply.c +182 -0
  258. data/ext/noderb_extension/libuv/src/ares/ares_parse_ptr_reply.c +208 -0
  259. data/ext/noderb_extension/libuv/src/ares/ares_parse_srv_reply.c +179 -0
  260. data/ext/noderb_extension/libuv/src/ares/ares_parse_txt_reply.c +201 -0
  261. data/ext/noderb_extension/libuv/src/ares/ares_private.h +351 -0
  262. data/ext/noderb_extension/libuv/src/ares/ares_process.c +1296 -0
  263. data/ext/noderb_extension/libuv/src/ares/ares_query.c +183 -0
  264. data/ext/noderb_extension/libuv/src/ares/ares_rules.h +144 -0
  265. data/ext/noderb_extension/libuv/src/ares/ares_search.c +322 -0
  266. data/ext/noderb_extension/libuv/src/ares/ares_send.c +134 -0
  267. data/ext/noderb_extension/libuv/src/ares/ares_setup.h +191 -0
  268. data/ext/noderb_extension/libuv/src/ares/ares_strcasecmp.c +66 -0
  269. data/ext/noderb_extension/libuv/src/ares/ares_strcasecmp.h +30 -0
  270. data/ext/noderb_extension/libuv/src/ares/ares_strdup.c +42 -0
  271. data/ext/noderb_extension/libuv/src/ares/ares_strdup.h +26 -0
  272. data/ext/noderb_extension/libuv/src/ares/ares_strerror.c +56 -0
  273. data/ext/noderb_extension/libuv/src/ares/ares_timeout.c +80 -0
  274. data/ext/noderb_extension/libuv/src/ares/ares_version.c +11 -0
  275. data/ext/noderb_extension/libuv/src/ares/ares_writev.c +79 -0
  276. data/ext/noderb_extension/libuv/src/ares/ares_writev.h +36 -0
  277. data/ext/noderb_extension/libuv/src/ares/bitncmp.c +59 -0
  278. data/ext/noderb_extension/libuv/src/ares/bitncmp.h +26 -0
  279. data/ext/noderb_extension/libuv/src/ares/config_cygwin/ares_config.h +510 -0
  280. data/ext/noderb_extension/libuv/src/ares/config_darwin/ares_config.h +510 -0
  281. data/ext/noderb_extension/libuv/src/ares/config_freebsd/ares_config.h +510 -0
  282. data/ext/noderb_extension/libuv/src/ares/config_linux/ares_config.h +510 -0
  283. data/ext/noderb_extension/libuv/src/ares/config_openbsd/ares_config.h +510 -0
  284. data/ext/noderb_extension/libuv/src/ares/config_sunos/ares_config.h +510 -0
  285. data/ext/noderb_extension/libuv/src/ares/config_win32/ares_config.h +369 -0
  286. data/ext/noderb_extension/libuv/src/ares/get_ver.awk +35 -0
  287. data/ext/noderb_extension/libuv/src/ares/inet_net_pton.c +450 -0
  288. data/ext/noderb_extension/libuv/src/ares/inet_net_pton.h +31 -0
  289. data/ext/noderb_extension/libuv/src/ares/inet_ntop.c +232 -0
  290. data/ext/noderb_extension/libuv/src/ares/inet_ntop.h +27 -0
  291. data/ext/noderb_extension/libuv/src/ares/nameser.h +193 -0
  292. data/ext/noderb_extension/libuv/src/ares/setup_once.h +488 -0
  293. data/ext/noderb_extension/libuv/src/ares/windows_port.c +22 -0
  294. data/ext/noderb_extension/libuv/src/eio/Changes +63 -0
  295. data/ext/noderb_extension/libuv/src/eio/LICENSE +36 -0
  296. data/ext/noderb_extension/libuv/src/eio/Makefile.am +15 -0
  297. data/ext/noderb_extension/libuv/src/eio/aclocal.m4 +8957 -0
  298. data/ext/noderb_extension/libuv/src/eio/autogen.sh +3 -0
  299. data/ext/noderb_extension/libuv/src/eio/config.h.in +86 -0
  300. data/ext/noderb_extension/libuv/src/eio/config_cygwin.h +77 -0
  301. data/ext/noderb_extension/libuv/src/eio/config_darwin.h +137 -0
  302. data/ext/noderb_extension/libuv/src/eio/config_freebsd.h +78 -0
  303. data/ext/noderb_extension/libuv/src/eio/config_linux.h +101 -0
  304. data/ext/noderb_extension/libuv/src/eio/config_sunos.h +81 -0
  305. data/ext/noderb_extension/libuv/src/eio/configure.ac +22 -0
  306. data/ext/noderb_extension/libuv/src/eio/demo.c +194 -0
  307. data/ext/noderb_extension/libuv/src/eio/ecb.h +370 -0
  308. data/ext/noderb_extension/libuv/src/eio/eio.3 +3428 -0
  309. data/ext/noderb_extension/libuv/src/eio/eio.c +2562 -0
  310. data/ext/noderb_extension/libuv/src/eio/eio.pod +969 -0
  311. data/ext/noderb_extension/libuv/src/eio/libeio.m4 +195 -0
  312. data/ext/noderb_extension/libuv/src/eio/xthread.h +164 -0
  313. data/ext/noderb_extension/libuv/src/ev/Changes +388 -0
  314. data/ext/noderb_extension/libuv/src/ev/LICENSE +36 -0
  315. data/ext/noderb_extension/libuv/src/ev/Makefile.am +18 -0
  316. data/ext/noderb_extension/libuv/src/ev/Makefile.in +771 -0
  317. data/ext/noderb_extension/libuv/src/ev/README +58 -0
  318. data/ext/noderb_extension/libuv/src/ev/aclocal.m4 +8957 -0
  319. data/ext/noderb_extension/libuv/src/ev/autogen.sh +6 -0
  320. data/ext/noderb_extension/libuv/src/ev/config.guess +1526 -0
  321. data/ext/noderb_extension/libuv/src/ev/config.h.in +125 -0
  322. data/ext/noderb_extension/libuv/src/ev/config.sub +1658 -0
  323. data/ext/noderb_extension/libuv/src/ev/config_cygwin.h +123 -0
  324. data/ext/noderb_extension/libuv/src/ev/config_darwin.h +122 -0
  325. data/ext/noderb_extension/libuv/src/ev/config_freebsd.h +120 -0
  326. data/ext/noderb_extension/libuv/src/ev/config_linux.h +130 -0
  327. data/ext/noderb_extension/libuv/src/ev/config_sunos.h +122 -0
  328. data/ext/noderb_extension/libuv/src/ev/configure +13037 -0
  329. data/ext/noderb_extension/libuv/src/ev/configure.ac +18 -0
  330. data/ext/noderb_extension/libuv/src/ev/depcomp +630 -0
  331. data/ext/noderb_extension/libuv/src/ev/ev++.h +816 -0
  332. data/ext/noderb_extension/libuv/src/ev/ev.3 +5311 -0
  333. data/ext/noderb_extension/libuv/src/ev/ev.c +3913 -0
  334. data/ext/noderb_extension/libuv/src/ev/ev.pod +5243 -0
  335. data/ext/noderb_extension/libuv/src/ev/ev_epoll.c +266 -0
  336. data/ext/noderb_extension/libuv/src/ev/ev_kqueue.c +198 -0
  337. data/ext/noderb_extension/libuv/src/ev/ev_poll.c +148 -0
  338. data/ext/noderb_extension/libuv/src/ev/ev_port.c +179 -0
  339. data/ext/noderb_extension/libuv/src/ev/ev_select.c +310 -0
  340. data/ext/noderb_extension/libuv/src/ev/ev_vars.h +203 -0
  341. data/ext/noderb_extension/libuv/src/ev/ev_win32.c +153 -0
  342. data/ext/noderb_extension/libuv/src/ev/ev_wrap.h +196 -0
  343. data/ext/noderb_extension/libuv/src/ev/event.c +402 -0
  344. data/ext/noderb_extension/libuv/src/ev/event.h +170 -0
  345. data/ext/noderb_extension/libuv/src/ev/install-sh +294 -0
  346. data/ext/noderb_extension/libuv/src/ev/libev.m4 +39 -0
  347. data/ext/noderb_extension/libuv/src/ev/ltmain.sh +8413 -0
  348. data/ext/noderb_extension/libuv/src/ev/missing +336 -0
  349. data/ext/noderb_extension/libuv/src/ev/mkinstalldirs +111 -0
  350. data/ext/noderb_extension/libuv/src/uv-common.c +172 -0
  351. data/ext/noderb_extension/libuv/src/uv-common.h +53 -0
  352. data/ext/noderb_extension/libuv/src/uv-cygwin.c +52 -0
  353. data/ext/noderb_extension/libuv/src/uv-darwin.c +64 -0
  354. data/ext/noderb_extension/libuv/src/uv-eio.c +113 -0
  355. data/ext/noderb_extension/libuv/src/uv-eio.h +13 -0
  356. data/ext/noderb_extension/libuv/src/uv-freebsd.c +65 -0
  357. data/ext/noderb_extension/libuv/src/uv-linux.c +51 -0
  358. data/ext/noderb_extension/libuv/src/uv-sunos.c +60 -0
  359. data/ext/noderb_extension/libuv/src/uv-unix.c +2408 -0
  360. data/ext/noderb_extension/libuv/src/win/async.c +129 -0
  361. data/ext/noderb_extension/libuv/src/win/cares.c +304 -0
  362. data/ext/noderb_extension/libuv/src/win/core.c +155 -0
  363. data/ext/noderb_extension/libuv/src/win/error.c +140 -0
  364. data/ext/noderb_extension/libuv/src/win/getaddrinfo.c +341 -0
  365. data/ext/noderb_extension/libuv/src/win/handle.c +176 -0
  366. data/ext/noderb_extension/libuv/src/win/internal.h +237 -0
  367. data/ext/noderb_extension/libuv/src/win/loop-watcher.c +128 -0
  368. data/ext/noderb_extension/libuv/src/win/pipe.c +828 -0
  369. data/ext/noderb_extension/libuv/src/win/process.c +936 -0
  370. data/ext/noderb_extension/libuv/src/win/req.c +141 -0
  371. data/ext/noderb_extension/libuv/src/win/stdio.c +75 -0
  372. data/ext/noderb_extension/libuv/src/win/stream.c +149 -0
  373. data/ext/noderb_extension/libuv/src/win/tcp.c +895 -0
  374. data/ext/noderb_extension/libuv/src/win/timer.c +269 -0
  375. data/ext/noderb_extension/libuv/src/win/util.c +82 -0
  376. data/ext/noderb_extension/libuv/test/benchmark-ares.c +117 -0
  377. data/ext/noderb_extension/libuv/test/benchmark-getaddrinfo.c +90 -0
  378. data/ext/noderb_extension/libuv/test/benchmark-list.h +77 -0
  379. data/ext/noderb_extension/libuv/test/benchmark-ping-pongs.c +210 -0
  380. data/ext/noderb_extension/libuv/test/benchmark-pound.c +237 -0
  381. data/ext/noderb_extension/libuv/test/benchmark-pump.c +459 -0
  382. data/ext/noderb_extension/libuv/test/benchmark-sizes.c +39 -0
  383. data/ext/noderb_extension/libuv/test/benchmark-spawn.c +154 -0
  384. data/ext/noderb_extension/libuv/test/dns-server.c +323 -0
  385. data/ext/noderb_extension/libuv/test/echo-server.c +299 -0
  386. data/ext/noderb_extension/libuv/test/run-benchmarks.c +64 -0
  387. data/ext/noderb_extension/libuv/test/run-tests.c +82 -0
  388. data/ext/noderb_extension/libuv/test/runner-unix.c +335 -0
  389. data/ext/noderb_extension/libuv/test/runner-unix.h +36 -0
  390. data/ext/noderb_extension/libuv/test/runner-win.c +343 -0
  391. data/ext/noderb_extension/libuv/test/runner-win.h +42 -0
  392. data/ext/noderb_extension/libuv/test/runner.c +311 -0
  393. data/ext/noderb_extension/libuv/test/runner.h +155 -0
  394. data/ext/noderb_extension/libuv/test/task.h +111 -0
  395. data/ext/noderb_extension/libuv/test/test-async.c +218 -0
  396. data/ext/noderb_extension/libuv/test/test-callback-stack.c +205 -0
  397. data/ext/noderb_extension/libuv/test/test-connection-fail.c +149 -0
  398. data/ext/noderb_extension/libuv/test/test-delayed-accept.c +198 -0
  399. data/ext/noderb_extension/libuv/test/test-fail-always.c +29 -0
  400. data/ext/noderb_extension/libuv/test/test-get-currentexe.c +53 -0
  401. data/ext/noderb_extension/libuv/test/test-getaddrinfo.c +110 -0
  402. data/ext/noderb_extension/libuv/test/test-gethostbyname.c +192 -0
  403. data/ext/noderb_extension/libuv/test/test-getsockname.c +196 -0
  404. data/ext/noderb_extension/libuv/test/test-hrtime.c +51 -0
  405. data/ext/noderb_extension/libuv/test/test-idle.c +83 -0
  406. data/ext/noderb_extension/libuv/test/test-list.h +165 -0
  407. data/ext/noderb_extension/libuv/test/test-loop-handles.c +361 -0
  408. data/ext/noderb_extension/libuv/test/test-pass-always.c +28 -0
  409. data/ext/noderb_extension/libuv/test/test-ping-pong.c +256 -0
  410. data/ext/noderb_extension/libuv/test/test-pipe-bind-error.c +148 -0
  411. data/ext/noderb_extension/libuv/test/test-ref.c +91 -0
  412. data/ext/noderb_extension/libuv/test/test-shutdown-eof.c +183 -0
  413. data/ext/noderb_extension/libuv/test/test-spawn.c +345 -0
  414. data/ext/noderb_extension/libuv/test/test-tcp-bind-error.c +204 -0
  415. data/ext/noderb_extension/libuv/test/test-tcp-bind6-error.c +164 -0
  416. data/ext/noderb_extension/libuv/test/test-tcp-writealot.c +198 -0
  417. data/ext/noderb_extension/libuv/test/test-timer-again.c +141 -0
  418. data/ext/noderb_extension/libuv/test/test-timer.c +134 -0
  419. data/ext/noderb_extension/noderb.c +340 -0
  420. data/ext/noderb_extension/noderb.h +2 -0
  421. data/lib/noderb/connection.rb +21 -0
  422. data/lib/noderb/process.rb +17 -0
  423. data/lib/noderb.rb +25 -0
  424. metadata +470 -0
@@ -0,0 +1,1665 @@
1
+
2
+ /* Copyright 1998 by the Massachusetts Institute of Technology.
3
+ * Copyright (C) 2007-2010 by Daniel Stenberg
4
+ *
5
+ * Permission to use, copy, modify, and distribute this
6
+ * software and its documentation for any purpose and without
7
+ * fee is hereby granted, provided that the above copyright
8
+ * notice appear in all copies and that both that copyright
9
+ * notice and this permission notice appear in supporting
10
+ * documentation, and that the name of M.I.T. not be used in
11
+ * advertising or publicity pertaining to distribution of the
12
+ * software without specific, written prior permission.
13
+ * M.I.T. makes no representations about the suitability of
14
+ * this software for any purpose. It is provided "as is"
15
+ * without express or implied warranty.
16
+ */
17
+
18
+ #include "ares_setup.h"
19
+
20
+ #ifdef USE_WINSOCK
21
+ #include <iphlpapi.h>
22
+ #endif
23
+
24
+ #ifdef HAVE_SYS_PARAM_H
25
+ #include <sys/param.h>
26
+ #endif
27
+
28
+ #ifdef HAVE_SYS_TIME_H
29
+ #include <sys/time.h>
30
+ #endif
31
+
32
+ #ifdef HAVE_SYS_SOCKET_H
33
+ #include <sys/socket.h>
34
+ #endif
35
+
36
+ #ifdef HAVE_NETINET_IN_H
37
+ #include <netinet/in.h>
38
+ #endif
39
+
40
+ #ifdef HAVE_NETDB_H
41
+ #include <netdb.h>
42
+ #endif
43
+
44
+ #ifdef HAVE_ARPA_INET_H
45
+ #include <arpa/inet.h>
46
+ #endif
47
+
48
+ #ifdef HAVE_ARPA_NAMESER_H
49
+ # include <arpa/nameser.h>
50
+ #else
51
+ # include "nameser.h"
52
+ #endif
53
+ #ifdef HAVE_ARPA_NAMESER_COMPAT_H
54
+ # include <arpa/nameser_compat.h>
55
+ #endif
56
+
57
+ #ifdef HAVE_UNISTD_H
58
+ #include <unistd.h>
59
+ #endif
60
+
61
+ #include <stdio.h>
62
+ #include <stdlib.h>
63
+ #include <string.h>
64
+ #include <ctype.h>
65
+ #include <time.h>
66
+ #include <errno.h>
67
+ #include "ares.h"
68
+ #include "inet_net_pton.h"
69
+ #include "ares_library_init.h"
70
+ #include "ares_nowarn.h"
71
+ #include "ares_private.h"
72
+
73
+ #ifdef ANDROID
74
+ #include <sys/system_properties.h>
75
+ #endif
76
+
77
+ #ifdef WATT32
78
+ #undef WIN32 /* Redefined in MingW/MSVC headers */
79
+ #endif
80
+
81
+ static int init_by_options(ares_channel channel, const struct ares_options *options,
82
+ int optmask);
83
+ static int init_by_environment(ares_channel channel);
84
+ static int init_by_resolv_conf(ares_channel channel);
85
+ static int init_by_defaults(ares_channel channel);
86
+
87
+ #ifndef WATT32
88
+ static int config_nameserver(struct server_state **servers, int *nservers,
89
+ char *str);
90
+ #endif
91
+ static int set_search(ares_channel channel, const char *str);
92
+ static int set_options(ares_channel channel, const char *str);
93
+ static const char *try_option(const char *p, const char *q, const char *opt);
94
+ static int init_id_key(rc4_key* key,int key_data_len);
95
+
96
+ #if !defined(WIN32) && !defined(WATT32)
97
+ static int sortlist_alloc(struct apattern **sortlist, int *nsort, struct apattern *pat);
98
+ static int ip_addr(const char *s, ssize_t len, struct in_addr *addr);
99
+ static void natural_mask(struct apattern *pat);
100
+ static int config_domain(ares_channel channel, char *str);
101
+ static int config_lookup(ares_channel channel, const char *str,
102
+ const char *bindch, const char *filech);
103
+ static int config_sortlist(struct apattern **sortlist, int *nsort,
104
+ const char *str);
105
+ static char *try_config(char *s, const char *opt);
106
+ #endif
107
+
108
+ #define ARES_CONFIG_CHECK(x) (x->lookups && x->nsort > -1 && \
109
+ x->nservers > -1 && \
110
+ x->ndomains > -1 && \
111
+ x->ndots > -1 && x->timeout > -1 && \
112
+ x->tries > -1)
113
+
114
+ int ares_init(ares_channel *channelptr)
115
+ {
116
+ return ares_init_options(channelptr, NULL, 0);
117
+ }
118
+
119
+ int ares_init_options(ares_channel *channelptr, struct ares_options *options,
120
+ int optmask)
121
+ {
122
+ ares_channel channel;
123
+ int i;
124
+ int status = ARES_SUCCESS;
125
+ struct timeval now;
126
+
127
+ #ifdef CURLDEBUG
128
+ const char *env = getenv("CARES_MEMDEBUG");
129
+
130
+ if (env)
131
+ curl_memdebug(env);
132
+ env = getenv("CARES_MEMLIMIT");
133
+ if (env) {
134
+ char *endptr;
135
+ long num = strtol(env, &endptr, 10);
136
+ if((endptr != env) && (endptr == env + strlen(env)) && (num > 0))
137
+ curl_memlimit(num);
138
+ }
139
+ #endif
140
+
141
+ if (ares_library_initialized() != ARES_SUCCESS)
142
+ return ARES_ENOTINITIALIZED;
143
+
144
+ channel = malloc(sizeof(struct ares_channeldata));
145
+ if (!channel) {
146
+ *channelptr = NULL;
147
+ return ARES_ENOMEM;
148
+ }
149
+
150
+ now = ares__tvnow();
151
+
152
+ /* Set everything to distinguished values so we know they haven't
153
+ * been set yet.
154
+ */
155
+ channel->flags = -1;
156
+ channel->timeout = -1;
157
+ channel->tries = -1;
158
+ channel->ndots = -1;
159
+ channel->rotate = -1;
160
+ channel->udp_port = -1;
161
+ channel->tcp_port = -1;
162
+ channel->socket_send_buffer_size = -1;
163
+ channel->socket_receive_buffer_size = -1;
164
+ channel->nservers = -1;
165
+ channel->ndomains = -1;
166
+ channel->nsort = -1;
167
+ channel->tcp_connection_generation = 0;
168
+ channel->lookups = NULL;
169
+ channel->domains = NULL;
170
+ channel->sortlist = NULL;
171
+ channel->servers = NULL;
172
+ channel->sock_state_cb = NULL;
173
+ channel->sock_state_cb_data = NULL;
174
+ channel->sock_create_cb = NULL;
175
+ channel->sock_create_cb_data = NULL;
176
+
177
+ channel->last_server = 0;
178
+ channel->last_timeout_processed = (time_t)now.tv_sec;
179
+
180
+ memset(&channel->local_dev_name, 0, sizeof(channel->local_dev_name));
181
+ channel->local_ip4 = 0;
182
+ memset(&channel->local_ip6, 0, sizeof(channel->local_ip6));
183
+
184
+ /* Initialize our lists of queries */
185
+ ares__init_list_head(&(channel->all_queries));
186
+ for (i = 0; i < ARES_QID_TABLE_SIZE; i++)
187
+ {
188
+ ares__init_list_head(&(channel->queries_by_qid[i]));
189
+ }
190
+ for (i = 0; i < ARES_TIMEOUT_TABLE_SIZE; i++)
191
+ {
192
+ ares__init_list_head(&(channel->queries_by_timeout[i]));
193
+ }
194
+
195
+ /* Initialize configuration by each of the four sources, from highest
196
+ * precedence to lowest.
197
+ */
198
+
199
+ if (status == ARES_SUCCESS) {
200
+ status = init_by_options(channel, options, optmask);
201
+ if (status != ARES_SUCCESS)
202
+ DEBUGF(fprintf(stderr, "Error: init_by_options failed: %s\n",
203
+ ares_strerror(status)));
204
+ }
205
+ if (status == ARES_SUCCESS) {
206
+ status = init_by_environment(channel);
207
+ if (status != ARES_SUCCESS)
208
+ DEBUGF(fprintf(stderr, "Error: init_by_environment failed: %s\n",
209
+ ares_strerror(status)));
210
+ }
211
+ if (status == ARES_SUCCESS) {
212
+ status = init_by_resolv_conf(channel);
213
+ if (status != ARES_SUCCESS)
214
+ DEBUGF(fprintf(stderr, "Error: init_by_resolv_conf failed: %s\n",
215
+ ares_strerror(status)));
216
+ }
217
+
218
+ /*
219
+ * No matter what failed or succeeded, seed defaults to provide
220
+ * useful behavior for things that we missed.
221
+ */
222
+ status = init_by_defaults(channel);
223
+ if (status != ARES_SUCCESS)
224
+ DEBUGF(fprintf(stderr, "Error: init_by_defaults failed: %s\n",
225
+ ares_strerror(status)));
226
+
227
+ /* Generate random key */
228
+
229
+ if (status == ARES_SUCCESS) {
230
+ status = init_id_key(&channel->id_key, ARES_ID_KEY_LEN);
231
+ if (status == ARES_SUCCESS)
232
+ channel->next_id = ares__generate_new_id(&channel->id_key);
233
+ else
234
+ DEBUGF(fprintf(stderr, "Error: init_id_key failed: %s\n",
235
+ ares_strerror(status)));
236
+ }
237
+
238
+ if (status != ARES_SUCCESS)
239
+ {
240
+ /* Something failed; clean up memory we may have allocated. */
241
+ if (channel->servers)
242
+ free(channel->servers);
243
+ if (channel->domains)
244
+ {
245
+ for (i = 0; i < channel->ndomains; i++)
246
+ free(channel->domains[i]);
247
+ free(channel->domains);
248
+ }
249
+ if (channel->sortlist)
250
+ free(channel->sortlist);
251
+ if(channel->lookups)
252
+ free(channel->lookups);
253
+ free(channel);
254
+ return status;
255
+ }
256
+
257
+ /* Trim to one server if ARES_FLAG_PRIMARY is set. */
258
+ if ((channel->flags & ARES_FLAG_PRIMARY) && channel->nservers > 1)
259
+ channel->nservers = 1;
260
+
261
+ ares__init_servers_state(channel);
262
+
263
+ *channelptr = channel;
264
+ return ARES_SUCCESS;
265
+ }
266
+
267
+ /* ares_dup() duplicates a channel handle with all its options and returns a
268
+ new channel handle */
269
+ int ares_dup(ares_channel *dest, ares_channel src)
270
+ {
271
+ struct ares_options opts;
272
+ struct ares_addr_node *servers;
273
+ int ipv6_nservers = 0;
274
+ int i, rc;
275
+ int optmask;
276
+
277
+ *dest = NULL; /* in case of failure return NULL explicitly */
278
+
279
+ /* First get the options supported by the old ares_save_options() function,
280
+ which is most of them */
281
+ rc = ares_save_options(src, &opts, &optmask);
282
+ if(rc)
283
+ return rc;
284
+
285
+ /* Then create the new channel with those options */
286
+ rc = ares_init_options(dest, &opts, optmask);
287
+
288
+ /* destroy the options copy to not leak any memory */
289
+ ares_destroy_options(&opts);
290
+
291
+ if(rc)
292
+ return rc;
293
+
294
+ /* Now clone the options that ares_save_options() doesn't support. */
295
+ (*dest)->sock_create_cb = src->sock_create_cb;
296
+ (*dest)->sock_create_cb_data = src->sock_create_cb_data;
297
+
298
+ strncpy((*dest)->local_dev_name, src->local_dev_name, sizeof(src->local_dev_name));
299
+ (*dest)->local_ip4 = src->local_ip4;
300
+ memcpy((*dest)->local_ip6, src->local_ip6, sizeof(src->local_ip6));
301
+
302
+ /* Full name server cloning required when not all are IPv4 */
303
+ for (i = 0; i < src->nservers; i++)
304
+ {
305
+ if (src->servers[i].addr.family != AF_INET) {
306
+ ipv6_nservers++;
307
+ break;
308
+ }
309
+ }
310
+ if (ipv6_nservers) {
311
+ rc = ares_get_servers(src, &servers);
312
+ if (rc != ARES_SUCCESS)
313
+ return rc;
314
+ rc = ares_set_servers(*dest, servers);
315
+ ares_free_data(servers);
316
+ if (rc != ARES_SUCCESS)
317
+ return rc;
318
+ }
319
+
320
+ return ARES_SUCCESS; /* everything went fine */
321
+ }
322
+
323
+ /* Save options from initialized channel */
324
+ int ares_save_options(ares_channel channel, struct ares_options *options,
325
+ int *optmask)
326
+ {
327
+ int i, j;
328
+ int ipv4_nservers = 0;
329
+
330
+ /* Zero everything out */
331
+ memset(options, 0, sizeof(struct ares_options));
332
+
333
+ if (!ARES_CONFIG_CHECK(channel))
334
+ return ARES_ENODATA;
335
+
336
+ /* Traditionally the optmask wasn't saved in the channel struct so it was
337
+ recreated here. ROTATE is the first option that has no struct field of
338
+ its own in the public config struct */
339
+ (*optmask) = (ARES_OPT_FLAGS|ARES_OPT_TRIES|ARES_OPT_NDOTS|
340
+ ARES_OPT_UDP_PORT|ARES_OPT_TCP_PORT|ARES_OPT_SOCK_STATE_CB|
341
+ ARES_OPT_SERVERS|ARES_OPT_DOMAINS|ARES_OPT_LOOKUPS|
342
+ ARES_OPT_SORTLIST|ARES_OPT_TIMEOUTMS) |
343
+ (channel->optmask & ARES_OPT_ROTATE);
344
+
345
+ /* Copy easy stuff */
346
+ options->flags = channel->flags;
347
+
348
+ /* We return full millisecond resolution but that's only because we don't
349
+ set the ARES_OPT_TIMEOUT anymore, only the new ARES_OPT_TIMEOUTMS */
350
+ options->timeout = channel->timeout;
351
+ options->tries = channel->tries;
352
+ options->ndots = channel->ndots;
353
+ options->udp_port = (unsigned short)channel->udp_port;
354
+ options->tcp_port = (unsigned short)channel->tcp_port;
355
+ options->sock_state_cb = channel->sock_state_cb;
356
+ options->sock_state_cb_data = channel->sock_state_cb_data;
357
+
358
+ /* Copy IPv4 servers */
359
+ if (channel->nservers) {
360
+ for (i = 0; i < channel->nservers; i++)
361
+ {
362
+ if (channel->servers[i].addr.family == AF_INET)
363
+ ipv4_nservers++;
364
+ }
365
+ if (ipv4_nservers) {
366
+ options->servers = malloc(ipv4_nservers * sizeof(struct server_state));
367
+ if (!options->servers)
368
+ return ARES_ENOMEM;
369
+ for (i = j = 0; i < channel->nservers; i++)
370
+ {
371
+ if (channel->servers[i].addr.family == AF_INET)
372
+ memcpy(&options->servers[j++],
373
+ &channel->servers[i].addr.addrV4,
374
+ sizeof(channel->servers[i].addr.addrV4));
375
+ }
376
+ }
377
+ }
378
+ options->nservers = ipv4_nservers;
379
+
380
+ /* copy domains */
381
+ if (channel->ndomains) {
382
+ options->domains = malloc(channel->ndomains * sizeof(char *));
383
+ if (!options->domains)
384
+ return ARES_ENOMEM;
385
+
386
+ for (i = 0; i < channel->ndomains; i++)
387
+ {
388
+ options->ndomains = i;
389
+ options->domains[i] = strdup(channel->domains[i]);
390
+ if (!options->domains[i])
391
+ return ARES_ENOMEM;
392
+ }
393
+ }
394
+ options->ndomains = channel->ndomains;
395
+
396
+ /* copy lookups */
397
+ if (channel->lookups) {
398
+ options->lookups = strdup(channel->lookups);
399
+ if (!options->lookups && channel->lookups)
400
+ return ARES_ENOMEM;
401
+ }
402
+
403
+ /* copy sortlist */
404
+ if (channel->nsort) {
405
+ options->sortlist = malloc(channel->nsort * sizeof(struct apattern));
406
+ if (!options->sortlist)
407
+ return ARES_ENOMEM;
408
+ for (i = 0; i < channel->nsort; i++)
409
+ options->sortlist[i] = channel->sortlist[i];
410
+ }
411
+ options->nsort = channel->nsort;
412
+
413
+ return ARES_SUCCESS;
414
+ }
415
+
416
+ static int init_by_options(ares_channel channel,
417
+ const struct ares_options *options,
418
+ int optmask)
419
+ {
420
+ int i;
421
+
422
+ /* Easy stuff. */
423
+ if ((optmask & ARES_OPT_FLAGS) && channel->flags == -1)
424
+ channel->flags = options->flags;
425
+ if ((optmask & ARES_OPT_TIMEOUTMS) && channel->timeout == -1)
426
+ channel->timeout = options->timeout;
427
+ else if ((optmask & ARES_OPT_TIMEOUT) && channel->timeout == -1)
428
+ channel->timeout = options->timeout * 1000;
429
+ if ((optmask & ARES_OPT_TRIES) && channel->tries == -1)
430
+ channel->tries = options->tries;
431
+ if ((optmask & ARES_OPT_NDOTS) && channel->ndots == -1)
432
+ channel->ndots = options->ndots;
433
+ if ((optmask & ARES_OPT_ROTATE) && channel->rotate == -1)
434
+ channel->rotate = 1;
435
+ if ((optmask & ARES_OPT_UDP_PORT) && channel->udp_port == -1)
436
+ channel->udp_port = options->udp_port;
437
+ if ((optmask & ARES_OPT_TCP_PORT) && channel->tcp_port == -1)
438
+ channel->tcp_port = options->tcp_port;
439
+ if ((optmask & ARES_OPT_SOCK_STATE_CB) && channel->sock_state_cb == NULL)
440
+ {
441
+ channel->sock_state_cb = options->sock_state_cb;
442
+ channel->sock_state_cb_data = options->sock_state_cb_data;
443
+ }
444
+ if ((optmask & ARES_OPT_SOCK_SNDBUF)
445
+ && channel->socket_send_buffer_size == -1)
446
+ channel->socket_send_buffer_size = options->socket_send_buffer_size;
447
+ if ((optmask & ARES_OPT_SOCK_RCVBUF)
448
+ && channel->socket_receive_buffer_size == -1)
449
+ channel->socket_receive_buffer_size = options->socket_receive_buffer_size;
450
+
451
+ /* Copy the IPv4 servers, if given. */
452
+ if ((optmask & ARES_OPT_SERVERS) && channel->nservers == -1)
453
+ {
454
+ /* Avoid zero size allocations at any cost */
455
+ if (options->nservers > 0)
456
+ {
457
+ channel->servers =
458
+ malloc(options->nservers * sizeof(struct server_state));
459
+ if (!channel->servers)
460
+ return ARES_ENOMEM;
461
+ for (i = 0; i < options->nservers; i++)
462
+ {
463
+ channel->servers[i].addr.family = AF_INET;
464
+ memcpy(&channel->servers[i].addr.addrV4,
465
+ &options->servers[i],
466
+ sizeof(channel->servers[i].addr.addrV4));
467
+ }
468
+ }
469
+ channel->nservers = options->nservers;
470
+ }
471
+
472
+ /* Copy the domains, if given. Keep channel->ndomains consistent so
473
+ * we can clean up in case of error.
474
+ */
475
+ if ((optmask & ARES_OPT_DOMAINS) && channel->ndomains == -1)
476
+ {
477
+ /* Avoid zero size allocations at any cost */
478
+ if (options->ndomains > 0)
479
+ {
480
+ channel->domains = malloc(options->ndomains * sizeof(char *));
481
+ if (!channel->domains)
482
+ return ARES_ENOMEM;
483
+ for (i = 0; i < options->ndomains; i++)
484
+ {
485
+ channel->ndomains = i;
486
+ channel->domains[i] = strdup(options->domains[i]);
487
+ if (!channel->domains[i])
488
+ return ARES_ENOMEM;
489
+ }
490
+ }
491
+ channel->ndomains = options->ndomains;
492
+ }
493
+
494
+ /* Set lookups, if given. */
495
+ if ((optmask & ARES_OPT_LOOKUPS) && !channel->lookups)
496
+ {
497
+ channel->lookups = strdup(options->lookups);
498
+ if (!channel->lookups)
499
+ return ARES_ENOMEM;
500
+ }
501
+
502
+ /* copy sortlist */
503
+ if ((optmask & ARES_OPT_SORTLIST) && (channel->nsort == -1) &&
504
+ (options->nsort>0)) {
505
+ channel->sortlist = malloc(options->nsort * sizeof(struct apattern));
506
+ if (!channel->sortlist)
507
+ return ARES_ENOMEM;
508
+ for (i = 0; i < options->nsort; i++)
509
+ channel->sortlist[i] = options->sortlist[i];
510
+ channel->nsort = options->nsort;
511
+ }
512
+
513
+ channel->optmask = optmask;
514
+
515
+ return ARES_SUCCESS;
516
+ }
517
+
518
+ static int init_by_environment(ares_channel channel)
519
+ {
520
+ const char *localdomain, *res_options;
521
+ int status;
522
+
523
+ localdomain = getenv("LOCALDOMAIN");
524
+ if (localdomain && channel->ndomains == -1)
525
+ {
526
+ status = set_search(channel, localdomain);
527
+ if (status != ARES_SUCCESS)
528
+ return status;
529
+ }
530
+
531
+ res_options = getenv("RES_OPTIONS");
532
+ if (res_options)
533
+ {
534
+ status = set_options(channel, res_options);
535
+ if (status != ARES_SUCCESS)
536
+ return status;
537
+ }
538
+
539
+ return ARES_SUCCESS;
540
+ }
541
+
542
+ #ifdef WIN32
543
+ /*
544
+ * Warning: returns a dynamically allocated buffer, the user MUST
545
+ * use free() if the function returns 1
546
+ */
547
+ static int get_res_nt(HKEY hKey, const char *subkey, char **obuf)
548
+ {
549
+ /* Test for the size we need */
550
+ DWORD size = 0;
551
+ int result;
552
+
553
+ result = RegQueryValueEx(hKey, subkey, 0, NULL, NULL, &size);
554
+ if ((result != ERROR_SUCCESS && result != ERROR_MORE_DATA) || !size)
555
+ return 0;
556
+ *obuf = malloc(size+1);
557
+ if (!*obuf)
558
+ return 0;
559
+
560
+ if (RegQueryValueEx(hKey, subkey, 0, NULL,
561
+ (LPBYTE)*obuf, &size) != ERROR_SUCCESS)
562
+ {
563
+ free(*obuf);
564
+ return 0;
565
+ }
566
+ if (size == 1)
567
+ {
568
+ free(*obuf);
569
+ return 0;
570
+ }
571
+ return 1;
572
+ }
573
+
574
+ static int get_res_interfaces_nt(HKEY hKey, const char *subkey, char **obuf)
575
+ {
576
+ char enumbuf[39]; /* GUIDs are 38 chars + 1 for NULL */
577
+ DWORD enum_size = 39;
578
+ int idx = 0;
579
+ HKEY hVal;
580
+
581
+ while (RegEnumKeyEx(hKey, idx++, enumbuf, &enum_size, 0,
582
+ NULL, NULL, NULL) != ERROR_NO_MORE_ITEMS)
583
+ {
584
+ int rc;
585
+
586
+ enum_size = 39;
587
+ if (RegOpenKeyEx(hKey, enumbuf, 0, KEY_QUERY_VALUE, &hVal) !=
588
+ ERROR_SUCCESS)
589
+ continue;
590
+ rc = get_res_nt(hVal, subkey, obuf);
591
+ RegCloseKey(hVal);
592
+ if (rc)
593
+ return 1;
594
+ }
595
+ return 0;
596
+ }
597
+
598
+ static int get_iphlpapi_dns_info (char *ret_buf, size_t ret_size)
599
+ {
600
+ FIXED_INFO *fi, *newfi;
601
+ DWORD size = sizeof (*fi);
602
+ IP_ADDR_STRING *ipAddr;
603
+ int i, count = 0;
604
+ int debug = 0;
605
+ size_t ip_size = sizeof("255.255.255.255,")-1;
606
+ size_t left = ret_size;
607
+ char *ret = ret_buf;
608
+ HRESULT res;
609
+
610
+ fi = malloc(size);
611
+ if (!fi)
612
+ return 0;
613
+
614
+ res = (*ares_fpGetNetworkParams) (fi, &size);
615
+ if ((res != ERROR_BUFFER_OVERFLOW) && (res != ERROR_SUCCESS))
616
+ goto quit;
617
+
618
+ newfi = realloc(fi, size);
619
+ if (!newfi)
620
+ goto quit;
621
+
622
+ fi = newfi;
623
+ res = (*ares_fpGetNetworkParams) (fi, &size);
624
+ if (res != ERROR_SUCCESS)
625
+ goto quit;
626
+
627
+ if (debug)
628
+ {
629
+ printf ("Host Name: %s\n", fi->HostName);
630
+ printf ("Domain Name: %s\n", fi->DomainName);
631
+ printf ("DNS Servers:\n"
632
+ " %s (primary)\n", fi->DnsServerList.IpAddress.String);
633
+ }
634
+ if (strlen(fi->DnsServerList.IpAddress.String) > 0 &&
635
+ inet_addr(fi->DnsServerList.IpAddress.String) != INADDR_NONE &&
636
+ left > ip_size)
637
+ {
638
+ ret += sprintf (ret, "%s,", fi->DnsServerList.IpAddress.String);
639
+ left -= ret - ret_buf;
640
+ count++;
641
+ }
642
+
643
+ for (i = 0, ipAddr = fi->DnsServerList.Next; ipAddr && left > ip_size;
644
+ ipAddr = ipAddr->Next, i++)
645
+ {
646
+ if (inet_addr(ipAddr->IpAddress.String) != INADDR_NONE)
647
+ {
648
+ ret += sprintf (ret, "%s,", ipAddr->IpAddress.String);
649
+ left -= ret - ret_buf;
650
+ count++;
651
+ }
652
+ if (debug)
653
+ printf (" %s (secondary %d)\n", ipAddr->IpAddress.String, i+1);
654
+ }
655
+
656
+ quit:
657
+ if (fi)
658
+ free(fi);
659
+
660
+ if (debug && left <= ip_size)
661
+ printf ("Too many nameservers. Truncating to %d addressess", count);
662
+ if (ret > ret_buf)
663
+ ret[-1] = '\0';
664
+ return count;
665
+ }
666
+ #endif
667
+
668
+ static int init_by_resolv_conf(ares_channel channel)
669
+ {
670
+ #ifndef WATT32
671
+ char *line = NULL;
672
+ #endif
673
+ int status = -1, nservers = 0, nsort = 0;
674
+ struct server_state *servers = NULL;
675
+ struct apattern *sortlist = NULL;
676
+
677
+ #ifdef WIN32
678
+
679
+ /*
680
+ NameServer info via IPHLPAPI (IP helper API):
681
+ GetNetworkParams() should be the trusted source for this.
682
+ Available in Win-98/2000 and later. If that fail, fall-back to
683
+ registry information.
684
+
685
+ NameServer Registry:
686
+
687
+ On Windows 9X, the DNS server can be found in:
688
+ HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD\MSTCP\NameServer
689
+
690
+ On Windows NT/2000/XP/2003:
691
+ HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NameServer
692
+ or
693
+ HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DhcpNameServer
694
+ or
695
+ HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\{AdapterID}\
696
+ NameServer
697
+ or
698
+ HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\{AdapterID}\
699
+ DhcpNameServer
700
+ */
701
+
702
+ HKEY mykey;
703
+ HKEY subkey;
704
+ DWORD data_type;
705
+ DWORD bytes;
706
+ DWORD result;
707
+ char buf[256];
708
+
709
+ if (channel->nservers > -1) /* don't override ARES_OPT_SERVER */
710
+ return ARES_SUCCESS;
711
+
712
+ if (get_iphlpapi_dns_info(buf,sizeof(buf)) > 0)
713
+ {
714
+ status = config_nameserver(&servers, &nservers, buf);
715
+ if (status == ARES_SUCCESS)
716
+ goto okay;
717
+ }
718
+
719
+ if (IS_NT())
720
+ {
721
+ if (RegOpenKeyEx(
722
+ HKEY_LOCAL_MACHINE, WIN_NS_NT_KEY, 0,
723
+ KEY_READ, &mykey
724
+ ) == ERROR_SUCCESS)
725
+ {
726
+ RegOpenKeyEx(mykey, "Interfaces", 0,
727
+ KEY_QUERY_VALUE|KEY_ENUMERATE_SUB_KEYS, &subkey);
728
+ if (get_res_nt(mykey, NAMESERVER, &line))
729
+ {
730
+ status = config_nameserver(&servers, &nservers, line);
731
+ free(line);
732
+ }
733
+ else if (get_res_nt(mykey, DHCPNAMESERVER, &line))
734
+ {
735
+ status = config_nameserver(&servers, &nservers, line);
736
+ free(line);
737
+ }
738
+ /* Try the interfaces */
739
+ else if (get_res_interfaces_nt(subkey, NAMESERVER, &line))
740
+ {
741
+ status = config_nameserver(&servers, &nservers, line);
742
+ free(line);
743
+ }
744
+ else if (get_res_interfaces_nt(subkey, DHCPNAMESERVER, &line))
745
+ {
746
+ status = config_nameserver(&servers, &nservers, line);
747
+ free(line);
748
+ }
749
+ RegCloseKey(subkey);
750
+ RegCloseKey(mykey);
751
+ }
752
+ }
753
+ else
754
+ {
755
+ if (RegOpenKeyEx(
756
+ HKEY_LOCAL_MACHINE, WIN_NS_9X, 0,
757
+ KEY_READ, &mykey
758
+ ) == ERROR_SUCCESS)
759
+ {
760
+ if ((result = RegQueryValueEx(
761
+ mykey, NAMESERVER, NULL, &data_type,
762
+ NULL, &bytes
763
+ )
764
+ ) == ERROR_SUCCESS ||
765
+ result == ERROR_MORE_DATA)
766
+ {
767
+ if (bytes)
768
+ {
769
+ line = malloc(bytes+1);
770
+ if (RegQueryValueEx(mykey, NAMESERVER, NULL, &data_type,
771
+ (unsigned char *)line, &bytes) ==
772
+ ERROR_SUCCESS)
773
+ {
774
+ status = config_nameserver(&servers, &nservers, line);
775
+ }
776
+ free(line);
777
+ }
778
+ }
779
+ }
780
+ RegCloseKey(mykey);
781
+ }
782
+
783
+ if (status == ARES_SUCCESS)
784
+ status = ARES_EOF;
785
+ else
786
+ /* Catch the case when all the above checks fail (which happens when there
787
+ is no network card or the cable is unplugged) */
788
+ status = ARES_EFILE;
789
+
790
+ #elif defined(__riscos__)
791
+
792
+ /* Under RISC OS, name servers are listed in the
793
+ system variable Inet$Resolvers, space separated. */
794
+
795
+ line = getenv("Inet$Resolvers");
796
+ status = ARES_EOF;
797
+ if (line) {
798
+ char *resolvers = strdup(line), *pos, *space;
799
+
800
+ if (!resolvers)
801
+ return ARES_ENOMEM;
802
+
803
+ pos = resolvers;
804
+ do {
805
+ space = strchr(pos, ' ');
806
+ if (space)
807
+ *space = '\0';
808
+ status = config_nameserver(&servers, &nservers, pos);
809
+ if (status != ARES_SUCCESS)
810
+ break;
811
+ pos = space + 1;
812
+ } while (space);
813
+
814
+ if (status == ARES_SUCCESS)
815
+ status = ARES_EOF;
816
+
817
+ free(resolvers);
818
+ }
819
+
820
+ #elif defined(WATT32)
821
+ int i;
822
+
823
+ sock_init();
824
+ for (i = 0; def_nameservers[i]; i++)
825
+ ;
826
+ if (i == 0)
827
+ return ARES_SUCCESS; /* use localhost DNS server */
828
+
829
+ nservers = i;
830
+ servers = calloc(i, sizeof(struct server_state));
831
+ if (!servers)
832
+ return ARES_ENOMEM;
833
+
834
+ for (i = 0; def_nameservers[i]; i++)
835
+ servers[i].addr.addrV4.s_addr = htonl(def_nameservers[i]);
836
+ status = ARES_EOF;
837
+
838
+ #elif defined(ANDROID)
839
+ char value[PROP_VALUE_MAX]="";
840
+ __system_property_get("net.dns1", value);
841
+ status = config_nameserver(&servers, &nservers, value);
842
+ if (status == ARES_SUCCESS)
843
+ status = ARES_EOF;
844
+ #else
845
+ {
846
+ char *p;
847
+ FILE *fp;
848
+ size_t linesize;
849
+ int error;
850
+
851
+ /* Don't read resolv.conf and friends if we don't have to */
852
+ if (ARES_CONFIG_CHECK(channel))
853
+ return ARES_SUCCESS;
854
+
855
+ fp = fopen(PATH_RESOLV_CONF, "r");
856
+ if (fp) {
857
+ while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS)
858
+ {
859
+ if ((p = try_config(line, "domain")))
860
+ status = config_domain(channel, p);
861
+ else if ((p = try_config(line, "lookup")) && !channel->lookups)
862
+ status = config_lookup(channel, p, "bind", "file");
863
+ else if ((p = try_config(line, "search")))
864
+ status = set_search(channel, p);
865
+ else if ((p = try_config(line, "nameserver")) && channel->nservers == -1)
866
+ status = config_nameserver(&servers, &nservers, p);
867
+ else if ((p = try_config(line, "sortlist")) && channel->nsort == -1)
868
+ status = config_sortlist(&sortlist, &nsort, p);
869
+ else if ((p = try_config(line, "options")))
870
+ status = set_options(channel, p);
871
+ else
872
+ status = ARES_SUCCESS;
873
+ if (status != ARES_SUCCESS)
874
+ break;
875
+ }
876
+ fclose(fp);
877
+ }
878
+ else {
879
+ error = ERRNO;
880
+ switch(error) {
881
+ case ENOENT:
882
+ case ESRCH:
883
+ status = ARES_EOF;
884
+ break;
885
+ default:
886
+ DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n",
887
+ error, strerror(error)));
888
+ DEBUGF(fprintf(stderr, "Error opening file: %s\n", PATH_RESOLV_CONF));
889
+ status = ARES_EFILE;
890
+ }
891
+ }
892
+
893
+ if ((status == ARES_EOF) && (!channel->lookups)) {
894
+ /* Many systems (Solaris, Linux, BSD's) use nsswitch.conf */
895
+ fp = fopen("/etc/nsswitch.conf", "r");
896
+ if (fp) {
897
+ while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS)
898
+ {
899
+ if ((p = try_config(line, "hosts:")) && !channel->lookups)
900
+ status = config_lookup(channel, p, "dns", "files");
901
+ }
902
+ fclose(fp);
903
+ }
904
+ else {
905
+ error = ERRNO;
906
+ switch(error) {
907
+ case ENOENT:
908
+ case ESRCH:
909
+ status = ARES_EOF;
910
+ break;
911
+ default:
912
+ DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n",
913
+ error, strerror(error)));
914
+ DEBUGF(fprintf(stderr, "Error opening file: %s\n", "/etc/nsswitch.conf"));
915
+ status = ARES_EFILE;
916
+ }
917
+ }
918
+ }
919
+
920
+ if ((status == ARES_EOF) && (!channel->lookups)) {
921
+ /* Linux / GNU libc 2.x and possibly others have host.conf */
922
+ fp = fopen("/etc/host.conf", "r");
923
+ if (fp) {
924
+ while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS)
925
+ {
926
+ if ((p = try_config(line, "order")) && !channel->lookups)
927
+ status = config_lookup(channel, p, "bind", "hosts");
928
+ }
929
+ fclose(fp);
930
+ }
931
+ else {
932
+ error = ERRNO;
933
+ switch(error) {
934
+ case ENOENT:
935
+ case ESRCH:
936
+ status = ARES_EOF;
937
+ break;
938
+ default:
939
+ DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n",
940
+ error, strerror(error)));
941
+ DEBUGF(fprintf(stderr, "Error opening file: %s\n", "/etc/host.conf"));
942
+ status = ARES_EFILE;
943
+ }
944
+ }
945
+ }
946
+
947
+ if ((status == ARES_EOF) && (!channel->lookups)) {
948
+ /* Tru64 uses /etc/svc.conf */
949
+ fp = fopen("/etc/svc.conf", "r");
950
+ if (fp) {
951
+ while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS)
952
+ {
953
+ if ((p = try_config(line, "hosts=")) && !channel->lookups)
954
+ status = config_lookup(channel, p, "bind", "local");
955
+ }
956
+ fclose(fp);
957
+ }
958
+ else {
959
+ error = ERRNO;
960
+ switch(error) {
961
+ case ENOENT:
962
+ case ESRCH:
963
+ status = ARES_EOF;
964
+ break;
965
+ default:
966
+ DEBUGF(fprintf(stderr, "fopen() failed with error: %d %s\n",
967
+ error, strerror(error)));
968
+ DEBUGF(fprintf(stderr, "Error opening file: %s\n", "/etc/svc.conf"));
969
+ status = ARES_EFILE;
970
+ }
971
+ }
972
+ }
973
+
974
+ if(line)
975
+ free(line);
976
+ }
977
+
978
+ #endif
979
+
980
+ /* Handle errors. */
981
+ if (status != ARES_EOF)
982
+ {
983
+ if (servers != NULL)
984
+ free(servers);
985
+ if (sortlist != NULL)
986
+ free(sortlist);
987
+ return status;
988
+ }
989
+
990
+ /* If we got any name server entries, fill them in. */
991
+ #ifdef WIN32
992
+ okay:
993
+ #endif
994
+ if (servers)
995
+ {
996
+ channel->servers = servers;
997
+ channel->nservers = nservers;
998
+ }
999
+
1000
+ /* If we got any sortlist entries, fill them in. */
1001
+ if (sortlist)
1002
+ {
1003
+ channel->sortlist = sortlist;
1004
+ channel->nsort = nsort;
1005
+ }
1006
+
1007
+ return ARES_SUCCESS;
1008
+ }
1009
+
1010
+ static int init_by_defaults(ares_channel channel)
1011
+ {
1012
+ char *hostname = NULL;
1013
+ int rc = ARES_SUCCESS;
1014
+ #ifdef HAVE_GETHOSTNAME
1015
+ char *dot;
1016
+ #endif
1017
+
1018
+ if (channel->flags == -1)
1019
+ channel->flags = 0;
1020
+ if (channel->timeout == -1)
1021
+ channel->timeout = DEFAULT_TIMEOUT;
1022
+ if (channel->tries == -1)
1023
+ channel->tries = DEFAULT_TRIES;
1024
+ if (channel->ndots == -1)
1025
+ channel->ndots = 1;
1026
+ if (channel->rotate == -1)
1027
+ channel->rotate = 0;
1028
+ if (channel->udp_port == -1)
1029
+ channel->udp_port = htons(NAMESERVER_PORT);
1030
+ if (channel->tcp_port == -1)
1031
+ channel->tcp_port = htons(NAMESERVER_PORT);
1032
+
1033
+ if (channel->nservers == -1) {
1034
+ /* If nobody specified servers, try a local named. */
1035
+ channel->servers = malloc(sizeof(struct server_state));
1036
+ if (!channel->servers) {
1037
+ rc = ARES_ENOMEM;
1038
+ goto error;
1039
+ }
1040
+ channel->servers[0].addr.family = AF_INET;
1041
+ channel->servers[0].addr.addrV4.s_addr = htonl(INADDR_LOOPBACK);
1042
+ channel->nservers = 1;
1043
+ }
1044
+
1045
+ #ifdef ENAMETOOLONG
1046
+ #define toolong(x) (x == -1) && ((ENAMETOOLONG == errno) || (EINVAL == errno))
1047
+ #else
1048
+ #define toolong(x) (x == -1) && (EINVAL == errno)
1049
+ #endif
1050
+
1051
+ if (channel->ndomains == -1) {
1052
+ /* Derive a default domain search list from the kernel hostname,
1053
+ * or set it to empty if the hostname isn't helpful.
1054
+ */
1055
+ size_t len = 64;
1056
+ int res;
1057
+ channel->ndomains = 0; /* default to none */
1058
+
1059
+ #ifdef HAVE_GETHOSTNAME
1060
+ hostname = malloc(len);
1061
+ if(!hostname) {
1062
+ rc = ARES_ENOMEM;
1063
+ goto error;
1064
+ }
1065
+
1066
+ do {
1067
+ res = gethostname(hostname, len);
1068
+
1069
+ if(toolong(res)) {
1070
+ char *p;
1071
+ len *= 2;
1072
+ p = realloc(hostname, len);
1073
+ if(!p) {
1074
+ rc = ARES_ENOMEM;
1075
+ goto error;
1076
+ }
1077
+ hostname = p;
1078
+ continue;
1079
+ }
1080
+ else if(res) {
1081
+ rc = ARES_EBADNAME;
1082
+ goto error;
1083
+ }
1084
+
1085
+ } while(0);
1086
+
1087
+ dot = strchr(hostname, '.');
1088
+ if (dot) {
1089
+ /* a dot was found */
1090
+ channel->domains = malloc(sizeof(char *));
1091
+ if (!channel->domains) {
1092
+ rc = ARES_ENOMEM;
1093
+ goto error;
1094
+ }
1095
+ channel->domains[0] = strdup(dot + 1);
1096
+ if (!channel->domains[0]) {
1097
+ rc = ARES_ENOMEM;
1098
+ goto error;
1099
+ }
1100
+ channel->ndomains = 1;
1101
+ }
1102
+ #endif
1103
+ }
1104
+
1105
+ if (channel->nsort == -1) {
1106
+ channel->sortlist = NULL;
1107
+ channel->nsort = 0;
1108
+ }
1109
+
1110
+ if (!channel->lookups) {
1111
+ channel->lookups = strdup("fb");
1112
+ if (!channel->lookups)
1113
+ rc = ARES_ENOMEM;
1114
+ }
1115
+
1116
+ error:
1117
+ if(rc) {
1118
+ if(channel->servers)
1119
+ free(channel->servers);
1120
+
1121
+ if(channel->domains && channel->domains[0])
1122
+ free(channel->domains[0]);
1123
+ if(channel->domains)
1124
+ free(channel->domains);
1125
+ if(channel->lookups)
1126
+ free(channel->lookups);
1127
+ }
1128
+
1129
+ if(hostname)
1130
+ free(hostname);
1131
+
1132
+ return rc;
1133
+ }
1134
+
1135
+ #if !defined(WIN32) && !defined(WATT32)
1136
+ static int config_domain(ares_channel channel, char *str)
1137
+ {
1138
+ char *q;
1139
+
1140
+ /* Set a single search domain. */
1141
+ q = str;
1142
+ while (*q && !ISSPACE(*q))
1143
+ q++;
1144
+ *q = '\0';
1145
+ return set_search(channel, str);
1146
+ }
1147
+
1148
+ #if defined(__INTEL_COMPILER) && (__INTEL_COMPILER == 910) && \
1149
+ defined(__OPTIMIZE__) && defined(__unix__) && defined(__i386__)
1150
+ /* workaround icc 9.1 optimizer issue */
1151
+ # define vqualifier volatile
1152
+ #else
1153
+ # define vqualifier
1154
+ #endif
1155
+
1156
+ static int config_lookup(ares_channel channel, const char *str,
1157
+ const char *bindch, const char *filech)
1158
+ {
1159
+ char lookups[3], *l;
1160
+ const char *vqualifier p;
1161
+
1162
+ /* Set the lookup order. Only the first letter of each work
1163
+ * is relevant, and it has to be "b" for DNS or "f" for the
1164
+ * host file. Ignore everything else.
1165
+ */
1166
+ l = lookups;
1167
+ p = str;
1168
+ while (*p)
1169
+ {
1170
+ if ((*p == *bindch || *p == *filech) && l < lookups + 2) {
1171
+ if (*p == *bindch) *l++ = 'b';
1172
+ else *l++ = 'f';
1173
+ }
1174
+ while (*p && !ISSPACE(*p) && (*p != ','))
1175
+ p++;
1176
+ while (*p && (ISSPACE(*p) || (*p == ',')))
1177
+ p++;
1178
+ }
1179
+ *l = '\0';
1180
+ channel->lookups = strdup(lookups);
1181
+ return (channel->lookups) ? ARES_SUCCESS : ARES_ENOMEM;
1182
+ }
1183
+ #endif /* !WIN32 & !WATT32 */
1184
+
1185
+ #ifndef WATT32
1186
+ static int config_nameserver(struct server_state **servers, int *nservers,
1187
+ char *str)
1188
+ {
1189
+ struct ares_addr host;
1190
+ struct server_state *newserv;
1191
+ char *p, *txtaddr;
1192
+ /* On Windows, there may be more than one nameserver specified in the same
1193
+ * registry key, so we parse input as a space or comma seperated list.
1194
+ */
1195
+ for (p = str; p;)
1196
+ {
1197
+ /* Skip whitespace and commas. */
1198
+ while (*p && (ISSPACE(*p) || (*p == ',')))
1199
+ p++;
1200
+ if (!*p)
1201
+ /* No more input, done. */
1202
+ break;
1203
+
1204
+ /* Pointer to start of IPv4 or IPv6 address part. */
1205
+ txtaddr = p;
1206
+
1207
+ /* Advance past this address. */
1208
+ while (*p && !ISSPACE(*p) && (*p != ','))
1209
+ p++;
1210
+ if (*p)
1211
+ /* Null terminate this address. */
1212
+ *p++ = '\0';
1213
+ else
1214
+ /* Reached end of input, done when this address is processed. */
1215
+ p = NULL;
1216
+
1217
+ /* Convert textual address to binary format. */
1218
+ if (ares_inet_pton(AF_INET, txtaddr, &host.addrV4) == 1)
1219
+ host.family = AF_INET;
1220
+ else if (ares_inet_pton(AF_INET6, txtaddr, &host.addrV6) == 1)
1221
+ host.family = AF_INET6;
1222
+ else
1223
+ continue;
1224
+
1225
+ /* Resize servers state array. */
1226
+ newserv = realloc(*servers, (*nservers + 1) *
1227
+ sizeof(struct server_state));
1228
+ if (!newserv)
1229
+ return ARES_ENOMEM;
1230
+
1231
+ /* Store address data. */
1232
+ newserv[*nservers].addr.family = host.family;
1233
+ if (host.family == AF_INET)
1234
+ memcpy(&newserv[*nservers].addr.addrV4, &host.addrV4,
1235
+ sizeof(host.addrV4));
1236
+ else
1237
+ memcpy(&newserv[*nservers].addr.addrV6, &host.addrV6,
1238
+ sizeof(host.addrV6));
1239
+
1240
+ /* Update arguments. */
1241
+ *servers = newserv;
1242
+ *nservers += 1;
1243
+ }
1244
+
1245
+ return ARES_SUCCESS;
1246
+ }
1247
+
1248
+ #ifndef WIN32
1249
+ static int config_sortlist(struct apattern **sortlist, int *nsort,
1250
+ const char *str)
1251
+ {
1252
+ struct apattern pat;
1253
+ const char *q;
1254
+
1255
+ /* Add sortlist entries. */
1256
+ while (*str && *str != ';')
1257
+ {
1258
+ int bits;
1259
+ char ipbuf[16], ipbufpfx[32];
1260
+ /* Find just the IP */
1261
+ q = str;
1262
+ while (*q && *q != '/' && *q != ';' && !ISSPACE(*q))
1263
+ q++;
1264
+ memcpy(ipbuf, str, q-str);
1265
+ ipbuf[q-str] = '\0';
1266
+ /* Find the prefix */
1267
+ if (*q == '/')
1268
+ {
1269
+ const char *str2 = q+1;
1270
+ while (*q && *q != ';' && !ISSPACE(*q))
1271
+ q++;
1272
+ memcpy(ipbufpfx, str, q-str);
1273
+ ipbufpfx[q-str] = '\0';
1274
+ str = str2;
1275
+ }
1276
+ else
1277
+ ipbufpfx[0] = '\0';
1278
+ /* Lets see if it is CIDR */
1279
+ /* First we'll try IPv6 */
1280
+ if ((bits = ares_inet_net_pton(AF_INET6, ipbufpfx[0] ? ipbufpfx : ipbuf,
1281
+ &pat.addrV6,
1282
+ sizeof(pat.addrV6))) > 0)
1283
+ {
1284
+ pat.type = PATTERN_CIDR;
1285
+ pat.mask.bits = (unsigned short)bits;
1286
+ pat.family = AF_INET6;
1287
+ if (!sortlist_alloc(sortlist, nsort, &pat))
1288
+ return ARES_ENOMEM;
1289
+ }
1290
+ if (ipbufpfx[0] &&
1291
+ (bits = ares_inet_net_pton(AF_INET, ipbufpfx, &pat.addrV4,
1292
+ sizeof(pat.addrV4))) > 0)
1293
+ {
1294
+ pat.type = PATTERN_CIDR;
1295
+ pat.mask.bits = (unsigned short)bits;
1296
+ pat.family = AF_INET;
1297
+ if (!sortlist_alloc(sortlist, nsort, &pat))
1298
+ return ARES_ENOMEM;
1299
+ }
1300
+ /* See if it is just a regular IP */
1301
+ else if (ip_addr(ipbuf, q-str, &pat.addrV4) == 0)
1302
+ {
1303
+ if (ipbufpfx[0])
1304
+ {
1305
+ memcpy(ipbuf, str, q-str);
1306
+ ipbuf[q-str] = '\0';
1307
+ if (ip_addr(ipbuf, q-str, &pat.mask.addr4) != 0)
1308
+ natural_mask(&pat);
1309
+ }
1310
+ else
1311
+ natural_mask(&pat);
1312
+ pat.family = AF_INET;
1313
+ pat.type = PATTERN_MASK;
1314
+ if (!sortlist_alloc(sortlist, nsort, &pat))
1315
+ return ARES_ENOMEM;
1316
+ }
1317
+ else
1318
+ {
1319
+ while (*q && *q != ';' && !ISSPACE(*q))
1320
+ q++;
1321
+ }
1322
+ str = q;
1323
+ while (ISSPACE(*str))
1324
+ str++;
1325
+ }
1326
+
1327
+ return ARES_SUCCESS;
1328
+ }
1329
+ #endif /* !WIN32 */
1330
+ #endif /* !WATT32 */
1331
+
1332
+ static int set_search(ares_channel channel, const char *str)
1333
+ {
1334
+ int n;
1335
+ const char *p, *q;
1336
+
1337
+ if(channel->ndomains != -1) {
1338
+ /* if we already have some domains present, free them first */
1339
+ for(n=0; n < channel->ndomains; n++)
1340
+ free(channel->domains[n]);
1341
+ free(channel->domains);
1342
+ channel->domains = NULL;
1343
+ channel->ndomains = -1;
1344
+ }
1345
+
1346
+ /* Count the domains given. */
1347
+ n = 0;
1348
+ p = str;
1349
+ while (*p)
1350
+ {
1351
+ while (*p && !ISSPACE(*p))
1352
+ p++;
1353
+ while (ISSPACE(*p))
1354
+ p++;
1355
+ n++;
1356
+ }
1357
+
1358
+ if (!n)
1359
+ {
1360
+ channel->ndomains = 0;
1361
+ return ARES_SUCCESS;
1362
+ }
1363
+
1364
+ channel->domains = malloc(n * sizeof(char *));
1365
+ if (!channel->domains)
1366
+ return ARES_ENOMEM;
1367
+
1368
+ /* Now copy the domains. */
1369
+ n = 0;
1370
+ p = str;
1371
+ while (*p)
1372
+ {
1373
+ channel->ndomains = n;
1374
+ q = p;
1375
+ while (*q && !ISSPACE(*q))
1376
+ q++;
1377
+ channel->domains[n] = malloc(q - p + 1);
1378
+ if (!channel->domains[n])
1379
+ return ARES_ENOMEM;
1380
+ memcpy(channel->domains[n], p, q - p);
1381
+ channel->domains[n][q - p] = 0;
1382
+ p = q;
1383
+ while (ISSPACE(*p))
1384
+ p++;
1385
+ n++;
1386
+ }
1387
+ channel->ndomains = n;
1388
+
1389
+ return ARES_SUCCESS;
1390
+ }
1391
+
1392
+ static int set_options(ares_channel channel, const char *str)
1393
+ {
1394
+ const char *p, *q, *val;
1395
+
1396
+ p = str;
1397
+ while (*p)
1398
+ {
1399
+ q = p;
1400
+ while (*q && !ISSPACE(*q))
1401
+ q++;
1402
+ val = try_option(p, q, "ndots:");
1403
+ if (val && channel->ndots == -1)
1404
+ channel->ndots = aresx_sltosi(strtol(val, NULL, 10));
1405
+ val = try_option(p, q, "retrans:");
1406
+ if (val && channel->timeout == -1)
1407
+ channel->timeout = aresx_sltosi(strtol(val, NULL, 10));
1408
+ val = try_option(p, q, "retry:");
1409
+ if (val && channel->tries == -1)
1410
+ channel->tries = aresx_sltosi(strtol(val, NULL, 10));
1411
+ val = try_option(p, q, "rotate");
1412
+ if (val && channel->rotate == -1)
1413
+ channel->rotate = 1;
1414
+ p = q;
1415
+ while (ISSPACE(*p))
1416
+ p++;
1417
+ }
1418
+
1419
+ return ARES_SUCCESS;
1420
+ }
1421
+
1422
+ static const char *try_option(const char *p, const char *q, const char *opt)
1423
+ {
1424
+ size_t len = strlen(opt);
1425
+ return ((size_t)(q - p) >= len && !strncmp(p, opt, len)) ? &p[len] : NULL;
1426
+ }
1427
+
1428
+ #if !defined(WIN32) && !defined(WATT32)
1429
+ static char *try_config(char *s, const char *opt)
1430
+ {
1431
+ size_t len;
1432
+ char *p;
1433
+ char *q;
1434
+
1435
+ if (!s || !opt)
1436
+ /* no line or no option */
1437
+ return NULL;
1438
+
1439
+ /* trim line comment */
1440
+ p = s;
1441
+ while (*p && (*p != '#'))
1442
+ p++;
1443
+ *p = '\0';
1444
+
1445
+ /* trim trailing whitespace */
1446
+ q = p - 1;
1447
+ while ((q >= s) && ISSPACE(*q))
1448
+ q--;
1449
+ *++q = '\0';
1450
+
1451
+ /* skip leading whitespace */
1452
+ p = s;
1453
+ while (*p && ISSPACE(*p))
1454
+ p++;
1455
+
1456
+ if (!*p)
1457
+ /* empty line */
1458
+ return NULL;
1459
+
1460
+ if ((len = strlen(opt)) == 0)
1461
+ /* empty option */
1462
+ return NULL;
1463
+
1464
+ if (strncmp(p, opt, len) != 0)
1465
+ /* line and option do not match */
1466
+ return NULL;
1467
+
1468
+ /* skip over given option name */
1469
+ p += len;
1470
+
1471
+ if (!*p)
1472
+ /* no option value */
1473
+ return NULL;
1474
+
1475
+ if ((opt[len-1] != ':') && (opt[len-1] != '=') && !ISSPACE(*p))
1476
+ /* whitespace between option name and value is mandatory
1477
+ for given option names which do not end with ':' or '=' */
1478
+ return NULL;
1479
+
1480
+ /* skip over whitespace */
1481
+ while (*p && ISSPACE(*p))
1482
+ p++;
1483
+
1484
+ if (!*p)
1485
+ /* no option value */
1486
+ return NULL;
1487
+
1488
+ /* return pointer to option value */
1489
+ return p;
1490
+ }
1491
+
1492
+ static int sortlist_alloc(struct apattern **sortlist, int *nsort,
1493
+ struct apattern *pat)
1494
+ {
1495
+ struct apattern *newsort;
1496
+ newsort = realloc(*sortlist, (*nsort + 1) * sizeof(struct apattern));
1497
+ if (!newsort)
1498
+ return 0;
1499
+ newsort[*nsort] = *pat;
1500
+ *sortlist = newsort;
1501
+ (*nsort)++;
1502
+ return 1;
1503
+ }
1504
+
1505
+ static int ip_addr(const char *ipbuf, ssize_t len, struct in_addr *addr)
1506
+ {
1507
+
1508
+ /* Four octets and three periods yields at most 15 characters. */
1509
+ if (len > 15)
1510
+ return -1;
1511
+
1512
+ addr->s_addr = inet_addr(ipbuf);
1513
+ if (addr->s_addr == INADDR_NONE && strcmp(ipbuf, "255.255.255.255") != 0)
1514
+ return -1;
1515
+ return 0;
1516
+ }
1517
+
1518
+ static void natural_mask(struct apattern *pat)
1519
+ {
1520
+ struct in_addr addr;
1521
+
1522
+ /* Store a host-byte-order copy of pat in a struct in_addr. Icky,
1523
+ * but portable.
1524
+ */
1525
+ addr.s_addr = ntohl(pat->addrV4.s_addr);
1526
+
1527
+ /* This is out of date in the CIDR world, but some people might
1528
+ * still rely on it.
1529
+ */
1530
+ if (IN_CLASSA(addr.s_addr))
1531
+ pat->mask.addr4.s_addr = htonl(IN_CLASSA_NET);
1532
+ else if (IN_CLASSB(addr.s_addr))
1533
+ pat->mask.addr4.s_addr = htonl(IN_CLASSB_NET);
1534
+ else
1535
+ pat->mask.addr4.s_addr = htonl(IN_CLASSC_NET);
1536
+ }
1537
+ #endif /* !WIN32 && !WATT32 */
1538
+
1539
+ /* initialize an rc4 key. If possible a cryptographically secure random key
1540
+ is generated using a suitable function (for example win32's RtlGenRandom as
1541
+ described in
1542
+ http://blogs.msdn.com/michael_howard/archive/2005/01/14/353379.aspx
1543
+ otherwise the code defaults to cross-platform albeit less secure mechanism
1544
+ using rand
1545
+ */
1546
+ static void randomize_key(unsigned char* key,int key_data_len)
1547
+ {
1548
+ int randomized = 0;
1549
+ int counter=0;
1550
+ #ifdef WIN32
1551
+ BOOLEAN res;
1552
+ if (ares_fpSystemFunction036)
1553
+ {
1554
+ res = (*ares_fpSystemFunction036) (key, key_data_len);
1555
+ if (res)
1556
+ randomized = 1;
1557
+ }
1558
+ #else /* !WIN32 */
1559
+ #ifdef RANDOM_FILE
1560
+ FILE *f = fopen(RANDOM_FILE, "rb");
1561
+ if(f) {
1562
+ counter = aresx_uztosi(fread(key, 1, key_data_len, f));
1563
+ fclose(f);
1564
+ }
1565
+ #endif
1566
+ #endif /* WIN32 */
1567
+
1568
+ if ( !randomized ) {
1569
+ for (;counter<key_data_len;counter++)
1570
+ key[counter]=(unsigned char)(rand() % 256);
1571
+ }
1572
+ }
1573
+
1574
+ static int init_id_key(rc4_key* key,int key_data_len)
1575
+ {
1576
+ unsigned char index1;
1577
+ unsigned char index2;
1578
+ unsigned char* state;
1579
+ short counter;
1580
+ unsigned char *key_data_ptr = 0;
1581
+
1582
+ key_data_ptr = calloc(1,key_data_len);
1583
+ if (!key_data_ptr)
1584
+ return ARES_ENOMEM;
1585
+
1586
+ state = &key->state[0];
1587
+ for(counter = 0; counter < 256; counter++)
1588
+ /* unnecessary AND but it keeps some compilers happier */
1589
+ state[counter] = (unsigned char)(counter & 0xff);
1590
+ randomize_key(key->state,key_data_len);
1591
+ key->x = 0;
1592
+ key->y = 0;
1593
+ index1 = 0;
1594
+ index2 = 0;
1595
+ for(counter = 0; counter < 256; counter++)
1596
+ {
1597
+ index2 = (unsigned char)((key_data_ptr[index1] + state[counter] +
1598
+ index2) % 256);
1599
+ ARES_SWAP_BYTE(&state[counter], &state[index2]);
1600
+
1601
+ index1 = (unsigned char)((index1 + 1) % key_data_len);
1602
+ }
1603
+ free(key_data_ptr);
1604
+ return ARES_SUCCESS;
1605
+ }
1606
+
1607
+ unsigned short ares__generate_new_id(rc4_key* key)
1608
+ {
1609
+ unsigned short r=0;
1610
+ ares__rc4(key, (unsigned char *)&r, sizeof(r));
1611
+ return r;
1612
+ }
1613
+
1614
+ void ares_set_local_ip4(ares_channel channel, unsigned int local_ip)
1615
+ {
1616
+ channel->local_ip4 = local_ip;
1617
+ }
1618
+
1619
+ /* local_ip6 should be 16 bytes in length */
1620
+ void ares_set_local_ip6(ares_channel channel,
1621
+ const unsigned char* local_ip6)
1622
+ {
1623
+ memcpy(&channel->local_ip6, local_ip6, sizeof(channel->local_ip6));
1624
+ }
1625
+
1626
+ /* local_dev_name should be null terminated. */
1627
+ void ares_set_local_dev(ares_channel channel,
1628
+ const char* local_dev_name)
1629
+ {
1630
+ strncpy(channel->local_dev_name, local_dev_name,
1631
+ sizeof(channel->local_dev_name));
1632
+ channel->local_dev_name[sizeof(channel->local_dev_name) - 1] = 0;
1633
+ }
1634
+
1635
+
1636
+ void ares_set_socket_callback(ares_channel channel,
1637
+ ares_sock_create_callback cb,
1638
+ void *data)
1639
+ {
1640
+ channel->sock_create_cb = cb;
1641
+ channel->sock_create_cb_data = data;
1642
+ }
1643
+
1644
+ void ares__init_servers_state(ares_channel channel)
1645
+ {
1646
+ struct server_state *server;
1647
+ int i;
1648
+
1649
+ for (i = 0; i < channel->nservers; i++)
1650
+ {
1651
+ server = &channel->servers[i];
1652
+ server->udp_socket = ARES_SOCKET_BAD;
1653
+ server->tcp_socket = ARES_SOCKET_BAD;
1654
+ server->tcp_connection_generation = ++channel->tcp_connection_generation;
1655
+ server->tcp_lenbuf_pos = 0;
1656
+ server->tcp_buffer_pos = 0;
1657
+ server->tcp_buffer = NULL;
1658
+ server->tcp_length = 0;
1659
+ server->qhead = NULL;
1660
+ server->qtail = NULL;
1661
+ ares__init_list_head(&server->queries_to_server);
1662
+ server->channel = channel;
1663
+ server->is_broken = 0;
1664
+ }
1665
+ }