Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DhcpInfo isn't responding the netmask in Android Lollipop

Yesterday I update my nexus 5 to lollipop and my application stops working, after a little investigation I found the problem the DhcpInfo isn't is returning null on the netmask variable.

I couldn't find any alternative to this class.

like image 657
Carlos EduardoL Avatar asked Nov 14 '14 15:11

Carlos EduardoL


1 Answers

You can use getNetworkPrefixLength method of InterfaceAddress, which you get from NetworkInterface. It returns the correct value in Lollipop.

NetworkInterface networkInterface = NetworkInterface.getByInetAddress(ipAddress);
for (InterfaceAddress address : networkInterface.getInterfaceAddresses()) {
    short netPrefix = address.getNetworkPrefixLength());
}

Note: It returns network prefix length, so you'd have to convert it (/24 for 255.255.255.0 etc.)

like image 90
phaethon Avatar answered Oct 24 '22 12:10

phaethon