c# - Xamarin.Android DhcpInfo.Netmask returns 0 -


i'm trying network address dhcpinfo.netmask net mask 0, though device connected wifi network. code i'm using:

namespace checks { [activity(label = "checks", mainlauncher = true, icon = "@drawable/icon")] public class mainactivity : activity {     protected override void oncreate(bundle bundle)     {         base.oncreate(bundle);         setcontentview (resource.layout.main);          button databutton = findviewbyid<button>(resource.id.connectiondatabutton);          databutton.click += (object sender, eventargs e) =>         {              wifimanager wifimanager = (wifimanager)getsystemservice(context.wifiservice);             var d = wifimanager.dhcpinfo;              console.writeline("my net mask: {0}", d.netmask);            };      } } 

}

i'm trying network address dhcpinfo.netmask net mask 0, though device connected wifi network.

this known issue.

as workaround, can use following codes networkprefixlength , convert netmask this table:

wifimanager wifimanager = (wifimanager)getsystemservice(context.wifiservice); dhcpinfo dhcpinfo = wifimanager.dhcpinfo; try {     byte[] ipaddress = bitconverter.getbytes(dhcpinfo.ipaddress);     inetaddress inetaddress = inetaddress.getbyaddress(ipaddress);     networkinterface networkinterface = networkinterface.getbyinetaddress(inetaddress);     foreach (interfaceaddress address in networkinterface.interfaceaddresses)     {         //short netprefix = address.getnetworkprefixlength();          //log.d(tag, address.tostring());         var prefix=address.networkprefixlength;     } } catch (ioexception exception) {     log.debug("exception:", exception.message); } 

Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -