Search code examples
socketsdnsethernetandroid-4.4-kitkatgethostbyname

DNS resolution fails for ethernet in my Android device(android 4.4.2)


I am trying to enable wired ethernet on my device which runs on android 4.4.I am successful in getting the eth0 interface up. But DNS resolution is not happening.Pinging the address from adb works fine.(if I connect to my router once through WiFi then onwards dns is getting resolved and can browse with ethernet).One more observation is that this problem does not exist if I use Firefox instead of default browser.

From the logs it is clear that gethostbyname() call is failing.When i tracked further it is clear that proxy socket opened in android_open_proxy() function does not contain proper values.

    /*   reading proxy-- proxy -->/dev/socket/dnsproxyd ..*/

if (fread(buf, 1, sizeof(buf), proxy) != sizeof(buf)) return NULL;

    /* This is reading serialized data from system/netd/DnsProxyListener.cpp
     * and changes here need to be matched there */
    int result_code = strtol(buf, NULL, 10);

***here result_code is 401 (in succes case it is 222).


Solution

  • It's noteworthy that Motorola has modified parts of the DNS resolution code (in the Bionic libc library) in its phones, so mentioning which device you have might help narrowing the issue.

    p.s. the 'ndc resolver' command may be necessary to change default dns configuration. example:

    ndc resolver setifdns wlan0 "" 192.168.0.1
    ndc resolver setdefaultif if wlan0