Support IPv6, make it usable on an IPv6-only host

Instead of unconditionally using a module IO::Socket::INET
which does not support IPv6 protocol family, try to use the
modern IO::Socket::IP, falling back to older IO::Socket::INET6,
or ultimately to IO::Socket::INET if that is the only module
available. Instead of assuming the loopback interface has
an IP address 127.0.0.1 (which it may not have, e.g. on an
IPv6-only host its only IP address is ::1), use a host name
'localhost', which is recognized by all three IO::Socket::*
modules and resolve to whatever IP address is available.