Fix detection of loopback address on ipv6.

Closes #385.