func hostToIP(net, host string) (ip netpkg.IP, err error) {
	var addr netpkg.IP
	addr = netpkg.ParseIP(host)
	if addr == nil {
		filter := anyaddr
		if net != "" && net[len(net)-1] == '4' {
			filter = ipv4only
		}
		if net != "" && net[len(net)-1] == '6' {
			filter = ipv6only
		}
		addrs, err1 := LookupHost(host)
		if err1 != nil {
			err = err1
			goto Error
		}
		addr = firstFavoriteAddr(filter, addrs)
		if addr == nil {
			err = &netpkg.AddrError{"LookupHost returned no suitable address", addrs[0]}
			goto Error
		}
	}
	return addr, nil
Error:
	return nil, err
}
Convert "host" into IP address.
package dns
import (
	netpkg "net"
	"strconv"
)
const (
	supportsIPv6    = true
	supportsIPv4map = true
)
func firstFavoriteAddr(filter func(netpkg.IP) netpkg.IP, addrs []string) (addr netpkg.IP) {
	if filter == nil {
		addr = firstSupportedAddr(ipv4only, addrs)
		if addr == nil {
			addr = firstSupportedAddr(anyaddr, addrs)
		}
	} else {
		addr = firstSupportedAddr(filter, addrs)
	}
	return
}
func firstSupportedAddr(filter func(netpkg.IP) netpkg.IP, addrs []string) netpkg.IP {
	for _, s := range addrs {
		if addr := filter(netpkg.ParseIP(s)); addr != nil {
			return addr
		}
	}
	return nil
}
func anyaddr(x netpkg.IP) netpkg.IP {
	if x4 := x.To4(); x4 != nil {
		return x4
	}
	if supportsIPv6 {
		return x
	}
	return nil
}
func ipv4only(x netpkg.IP) netpkg.IP { return x.To4() }
func ipv6only(x netpkg.IP) netpkg.IP {
	if len(x) == netpkg.IPv6len && x.To4() == nil && supportsIPv6 {
		return x
	}
	return nil
}
func hostPortToIP(net, hostport string) (ip netpkg.IP, iport int, err error) {
	host, port, err := netpkg.SplitHostPort(hostport)
	if err != nil {
		return nil, 0, err
	}
	var addr netpkg.IP
	if host != "" {
		addr = netpkg.ParseIP(host)
		if addr == nil {
			var filter func(netpkg.IP) netpkg.IP
			if net != "" && net[len(net)-1] == '4' {
				filter = ipv4only
			}
			if net != "" && net[len(net)-1] == '6' {
				filter = ipv6only
			}
			addrs, err := LookupHost(host)
			if err != nil {
				return nil, 0, err
			}
			addr = firstFavoriteAddr(filter, addrs)
			if addr == nil {
				return nil, 0, &netpkg.AddrError{"LookupHost returned no suitable address", addrs[0]}
			}
		}
	}
	p, err := strconv.Atoi(port)
	if err != nil {
		p, err = netpkg.LookupPort(net, port)
		if err != nil {
			return nil, 0, err
		}
	}
	if p < 0 || p > 0xFFFF {
		return nil, 0, &netpkg.AddrError{"invalid port", port}
	}
	return addr, p, nil
}