DhcpInfo isn't responding the netmask in Android Lollipop

1.5k views Asked by At

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.

1

There are 1 answers

1
phaethon On BEST ANSWER

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.)