Can't do reverse DNS lookup on Android
<p>I have an Android device connected to Wifi network with an IP address. I did NS lookup on my linux computer of this IP address and verified that there is a corresponding hostname for that IP address.</p>

<p>I have a piece of Java code, which when run on my Windows PC does reverse DNS lookup fine (returns a hostname):</p>

<pre><code>        String dnSuffix;
        String ipAddress = "10.228.59.217";
   InetAddress inetAddr;
    try {
        //inetAddr = InetAddress.getLocalHost();
        inetAddr = InetAddress.getByName(ipAddress);
        //System.out.println("inetAddr = " + inetAddr);
        Log.v(LOG_TAG, "inetAddr = " + inetAddr);
        if (inetAddr != null) {
            dnSuffix = inetAddr.getHostName();
            //System.out.println("dnSuffix is " + dnSuffix);
            Log.v(LOG_TAG,"dnSuffix is " + dnSuffix); 
        }
    } catch (UnknownHostException e) {
        //System.out.println("Error getting DN suffix: " + e.getMessage());
        Log.v(LOG_TAG,"Error getting DN suffix: " + e.getMessage());
    }
</code></pre>

<p>dnSuffix is the hostname as expected on Windows.</p>

<p>But on Android, it returns an IP address instead of a hostname, which indicates that it failed.</p>

<p>I have all the permissions that I would think I need for this in my app:</p>

<pre><code>&lt;uses-permission android:name="android.permission.INTERNET"&gt;&lt;/uses-permission&gt;
&lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" &gt;&lt;/uses-permission&gt;
&lt;uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /&gt;
&lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
</code></pre>

<p>I found this documentation:</p>

<p>getCanonicalHostName</p>

<p>public String getCanonicalHostName()</p>

<p>Gets the fully qualified domain name for this IP address. Best effort method, meaning we may not be able to return the FQDN depending on the underlying system configuration.
If there is a security manager, this method first calls its checkConnect method with the hostname and -1 as its arguments to see if the calling code is allowed to know the hostname for this IP address, i.e., to connect to the host. If the operation is not allowed, it will return the textual representation of the IP address.</p>

<p>Returns:</p>

<p>the fully qualified domain name for this IP address, or if the operation is not allowed by the security check, the textual representation of the IP address.</p>

<p>Since:</p>

<p>1.4</p>

<p>See Also:</p>

<p>SecurityManager.checkConnect(java.lang.String, int)</p>

<p>I also found someone having similar problem:
<a href="https://groups.google.com/forum/#!msg/android-security-discuss/nVUoTz_zQBI/ZL4tzSbHbqoJ" rel="nofollow">https://groups.google.com/forum/#!msg/android-security-discuss/nVUoTz_zQBI/ZL4tzSbHbqoJ</a></p>

<p>But no resolution.</p>

<p>Can anyone provide any help at all?</p>
