简体   繁体   中英

How to resolve dns in android?

I am using Android NDK and a C++ project linked with a JNI wrapper to build my android app. The C++ project consists of several basic functions, one of them is DNS lookup. I am using ares_gethostbyname API to resolve DNS. But there is an error, DNS lookup fails for android. But in other platforms it works fine. I couldn't find the probable cause. I have checked the address that passes from the app. It's correct. But it fails to resolve DNS. Can anyone help me on this issue?

Yes it will not work with in UDP-Blocked environment. The root cause is, DNS resolution is done by using UDP ports in gethostbyname(). Though it is documented that getaddrinfo() can be used to resolve dns name using both udp and tcp port. But I am not sure whether it works or not in UDP blocked environment. Though you can try using it.

Solved that. In android dns lookup is not possible in UDP-BLOCKED environment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM