Fix: clearer error and ipv6 string parse (#325)

This commit is contained in:
Comzyh
2019-09-27 10:33:37 +08:00
committed by Dreamacro
parent 904c354ee4
commit 045c3a3ad4
3 changed files with 33 additions and 19 deletions

View File

@ -221,13 +221,11 @@ func (r *Resolver) fallbackExchange(m *D.Msg) (msg *D.Msg, err error) {
func (r *Resolver) resolveIP(host string, dnsType uint16) (ip net.IP, err error) {
ip = net.ParseIP(host)
if dnsType == D.TypeAAAA {
if ip6 := ip.To16(); ip6 != nil {
return ip6, nil
}
} else {
if ip4 := ip.To4(); ip4 != nil {
return ip4, nil
if ip != nil {
if dnsType == D.TypeAAAA && len(ip) == net.IPv6len {
return ip, nil
} else if dnsType == D.TypeA && len(ip) == net.IPv4len {
return ip, nil
}
}