DNS bugfixes

This fixes a few bugs in the DNS code, and introduces a test to avoid some of them happening again. 
(used to be the case that logging in with login `foo` and password `bar` caused an undefined error, now it at least causes `errnoException` to be called vaguely sensibly.)