dns: Fix segfault with mixed ipv4/ipv6 nameservers

Follow-up on bug #1154432.