Finding nameservers in Android 4.2

I’m having some trouble finding out how to pull out the currently active nameservers in recent versions of Android. This goes back to the SetDNS app that I’ve been maintaining on and off for a few years since writing it.

I’ve had a new version 90% written for about a year. I keep going back to it and think about releasing it, but I’m really unhappy with the way that I can’t detect what the current nameservers on the device are. So I can throw IP addresses into the ndc binary with resolver commands, but I can’t get anything back with whether it was a success or what the current IPs are.

So, setting the nameservers is achived by running:

/system/bin/ndc resolver setifdns [interface] [dns1] [dns2]

but for general usefulness, it’s handy to know if the settings have actually changed.

My current plan is to work through the Android bionic source code – specifically the resolv section. Then to try and augment the functions there with a binary written using the Android NDK.

It might all be hopeless, but I’d prefer to have something that worked in the same way as the old app, rather than something that feels like a kludge.

Having said all that, I’m conscious that the app doesn’t work for a lot of people and so I’m close to just kicking out a version that sets the nameservers without any visual feedback in the app. I’m not sure if that’s a good idea. If I come up with something then I’ll post it here.