grpc 1.2.5 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (327) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1434 -399
  3. data/etc/roots.pem +34 -150
  4. data/include/grpc/grpc.h +71 -0
  5. data/include/grpc/impl/codegen/atm.h +5 -0
  6. data/include/grpc/impl/codegen/atm_gcc_atomic.h +6 -0
  7. data/include/grpc/impl/codegen/atm_gcc_sync.h +2 -0
  8. data/include/grpc/impl/codegen/atm_windows.h +11 -0
  9. data/include/grpc/impl/codegen/grpc_types.h +54 -13
  10. data/include/grpc/impl/codegen/port_platform.h +15 -1
  11. data/include/grpc/support/alloc.h +2 -1
  12. data/include/grpc/support/sync.h +4 -0
  13. data/include/grpc/support/tls.h +1 -1
  14. data/src/core/ext/census/gen/trace_context.pb.h +1 -1
  15. data/src/core/ext/census/grpc_filter.c +14 -10
  16. data/src/core/ext/census/grpc_plugin.c +3 -1
  17. data/src/core/ext/census/trace_label.h +1 -1
  18. data/src/core/ext/census/trace_propagation.h +1 -1
  19. data/src/core/ext/census/trace_status.h +1 -1
  20. data/src/core/ext/census/trace_string.h +1 -1
  21. data/src/core/ext/census/tracing.h +1 -1
  22. data/src/core/ext/{client_channel → filters/client_channel}/channel_connectivity.c +56 -27
  23. data/src/core/ext/{client_channel → filters/client_channel}/client_channel.c +407 -202
  24. data/src/core/ext/{client_channel → filters/client_channel}/client_channel.h +10 -6
  25. data/src/core/ext/{client_channel → filters/client_channel}/client_channel_factory.c +1 -1
  26. data/src/core/ext/{client_channel → filters/client_channel}/client_channel_factory.h +4 -4
  27. data/src/core/ext/{client_channel → filters/client_channel}/client_channel_plugin.c +12 -7
  28. data/src/core/ext/{client_channel → filters/client_channel}/connector.c +1 -1
  29. data/src/core/ext/{client_channel → filters/client_channel}/connector.h +3 -5
  30. data/src/core/ext/{client_channel → filters/client_channel}/http_connect_handshaker.c +6 -6
  31. data/src/core/ext/{client_channel → filters/client_channel}/http_connect_handshaker.h +3 -3
  32. data/src/core/ext/{client_channel → filters/client_channel}/http_proxy.c +4 -4
  33. data/src/core/ext/{client_channel → filters/client_channel}/http_proxy.h +3 -3
  34. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy.c +1 -1
  35. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy.h +4 -4
  36. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb.c +22 -20
  37. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb.h +4 -4
  38. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb_channel.h +5 -4
  39. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb_channel_secure.c +2 -2
  40. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/load_balancer_api.c +1 -1
  41. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/load_balancer_api.h +6 -5
  42. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +1 -1
  43. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +0 -0
  44. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/pick_first/pick_first.c +20 -15
  45. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/round_robin/round_robin.c +21 -16
  46. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_factory.c +1 -1
  47. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_factory.h +5 -5
  48. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_registry.c +1 -1
  49. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_registry.h +4 -4
  50. data/src/core/ext/{client_channel → filters/client_channel}/parse_address.c +1 -1
  51. data/src/core/ext/{client_channel → filters/client_channel}/parse_address.h +4 -4
  52. data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper.c +1 -1
  53. data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper.h +3 -3
  54. data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper_registry.c +10 -4
  55. data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper_registry.h +4 -4
  56. data/src/core/ext/{client_channel → filters/client_channel}/resolver.c +1 -1
  57. data/src/core/ext/{client_channel → filters/client_channel}/resolver.h +4 -4
  58. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.c +350 -0
  59. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +66 -0
  60. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.c +319 -0
  61. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.c +289 -0
  62. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +64 -0
  63. data/src/core/ext/{resolver → filters/client_channel/resolver}/dns/native/dns_resolver.c +21 -5
  64. data/src/core/ext/{resolver → filters/client_channel/resolver}/sockaddr/sockaddr_resolver.c +3 -3
  65. data/src/core/ext/{client_channel → filters/client_channel}/resolver_factory.c +1 -1
  66. data/src/core/ext/{client_channel → filters/client_channel}/resolver_factory.h +6 -6
  67. data/src/core/ext/{client_channel → filters/client_channel}/resolver_registry.c +1 -2
  68. data/src/core/ext/{client_channel → filters/client_channel}/resolver_registry.h +4 -4
  69. data/src/core/ext/filters/client_channel/retry_throttle.c +210 -0
  70. data/src/core/ext/filters/client_channel/retry_throttle.h +65 -0
  71. data/src/core/ext/{client_channel → filters/client_channel}/subchannel.c +49 -43
  72. data/src/core/ext/{client_channel → filters/client_channel}/subchannel.h +21 -7
  73. data/src/core/ext/{client_channel → filters/client_channel}/subchannel_index.c +1 -1
  74. data/src/core/ext/{client_channel → filters/client_channel}/subchannel_index.h +5 -5
  75. data/src/core/ext/{client_channel → filters/client_channel}/uri_parser.c +1 -1
  76. data/src/core/ext/{client_channel → filters/client_channel}/uri_parser.h +3 -3
  77. data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting.c +4 -2
  78. data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting.h +3 -3
  79. data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting_filter.c +17 -14
  80. data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting_filter.h +4 -4
  81. data/src/core/ext/filters/max_age/max_age_filter.c +439 -0
  82. data/src/core/ext/filters/max_age/max_age_filter.h +39 -0
  83. data/src/core/ext/transport/chttp2/client/chttp2_connector.c +6 -41
  84. data/src/core/ext/transport/chttp2/client/chttp2_connector.h +1 -1
  85. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +2 -2
  86. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +3 -3
  87. data/src/core/ext/transport/chttp2/server/chttp2_server.c +2 -2
  88. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c +2 -5
  89. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +2 -2
  90. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +449 -204
  91. data/src/core/ext/transport/chttp2/transport/frame_data.c +10 -7
  92. data/src/core/ext/transport/chttp2/transport/frame_goaway.c +3 -2
  93. data/src/core/ext/transport/chttp2/transport/frame_ping.c +37 -7
  94. data/src/core/ext/transport/chttp2/transport/frame_ping.h +3 -0
  95. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +4 -3
  96. data/src/core/ext/transport/chttp2/transport/frame_settings.c +18 -38
  97. data/src/core/ext/transport/chttp2/transport/frame_settings.h +1 -29
  98. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +2 -2
  99. data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +64 -37
  100. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +11 -4
  101. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +60 -39
  102. data/src/core/ext/transport/chttp2/transport/hpack_table.c +2 -2
  103. data/src/core/ext/transport/chttp2/transport/http2_settings.c +75 -0
  104. data/src/core/ext/transport/chttp2/transport/http2_settings.h +74 -0
  105. data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +22 -43
  106. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +8 -10
  107. data/src/core/ext/transport/chttp2/transport/internal.h +24 -2
  108. data/src/core/ext/transport/chttp2/transport/parsing.c +33 -15
  109. data/src/core/ext/transport/chttp2/transport/writing.c +56 -10
  110. data/src/core/lib/channel/channel_args.c +7 -0
  111. data/src/core/lib/channel/channel_args.h +2 -0
  112. data/src/core/lib/channel/channel_stack.c +20 -27
  113. data/src/core/lib/channel/channel_stack.h +18 -16
  114. data/src/core/lib/channel/compress_filter.c +20 -18
  115. data/src/core/lib/channel/connected_channel.c +9 -8
  116. data/src/core/lib/channel/deadline_filter.c +28 -24
  117. data/src/core/lib/channel/deadline_filter.h +3 -3
  118. data/src/core/lib/channel/handshaker.c +3 -2
  119. data/src/core/lib/channel/http_client_filter.c +119 -61
  120. data/src/core/lib/channel/http_server_filter.c +124 -69
  121. data/src/core/lib/channel/message_size_filter.c +23 -19
  122. data/src/core/lib/http/httpcli.c +8 -6
  123. data/src/core/lib/http/httpcli_security_connector.c +5 -5
  124. data/src/core/lib/http/parser.c +57 -31
  125. data/src/core/lib/iomgr/closure.c +15 -0
  126. data/src/core/lib/iomgr/closure.h +4 -0
  127. data/src/core/lib/iomgr/combiner.c +8 -0
  128. data/src/core/lib/iomgr/endpoint_pair.h +2 -3
  129. data/src/core/lib/iomgr/endpoint_pair_posix.c +10 -7
  130. data/src/core/lib/iomgr/endpoint_pair_uv.c +2 -3
  131. data/src/core/lib/iomgr/endpoint_pair_windows.c +9 -6
  132. data/src/core/lib/iomgr/error.c +360 -177
  133. data/src/core/lib/iomgr/error.h +31 -33
  134. data/src/core/lib/iomgr/error_internal.h +30 -9
  135. data/src/core/lib/iomgr/ev_epoll_linux.c +25 -239
  136. data/src/core/lib/iomgr/ev_poll_posix.c +11 -7
  137. data/src/core/lib/iomgr/ev_posix.c +6 -0
  138. data/src/core/lib/iomgr/ev_posix.h +3 -0
  139. data/src/core/lib/iomgr/exec_ctx.c +6 -0
  140. data/src/core/lib/iomgr/executor.c +8 -2
  141. data/src/core/lib/iomgr/load_file.c +6 -3
  142. data/src/core/lib/iomgr/lockfree_event.c +238 -0
  143. data/src/core/{ext/client_channel/initial_connect_string.h → lib/iomgr/lockfree_event.h} +17 -13
  144. data/src/core/lib/iomgr/pollset.h +4 -0
  145. data/src/core/lib/iomgr/pollset_windows.c +2 -2
  146. data/src/core/lib/iomgr/port.h +9 -0
  147. data/src/core/lib/iomgr/resolve_address_posix.c +15 -9
  148. data/src/core/lib/iomgr/resolve_address_uv.c +8 -6
  149. data/src/core/lib/iomgr/resolve_address_windows.c +2 -2
  150. data/src/core/lib/iomgr/resource_quota.c +19 -4
  151. data/src/core/lib/iomgr/resource_quota.h +2 -0
  152. data/src/core/lib/iomgr/sockaddr_utils.c +3 -1
  153. data/src/core/lib/iomgr/socket_factory_posix.c +110 -0
  154. data/src/core/lib/iomgr/socket_factory_posix.h +90 -0
  155. data/src/core/lib/iomgr/socket_utils_common_posix.c +25 -9
  156. data/src/core/lib/iomgr/socket_utils_posix.h +7 -0
  157. data/src/core/lib/iomgr/tcp_client.h +0 -4
  158. data/src/core/lib/iomgr/tcp_client_posix.c +15 -31
  159. data/src/core/lib/iomgr/tcp_client_uv.c +10 -6
  160. data/src/core/lib/iomgr/tcp_client_windows.c +9 -19
  161. data/src/core/lib/iomgr/tcp_posix.c +111 -22
  162. data/src/core/lib/iomgr/tcp_posix.h +3 -4
  163. data/src/core/lib/iomgr/tcp_server_posix.c +39 -417
  164. data/src/core/lib/iomgr/tcp_server_utils_posix.h +135 -0
  165. data/src/core/lib/iomgr/tcp_server_utils_posix_common.c +221 -0
  166. data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.c +196 -0
  167. data/src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.c +49 -0
  168. data/src/core/lib/iomgr/tcp_server_uv.c +43 -16
  169. data/src/core/lib/iomgr/tcp_server_windows.c +10 -22
  170. data/src/core/lib/iomgr/tcp_uv.c +16 -13
  171. data/src/core/lib/iomgr/tcp_windows.c +24 -12
  172. data/src/core/lib/iomgr/tcp_windows.h +2 -2
  173. data/src/core/lib/iomgr/timer.h +3 -0
  174. data/src/core/lib/iomgr/timer_generic.c +257 -72
  175. data/src/core/lib/iomgr/timer_generic.h +1 -1
  176. data/src/core/lib/iomgr/timer_heap.c +8 -8
  177. data/src/core/lib/iomgr/udp_server.c +54 -24
  178. data/src/core/lib/iomgr/udp_server.h +7 -7
  179. data/src/core/lib/iomgr/unix_sockets_posix.c +1 -1
  180. data/src/core/lib/iomgr/unix_sockets_posix_noop.c +2 -1
  181. data/src/core/lib/iomgr/wakeup_fd_posix.h +1 -1
  182. data/src/core/lib/profiling/basic_timers.c +1 -1
  183. data/src/core/lib/security/credentials/credentials.h +1 -1
  184. data/src/core/lib/security/credentials/google_default/google_default_credentials.c +10 -9
  185. data/src/core/lib/security/credentials/jwt/json_token.c +1 -1
  186. data/src/core/lib/security/credentials/jwt/jwt_verifier.c +2 -2
  187. data/src/core/lib/security/transport/client_auth_filter.c +33 -26
  188. data/src/core/lib/security/transport/secure_endpoint.c +8 -5
  189. data/src/core/lib/security/transport/security_connector.c +37 -37
  190. data/src/core/lib/security/transport/security_connector.h +1 -1
  191. data/src/core/lib/security/transport/security_handshaker.c +15 -12
  192. data/src/core/lib/security/transport/server_auth_filter.c +20 -18
  193. data/src/core/lib/security/transport/tsi_error.c +5 -3
  194. data/src/core/lib/security/transport/tsi_error.h +1 -1
  195. data/src/core/lib/{security/util → slice}/b64.c +21 -6
  196. data/src/core/lib/{security/util → slice}/b64.h +16 -4
  197. data/src/core/lib/slice/slice.c +4 -2
  198. data/src/core/lib/slice/slice_buffer.c +16 -14
  199. data/src/core/lib/support/arena.c +98 -0
  200. data/src/core/{ext/client_channel/initial_connect_string.c → lib/support/arena.h} +17 -15
  201. data/src/core/{ext/client_channel/default_initial_connect_string.c → lib/support/atm.c} +14 -5
  202. data/src/core/lib/support/cpu_linux.c +5 -0
  203. data/src/core/lib/support/sync.c +4 -0
  204. data/src/core/lib/support/time.c +4 -10
  205. data/src/core/lib/support/wrap_memcpy.c +3 -1
  206. data/src/core/lib/surface/call.c +252 -221
  207. data/src/core/lib/surface/channel.c +72 -21
  208. data/src/core/lib/surface/channel.h +8 -0
  209. data/src/core/lib/surface/completion_queue.c +2 -3
  210. data/src/core/lib/surface/completion_queue_factory.c +77 -0
  211. data/src/core/lib/surface/completion_queue_factory.h +51 -0
  212. data/src/core/lib/surface/init_secure.c +3 -1
  213. data/src/core/lib/surface/lame_client.c +18 -14
  214. data/src/core/lib/surface/server.c +43 -41
  215. data/src/core/lib/surface/validate_metadata.c +8 -4
  216. data/src/core/lib/surface/version.c +2 -2
  217. data/src/core/lib/transport/bdp_estimator.h +1 -1
  218. data/src/core/lib/transport/connectivity_state.c +2 -1
  219. data/src/core/lib/transport/error_utils.c +17 -17
  220. data/src/core/lib/transport/error_utils.h +1 -1
  221. data/src/core/lib/transport/metadata_batch.c +6 -7
  222. data/src/core/lib/transport/pid_controller.c +1 -0
  223. data/src/core/lib/transport/service_config.c +12 -0
  224. data/src/core/lib/transport/service_config.h +6 -0
  225. data/src/core/lib/transport/transport.c +29 -17
  226. data/src/core/lib/transport/transport.h +85 -42
  227. data/src/core/lib/transport/transport_impl.h +5 -3
  228. data/src/core/lib/transport/transport_op_string.c +20 -14
  229. data/src/core/plugin_registry/grpc_plugin_registry.c +8 -0
  230. data/src/core/{lib/tsi → tsi}/fake_transport_security.c +2 -2
  231. data/src/core/{lib/tsi → tsi}/fake_transport_security.h +4 -4
  232. data/src/core/{lib/tsi → tsi}/ssl_transport_security.c +40 -79
  233. data/src/core/{lib/tsi → tsi}/ssl_transport_security.h +44 -21
  234. data/src/core/{lib/tsi → tsi}/ssl_types.h +3 -3
  235. data/src/core/{lib/tsi → tsi}/transport_security.c +2 -2
  236. data/src/core/{lib/tsi → tsi}/transport_security.h +4 -4
  237. data/src/core/{lib/tsi → tsi}/transport_security_interface.h +3 -3
  238. data/src/ruby/ext/grpc/extconf.rb +1 -0
  239. data/src/ruby/ext/grpc/rb_call_credentials.c +2 -2
  240. data/src/ruby/ext/grpc/rb_channel.c +520 -93
  241. data/src/ruby/ext/grpc/rb_channel.h +2 -0
  242. data/src/ruby/ext/grpc/rb_channel_credentials.c +3 -0
  243. data/src/ruby/ext/grpc/rb_compression_options.c +5 -2
  244. data/src/ruby/ext/grpc/rb_event_thread.c +6 -6
  245. data/src/ruby/ext/grpc/rb_grpc.c +29 -7
  246. data/src/ruby/ext/grpc/rb_grpc.h +2 -0
  247. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +10 -0
  248. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +15 -0
  249. data/src/ruby/ext/grpc/rb_server.c +5 -3
  250. data/src/ruby/lib/grpc/version.rb +1 -1
  251. data/src/ruby/spec/channel_connection_spec.rb +173 -0
  252. data/src/ruby/spec/channel_spec.rb +29 -0
  253. data/src/ruby/spec/generic/rpc_server_pool_spec.rb +27 -17
  254. data/third_party/cares/ares_build.h +264 -0
  255. data/third_party/cares/cares/ares.h +636 -0
  256. data/third_party/cares/cares/ares__close_sockets.c +61 -0
  257. data/third_party/cares/cares/ares__get_hostent.c +261 -0
  258. data/third_party/cares/cares/ares__read_line.c +73 -0
  259. data/third_party/cares/cares/ares__timeval.c +111 -0
  260. data/third_party/cares/cares/ares_cancel.c +63 -0
  261. data/third_party/cares/cares/ares_create_query.c +202 -0
  262. data/third_party/cares/cares/ares_data.c +221 -0
  263. data/third_party/cares/cares/ares_data.h +72 -0
  264. data/third_party/cares/cares/ares_destroy.c +108 -0
  265. data/third_party/cares/cares/ares_dns.h +103 -0
  266. data/third_party/cares/cares/ares_expand_name.c +205 -0
  267. data/third_party/cares/cares/ares_expand_string.c +70 -0
  268. data/third_party/cares/cares/ares_fds.c +59 -0
  269. data/third_party/cares/cares/ares_free_hostent.c +41 -0
  270. data/third_party/cares/cares/ares_free_string.c +25 -0
  271. data/third_party/cares/cares/ares_getenv.c +30 -0
  272. data/third_party/cares/cares/ares_getenv.h +26 -0
  273. data/third_party/cares/cares/ares_gethostbyaddr.c +294 -0
  274. data/third_party/cares/cares/ares_gethostbyname.c +518 -0
  275. data/third_party/cares/cares/ares_getnameinfo.c +422 -0
  276. data/third_party/cares/cares/ares_getopt.c +122 -0
  277. data/third_party/cares/cares/ares_getopt.h +53 -0
  278. data/third_party/cares/cares/ares_getsock.c +66 -0
  279. data/third_party/cares/cares/ares_inet_net_pton.h +25 -0
  280. data/third_party/cares/cares/ares_init.c +2146 -0
  281. data/third_party/cares/cares/ares_iphlpapi.h +221 -0
  282. data/third_party/cares/cares/ares_ipv6.h +78 -0
  283. data/third_party/cares/cares/ares_library_init.c +167 -0
  284. data/third_party/cares/cares/ares_library_init.h +42 -0
  285. data/third_party/cares/cares/ares_llist.c +63 -0
  286. data/third_party/cares/cares/ares_llist.h +39 -0
  287. data/third_party/cares/cares/ares_mkquery.c +24 -0
  288. data/third_party/cares/cares/ares_nowarn.c +260 -0
  289. data/third_party/cares/cares/ares_nowarn.h +61 -0
  290. data/third_party/cares/cares/ares_options.c +402 -0
  291. data/third_party/cares/cares/ares_parse_a_reply.c +264 -0
  292. data/third_party/cares/cares/ares_parse_aaaa_reply.c +264 -0
  293. data/third_party/cares/cares/ares_parse_mx_reply.c +170 -0
  294. data/third_party/cares/cares/ares_parse_naptr_reply.c +188 -0
  295. data/third_party/cares/cares/ares_parse_ns_reply.c +183 -0
  296. data/third_party/cares/cares/ares_parse_ptr_reply.c +219 -0
  297. data/third_party/cares/cares/ares_parse_soa_reply.c +133 -0
  298. data/third_party/cares/cares/ares_parse_srv_reply.c +179 -0
  299. data/third_party/cares/cares/ares_parse_txt_reply.c +220 -0
  300. data/third_party/cares/cares/ares_platform.c +11035 -0
  301. data/third_party/cares/cares/ares_platform.h +43 -0
  302. data/third_party/cares/cares/ares_private.h +363 -0
  303. data/third_party/cares/cares/ares_process.c +1359 -0
  304. data/third_party/cares/cares/ares_query.c +186 -0
  305. data/third_party/cares/cares/ares_rules.h +125 -0
  306. data/third_party/cares/cares/ares_search.c +316 -0
  307. data/third_party/cares/cares/ares_send.c +131 -0
  308. data/third_party/cares/cares/ares_setup.h +217 -0
  309. data/third_party/cares/cares/ares_strcasecmp.c +66 -0
  310. data/third_party/cares/cares/ares_strcasecmp.h +30 -0
  311. data/third_party/cares/cares/ares_strdup.c +49 -0
  312. data/third_party/cares/cares/ares_strdup.h +24 -0
  313. data/third_party/cares/cares/ares_strerror.c +56 -0
  314. data/third_party/cares/cares/ares_timeout.c +88 -0
  315. data/third_party/cares/cares/ares_version.c +11 -0
  316. data/third_party/cares/cares/ares_version.h +24 -0
  317. data/third_party/cares/cares/ares_writev.c +79 -0
  318. data/third_party/cares/cares/bitncmp.c +59 -0
  319. data/third_party/cares/cares/bitncmp.h +26 -0
  320. data/third_party/cares/cares/config-win32.h +377 -0
  321. data/third_party/cares/cares/inet_net_pton.c +450 -0
  322. data/third_party/cares/cares/inet_ntop.c +208 -0
  323. data/third_party/cares/cares/setup_once.h +554 -0
  324. data/third_party/cares/cares/windows_port.c +22 -0
  325. data/third_party/cares/config_darwin/ares_config.h +523 -0
  326. data/third_party/cares/config_linux/ares_config.h +524 -0
  327. metadata +164 -68
@@ -0,0 +1,450 @@
1
+
2
+ /*
3
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
4
+ * Copyright (c) 1996,1999 by Internet Software Consortium.
5
+ *
6
+ * Permission to use, copy, modify, and distribute this software for any
7
+ * purpose with or without fee is hereby granted, provided that the above
8
+ * copyright notice and this permission notice appear in all copies.
9
+ *
10
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
11
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
13
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
16
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
+ */
18
+
19
+ #include "ares_setup.h"
20
+
21
+ #ifdef HAVE_NETINET_IN_H
22
+ # include <netinet/in.h>
23
+ #endif
24
+ #ifdef HAVE_ARPA_INET_H
25
+ # include <arpa/inet.h>
26
+ #endif
27
+ #ifdef HAVE_ARPA_NAMESER_H
28
+ # include <arpa/nameser.h>
29
+ #else
30
+ # include "nameser.h"
31
+ #endif
32
+ #ifdef HAVE_ARPA_NAMESER_COMPAT_H
33
+ # include <arpa/nameser_compat.h>
34
+ #endif
35
+
36
+ #include "ares.h"
37
+ #include "ares_ipv6.h"
38
+ #include "ares_nowarn.h"
39
+ #include "ares_inet_net_pton.h"
40
+
41
+
42
+ const struct ares_in6_addr ares_in6addr_any = { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } };
43
+
44
+
45
+ #ifndef HAVE_INET_NET_PTON
46
+
47
+ /*
48
+ * static int
49
+ * inet_net_pton_ipv4(src, dst, size)
50
+ * convert IPv4 network number from presentation to network format.
51
+ * accepts hex octets, hex strings, decimal octets, and /CIDR.
52
+ * "size" is in bytes and describes "dst".
53
+ * return:
54
+ * number of bits, either imputed classfully or specified with /CIDR,
55
+ * or -1 if some failure occurred (check errno). ENOENT means it was
56
+ * not an IPv4 network specification.
57
+ * note:
58
+ * network byte order assumed. this means 192.5.5.240/28 has
59
+ * 0b11110000 in its fourth octet.
60
+ * note:
61
+ * On Windows we store the error in the thread errno, not
62
+ * in the winsock error code. This is to avoid loosing the
63
+ * actual last winsock error. So use macro ERRNO to fetch the
64
+ * errno this funtion sets when returning (-1), not SOCKERRNO.
65
+ * author:
66
+ * Paul Vixie (ISC), June 1996
67
+ */
68
+ static int
69
+ inet_net_pton_ipv4(const char *src, unsigned char *dst, size_t size)
70
+ {
71
+ static const char xdigits[] = "0123456789abcdef";
72
+ static const char digits[] = "0123456789";
73
+ int n, ch, tmp = 0, dirty, bits;
74
+ const unsigned char *odst = dst;
75
+
76
+ ch = *src++;
77
+ if (ch == '0' && (src[0] == 'x' || src[0] == 'X')
78
+ && ISASCII(src[1])
79
+ && ISXDIGIT(src[1])) {
80
+ /* Hexadecimal: Eat nybble string. */
81
+ if (!size)
82
+ goto emsgsize;
83
+ dirty = 0;
84
+ src++; /* skip x or X. */
85
+ while ((ch = *src++) != '\0' && ISASCII(ch) && ISXDIGIT(ch)) {
86
+ if (ISUPPER(ch))
87
+ ch = tolower(ch);
88
+ n = aresx_sztosi(strchr(xdigits, ch) - xdigits);
89
+ if (dirty == 0)
90
+ tmp = n;
91
+ else
92
+ tmp = (tmp << 4) | n;
93
+ if (++dirty == 2) {
94
+ if (!size--)
95
+ goto emsgsize;
96
+ *dst++ = (unsigned char) tmp;
97
+ dirty = 0;
98
+ }
99
+ }
100
+ if (dirty) { /* Odd trailing nybble? */
101
+ if (!size--)
102
+ goto emsgsize;
103
+ *dst++ = (unsigned char) (tmp << 4);
104
+ }
105
+ } else if (ISASCII(ch) && ISDIGIT(ch)) {
106
+ /* Decimal: eat dotted digit string. */
107
+ for (;;) {
108
+ tmp = 0;
109
+ do {
110
+ n = aresx_sztosi(strchr(digits, ch) - digits);
111
+ tmp *= 10;
112
+ tmp += n;
113
+ if (tmp > 255)
114
+ goto enoent;
115
+ } while ((ch = *src++) != '\0' &&
116
+ ISASCII(ch) && ISDIGIT(ch));
117
+ if (!size--)
118
+ goto emsgsize;
119
+ *dst++ = (unsigned char) tmp;
120
+ if (ch == '\0' || ch == '/')
121
+ break;
122
+ if (ch != '.')
123
+ goto enoent;
124
+ ch = *src++;
125
+ if (!ISASCII(ch) || !ISDIGIT(ch))
126
+ goto enoent;
127
+ }
128
+ } else
129
+ goto enoent;
130
+
131
+ bits = -1;
132
+ if (ch == '/' && ISASCII(src[0]) &&
133
+ ISDIGIT(src[0]) && dst > odst) {
134
+ /* CIDR width specifier. Nothing can follow it. */
135
+ ch = *src++; /* Skip over the /. */
136
+ bits = 0;
137
+ do {
138
+ n = aresx_sztosi(strchr(digits, ch) - digits);
139
+ bits *= 10;
140
+ bits += n;
141
+ if (bits > 32)
142
+ goto enoent;
143
+ } while ((ch = *src++) != '\0' && ISASCII(ch) && ISDIGIT(ch));
144
+ if (ch != '\0')
145
+ goto enoent;
146
+ }
147
+
148
+ /* Firey death and destruction unless we prefetched EOS. */
149
+ if (ch != '\0')
150
+ goto enoent;
151
+
152
+ /* If nothing was written to the destination, we found no address. */
153
+ if (dst == odst)
154
+ goto enoent; /* LCOV_EXCL_LINE: all valid paths above increment dst */
155
+ /* If no CIDR spec was given, infer width from net class. */
156
+ if (bits == -1) {
157
+ if (*odst >= 240) /* Class E */
158
+ bits = 32;
159
+ else if (*odst >= 224) /* Class D */
160
+ bits = 8;
161
+ else if (*odst >= 192) /* Class C */
162
+ bits = 24;
163
+ else if (*odst >= 128) /* Class B */
164
+ bits = 16;
165
+ else /* Class A */
166
+ bits = 8;
167
+ /* If imputed mask is narrower than specified octets, widen. */
168
+ if (bits < ((dst - odst) * 8))
169
+ bits = aresx_sztosi(dst - odst) * 8;
170
+ /*
171
+ * If there are no additional bits specified for a class D
172
+ * address adjust bits to 4.
173
+ */
174
+ if (bits == 8 && *odst == 224)
175
+ bits = 4;
176
+ }
177
+ /* Extend network to cover the actual mask. */
178
+ while (bits > ((dst - odst) * 8)) {
179
+ if (!size--)
180
+ goto emsgsize;
181
+ *dst++ = '\0';
182
+ }
183
+ return (bits);
184
+
185
+ enoent:
186
+ SET_ERRNO(ENOENT);
187
+ return (-1);
188
+
189
+ emsgsize:
190
+ SET_ERRNO(EMSGSIZE);
191
+ return (-1);
192
+ }
193
+
194
+ static int
195
+ getbits(const char *src, int *bitsp)
196
+ {
197
+ static const char digits[] = "0123456789";
198
+ int n;
199
+ int val;
200
+ char ch;
201
+
202
+ val = 0;
203
+ n = 0;
204
+ while ((ch = *src++) != '\0') {
205
+ const char *pch;
206
+
207
+ pch = strchr(digits, ch);
208
+ if (pch != NULL) {
209
+ if (n++ != 0 && val == 0) /* no leading zeros */
210
+ return (0);
211
+ val *= 10;
212
+ val += aresx_sztosi(pch - digits);
213
+ if (val > 128) /* range */
214
+ return (0);
215
+ continue;
216
+ }
217
+ return (0);
218
+ }
219
+ if (n == 0)
220
+ return (0);
221
+ *bitsp = val;
222
+ return (1);
223
+ }
224
+
225
+ static int
226
+ getv4(const char *src, unsigned char *dst, int *bitsp)
227
+ {
228
+ static const char digits[] = "0123456789";
229
+ unsigned char *odst = dst;
230
+ int n;
231
+ unsigned int val;
232
+ char ch;
233
+
234
+ val = 0;
235
+ n = 0;
236
+ while ((ch = *src++) != '\0') {
237
+ const char *pch;
238
+
239
+ pch = strchr(digits, ch);
240
+ if (pch != NULL) {
241
+ if (n++ != 0 && val == 0) /* no leading zeros */
242
+ return (0);
243
+ val *= 10;
244
+ val += aresx_sztoui(pch - digits);
245
+ if (val > 255) /* range */
246
+ return (0);
247
+ continue;
248
+ }
249
+ if (ch == '.' || ch == '/') {
250
+ if (dst - odst > 3) /* too many octets? */
251
+ return (0);
252
+ *dst++ = (unsigned char)val;
253
+ if (ch == '/')
254
+ return (getbits(src, bitsp));
255
+ val = 0;
256
+ n = 0;
257
+ continue;
258
+ }
259
+ return (0);
260
+ }
261
+ if (n == 0)
262
+ return (0);
263
+ if (dst - odst > 3) /* too many octets? */
264
+ return (0);
265
+ *dst = (unsigned char)val;
266
+ return 1;
267
+ }
268
+
269
+ static int
270
+ inet_net_pton_ipv6(const char *src, unsigned char *dst, size_t size)
271
+ {
272
+ static const char xdigits_l[] = "0123456789abcdef",
273
+ xdigits_u[] = "0123456789ABCDEF";
274
+ unsigned char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
275
+ const char *xdigits, *curtok;
276
+ int ch, saw_xdigit;
277
+ unsigned int val;
278
+ int digits;
279
+ int bits;
280
+ size_t bytes;
281
+ int words;
282
+ int ipv4;
283
+
284
+ memset((tp = tmp), '\0', NS_IN6ADDRSZ);
285
+ endp = tp + NS_IN6ADDRSZ;
286
+ colonp = NULL;
287
+ /* Leading :: requires some special handling. */
288
+ if (*src == ':')
289
+ if (*++src != ':')
290
+ goto enoent;
291
+ curtok = src;
292
+ saw_xdigit = 0;
293
+ val = 0;
294
+ digits = 0;
295
+ bits = -1;
296
+ ipv4 = 0;
297
+ while ((ch = *src++) != '\0') {
298
+ const char *pch;
299
+
300
+ if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
301
+ pch = strchr((xdigits = xdigits_u), ch);
302
+ if (pch != NULL) {
303
+ val <<= 4;
304
+ val |= aresx_sztoui(pch - xdigits);
305
+ if (++digits > 4)
306
+ goto enoent;
307
+ saw_xdigit = 1;
308
+ continue;
309
+ }
310
+ if (ch == ':') {
311
+ curtok = src;
312
+ if (!saw_xdigit) {
313
+ if (colonp)
314
+ goto enoent;
315
+ colonp = tp;
316
+ continue;
317
+ } else if (*src == '\0')
318
+ goto enoent;
319
+ if (tp + NS_INT16SZ > endp)
320
+ return (0);
321
+ *tp++ = (unsigned char)((val >> 8) & 0xff);
322
+ *tp++ = (unsigned char)(val & 0xff);
323
+ saw_xdigit = 0;
324
+ digits = 0;
325
+ val = 0;
326
+ continue;
327
+ }
328
+ if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
329
+ getv4(curtok, tp, &bits) > 0) {
330
+ tp += NS_INADDRSZ;
331
+ saw_xdigit = 0;
332
+ ipv4 = 1;
333
+ break; /* '\0' was seen by inet_pton4(). */
334
+ }
335
+ if (ch == '/' && getbits(src, &bits) > 0)
336
+ break;
337
+ goto enoent;
338
+ }
339
+ if (saw_xdigit) {
340
+ if (tp + NS_INT16SZ > endp)
341
+ goto enoent;
342
+ *tp++ = (unsigned char)((val >> 8) & 0xff);
343
+ *tp++ = (unsigned char)(val & 0xff);
344
+ }
345
+ if (bits == -1)
346
+ bits = 128;
347
+
348
+ words = (bits + 15) / 16;
349
+ if (words < 2)
350
+ words = 2;
351
+ if (ipv4)
352
+ words = 8;
353
+ endp = tmp + 2 * words;
354
+
355
+ if (colonp != NULL) {
356
+ /*
357
+ * Since some memmove()'s erroneously fail to handle
358
+ * overlapping regions, we'll do the shift by hand.
359
+ */
360
+ const ssize_t n = tp - colonp;
361
+ ssize_t i;
362
+
363
+ if (tp == endp)
364
+ goto enoent;
365
+ for (i = 1; i <= n; i++) {
366
+ *(endp - i) = *(colonp + n - i);
367
+ *(colonp + n - i) = 0;
368
+ }
369
+ tp = endp;
370
+ }
371
+ if (tp != endp)
372
+ goto enoent;
373
+
374
+ bytes = (bits + 7) / 8;
375
+ if (bytes > size)
376
+ goto emsgsize;
377
+ memcpy(dst, tmp, bytes);
378
+ return (bits);
379
+
380
+ enoent:
381
+ SET_ERRNO(ENOENT);
382
+ return (-1);
383
+
384
+ emsgsize:
385
+ SET_ERRNO(EMSGSIZE);
386
+ return (-1);
387
+ }
388
+
389
+ /*
390
+ * int
391
+ * inet_net_pton(af, src, dst, size)
392
+ * convert network number from presentation to network format.
393
+ * accepts hex octets, hex strings, decimal octets, and /CIDR.
394
+ * "size" is in bytes and describes "dst".
395
+ * return:
396
+ * number of bits, either imputed classfully or specified with /CIDR,
397
+ * or -1 if some failure occurred (check errno). ENOENT means it was
398
+ * not a valid network specification.
399
+ * note:
400
+ * On Windows we store the error in the thread errno, not
401
+ * in the winsock error code. This is to avoid loosing the
402
+ * actual last winsock error. So use macro ERRNO to fetch the
403
+ * errno this funtion sets when returning (-1), not SOCKERRNO.
404
+ * author:
405
+ * Paul Vixie (ISC), June 1996
406
+ */
407
+ int
408
+ ares_inet_net_pton(int af, const char *src, void *dst, size_t size)
409
+ {
410
+ switch (af) {
411
+ case AF_INET:
412
+ return (inet_net_pton_ipv4(src, dst, size));
413
+ case AF_INET6:
414
+ return (inet_net_pton_ipv6(src, dst, size));
415
+ default:
416
+ SET_ERRNO(EAFNOSUPPORT);
417
+ return (-1);
418
+ }
419
+ }
420
+
421
+ #endif /* HAVE_INET_NET_PTON */
422
+
423
+ #ifndef HAVE_INET_PTON
424
+ int ares_inet_pton(int af, const char *src, void *dst)
425
+ {
426
+ int result;
427
+ size_t size;
428
+
429
+ if (af == AF_INET)
430
+ size = sizeof(struct in_addr);
431
+ else if (af == AF_INET6)
432
+ size = sizeof(struct ares_in6_addr);
433
+ else
434
+ {
435
+ SET_ERRNO(EAFNOSUPPORT);
436
+ return -1;
437
+ }
438
+ result = ares_inet_net_pton(af, src, dst, size);
439
+ if (result == -1 && ERRNO == ENOENT)
440
+ return 0;
441
+ return (result > -1 ? 1 : -1);
442
+ }
443
+ #else /* HAVE_INET_PTON */
444
+ int ares_inet_pton(int af, const char *src, void *dst)
445
+ {
446
+ /* just relay this to the underlying function */
447
+ return inet_pton(af, src, dst);
448
+ }
449
+
450
+ #endif
@@ -0,0 +1,208 @@
1
+ /*
2
+ * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
3
+ * Copyright (c) 1996-1999 by Internet Software Consortium.
4
+ *
5
+ * Permission to use, copy, modify, and distribute this software for any
6
+ * purpose with or without fee is hereby granted, provided that the above
7
+ * copyright notice and this permission notice appear in all copies.
8
+ *
9
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
10
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
12
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
15
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
+ */
17
+
18
+ #include "ares_setup.h"
19
+
20
+ #ifdef HAVE_NETINET_IN_H
21
+ # include <netinet/in.h>
22
+ #endif
23
+ #ifdef HAVE_ARPA_INET_H
24
+ # include <arpa/inet.h>
25
+ #endif
26
+ #ifdef HAVE_ARPA_NAMESER_H
27
+ # include <arpa/nameser.h>
28
+ #else
29
+ # include "nameser.h"
30
+ #endif
31
+ #ifdef HAVE_ARPA_NAMESER_COMPAT_H
32
+ # include <arpa/nameser_compat.h>
33
+ #endif
34
+
35
+ #include "ares.h"
36
+ #include "ares_ipv6.h"
37
+
38
+ #ifndef HAVE_INET_NTOP
39
+
40
+ /*
41
+ * WARNING: Don't even consider trying to compile this on a system where
42
+ * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
43
+ */
44
+
45
+ static const char *inet_ntop4(const unsigned char *src, char *dst, size_t size);
46
+ static const char *inet_ntop6(const unsigned char *src, char *dst, size_t size);
47
+
48
+ /* char *
49
+ * inet_ntop(af, src, dst, size)
50
+ * convert a network format address to presentation format.
51
+ * return:
52
+ * pointer to presentation format address (`dst'), or NULL (see errno).
53
+ * note:
54
+ * On Windows we store the error in the thread errno, not
55
+ * in the winsock error code. This is to avoid loosing the
56
+ * actual last winsock error. So use macro ERRNO to fetch the
57
+ * errno this funtion sets when returning NULL, not SOCKERRNO.
58
+ * author:
59
+ * Paul Vixie, 1996.
60
+ */
61
+ const char *
62
+ ares_inet_ntop(int af, const void *src, char *dst, ares_socklen_t size)
63
+ {
64
+ switch (af) {
65
+ case AF_INET:
66
+ return (inet_ntop4(src, dst, (size_t)size));
67
+ case AF_INET6:
68
+ return (inet_ntop6(src, dst, (size_t)size));
69
+ default:
70
+ SET_ERRNO(EAFNOSUPPORT);
71
+ return (NULL);
72
+ }
73
+ /* NOTREACHED */
74
+ }
75
+
76
+ /* const char *
77
+ * inet_ntop4(src, dst, size)
78
+ * format an IPv4 address
79
+ * return:
80
+ * `dst' (as a const)
81
+ * notes:
82
+ * (1) uses no statics
83
+ * (2) takes a unsigned char* not an in_addr as input
84
+ * author:
85
+ * Paul Vixie, 1996.
86
+ */
87
+ static const char *
88
+ inet_ntop4(const unsigned char *src, char *dst, size_t size)
89
+ {
90
+ static const char fmt[] = "%u.%u.%u.%u";
91
+ char tmp[sizeof("255.255.255.255")];
92
+
93
+ if ((size_t)sprintf(tmp, fmt, src[0], src[1], src[2], src[3]) >= size) {
94
+ SET_ERRNO(ENOSPC);
95
+ return (NULL);
96
+ }
97
+ strcpy(dst, tmp);
98
+ return (dst);
99
+ }
100
+
101
+ /* const char *
102
+ * inet_ntop6(src, dst, size)
103
+ * convert IPv6 binary address into presentation (printable) format
104
+ * author:
105
+ * Paul Vixie, 1996.
106
+ */
107
+ static const char *
108
+ inet_ntop6(const unsigned char *src, char *dst, size_t size)
109
+ {
110
+ /*
111
+ * Note that int32_t and int16_t need only be "at least" large enough
112
+ * to contain a value of the specified size. On some systems, like
113
+ * Crays, there is no such thing as an integer variable with 16 bits.
114
+ * Keep this in mind if you think this function should have been coded
115
+ * to use pointer overlays. All the world's not a VAX.
116
+ */
117
+ char tmp[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
118
+ char *tp;
119
+ struct { int base, len; } best, cur;
120
+ unsigned int words[NS_IN6ADDRSZ / NS_INT16SZ];
121
+ int i;
122
+
123
+ /*
124
+ * Preprocess:
125
+ * Copy the input (bytewise) array into a wordwise array.
126
+ * Find the longest run of 0x00's in src[] for :: shorthanding.
127
+ */
128
+ memset(words, '\0', sizeof(words));
129
+ for (i = 0; i < NS_IN6ADDRSZ; i++)
130
+ words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3));
131
+ best.base = -1;
132
+ best.len = 0;
133
+ cur.base = -1;
134
+ cur.len = 0;
135
+ for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
136
+ if (words[i] == 0) {
137
+ if (cur.base == -1)
138
+ cur.base = i, cur.len = 1;
139
+ else
140
+ cur.len++;
141
+ } else {
142
+ if (cur.base != -1) {
143
+ if (best.base == -1 || cur.len > best.len)
144
+ best = cur;
145
+ cur.base = -1;
146
+ }
147
+ }
148
+ }
149
+ if (cur.base != -1) {
150
+ if (best.base == -1 || cur.len > best.len)
151
+ best = cur;
152
+ }
153
+ if (best.base != -1 && best.len < 2)
154
+ best.base = -1;
155
+
156
+ /*
157
+ * Format the result.
158
+ */
159
+ tp = tmp;
160
+ for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
161
+ /* Are we inside the best run of 0x00's? */
162
+ if (best.base != -1 && i >= best.base &&
163
+ i < (best.base + best.len)) {
164
+ if (i == best.base)
165
+ *tp++ = ':';
166
+ continue;
167
+ }
168
+ /* Are we following an initial run of 0x00s or any real hex? */
169
+ if (i != 0)
170
+ *tp++ = ':';
171
+ /* Is this address an encapsulated IPv4? */
172
+ if (i == 6 && best.base == 0 && (best.len == 6 ||
173
+ (best.len == 7 && words[7] != 0x0001) ||
174
+ (best.len == 5 && words[5] == 0xffff))) {
175
+ if (!inet_ntop4(src+12, tp, sizeof(tmp) - (tp - tmp)))
176
+ return (NULL);
177
+ tp += strlen(tp);
178
+ break;
179
+ }
180
+ tp += sprintf(tp, "%x", words[i]);
181
+ }
182
+ /* Was it a trailing run of 0x00's? */
183
+ if (best.base != -1 && (best.base + best.len) ==
184
+ (NS_IN6ADDRSZ / NS_INT16SZ))
185
+ *tp++ = ':';
186
+ *tp++ = '\0';
187
+
188
+ /*
189
+ * Check for overflow, copy, and we're done.
190
+ */
191
+ if ((size_t)(tp - tmp) > size) {
192
+ SET_ERRNO(ENOSPC);
193
+ return (NULL);
194
+ }
195
+ strcpy(dst, tmp);
196
+ return (dst);
197
+ }
198
+
199
+ #else /* HAVE_INET_NTOP */
200
+
201
+ const char *
202
+ ares_inet_ntop(int af, const void *src, char *dst, ares_socklen_t size)
203
+ {
204
+ /* just relay this to the underlying function */
205
+ return inet_ntop(af, src, dst, size);
206
+ }
207
+
208
+ #endif /* HAVE_INET_NTOP */