title: Find netMask on Android device
body: <p>I have to find information about the network to which the Android device is connected. Basically the Android device is a Android TV and it has WiFi and Ethernet connectivity.<br>
  I am working with WiFi and getting all the correct information except <code>netMask</code> as it is always showing <b>0</b> (zero), whereas it should show <b>255.255.255.0</b></p>
  
  <p>Following is the code that I'm using:</p>
  
  <pre><code>wifiMgr= (WifiManager) getSystemService(Context.WIFI_SERVICE);
  dhcpInfo=wifiMgr.getDhcpInfo();
  
  vDns1="DNS 1: "+intToIp(dhcpInfo.dns1);
  vDns2="DNS 2: "+intToIp(dhcpInfo.dns2);
  vGateway="Default Gateway: "+intToIp(dhcpInfo.gateway);
  vIpAddress="IP Address: "+intToIp(dhcpInfo.ipAddress);
  vLeaseDuration="Lease Time: "+String.valueOf(dhcpInfo.leaseDuration);
  vNetmask="Subnet Mask: "+intToIp(dhcpInfo.netmask);
  vServerAddress="Server IP: "+intToIp(dhcpInfo.serverAddress);
  </code></pre>
  
  <p>Definition for <code>intToIp(int)</code>:</p>
  
  <pre><code>public String intToIp(int i) {
  
      return ((i &gt;&gt; 24 ) &amp; 0xFF ) + "." +
              ((i &gt;&gt; 16 ) &amp; 0xFF) + "." +
              ((i &gt;&gt; 8 ) &amp; 0xFF) + "." +
              ( i &amp; 0xFF) ;
  }
  </code></pre>
  
  <p>The <code>AndroidManifest.xml</code>:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/&gt;
  &lt;uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /&gt;
  </code></pre>
  
  <p>Why is this happening and how can I fix it?</p>