一个问题
在实际的开发中遇到了不能域名解析的情况,在网上搜集了大量的资料,发现有网友遇到了和我一样的状况,所以把查找的资料汇总一下,作个记录。以下信息摘自这里:
I’m using libcurl 7.29.0 on Android with c-ares 1.9.1.
I’ve been noticing a bug on a Samsung Galaxy S3 & Samsung Galaxy Note 2 (and possibly other devices too) when the bearer switches from wifi to 3G where I can no longer connect to a host.
If I undefine USE_ARES (build without c-ares) then this issue is gone, but I would like to keep c-ares for performance.
Some other (useful?) info:
1) Switching back to the original bearer will allow a connection again
2) I tried performing a curl_global_cleanup() and curl_global_init(CURL_GLOBAL_ALL) during the switch, but it didn’t seem to help.If anyone knows of anything that I can do to continue to use c-ares I would greatly appreciate it!
Android NDK 编译c-ares
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
adns接口介绍及示例
adns是一个开源的dns解析库,官方文档点击这里。
初始化
1 2 3 |
|
函数原型:
1
|
|
举例:
1
|
|
提交待解析的域名
函数原型:
1 2 3 4 5 6 |
|
举例:
1
|
|
检测是否有域名已检测完成
函数原型:
1 2 3 4 |
|
举例:
1
|
|
函数原型:
1 2 3 4 |
|
举例:
1
|
|
检测是否已完成所有提交的域名的解析
函数原型:
1
|
|
举例:
1
|
|
示例代码testdns.c
(解析IPv4地址可使用adns v1.2或adns v1.4,解析IPv6地址使用adns v1.6):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
Makefile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
下载adns-1.2的源码,然后解压,到adns-1.2/
目录下执行./configure
,进入到src/
目录并加入以上的testdns.c
、Makefile
两个文件,make
编译后就得到了我们需要的测试程序。
参考链接:
libcurl + c-ares on Android
Android NDK 编译c-ares
c-ares
adns解析库——域名解析实例(C++、linux)
GNU adns