Fix: ip version check
This commit is contained in:
parent
045c3a3ad4
commit
c38469330d
2 changed files with 6 additions and 5 deletions
|
@ -37,8 +37,8 @@ func ResolveIPv4(host string) (net.IP, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, ip := range ipAddrs {
|
for _, ip := range ipAddrs {
|
||||||
if len(ip) == net.IPv4len {
|
if ip4 := ip.To4(); ip4 != nil {
|
||||||
return ip, nil
|
return ip4, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ func ResolveIPv6(host string) (net.IP, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, ip := range ipAddrs {
|
for _, ip := range ipAddrs {
|
||||||
if len(ip) == net.IPv6len {
|
if ip.To4() == nil {
|
||||||
return ip, nil
|
return ip, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,9 +222,10 @@ 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) {
|
func (r *Resolver) resolveIP(host string, dnsType uint16) (ip net.IP, err error) {
|
||||||
ip = net.ParseIP(host)
|
ip = net.ParseIP(host)
|
||||||
if ip != nil {
|
if ip != nil {
|
||||||
if dnsType == D.TypeAAAA && len(ip) == net.IPv6len {
|
isIPv4 := ip.To4() != nil
|
||||||
|
if dnsType == D.TypeAAAA && !isIPv4 {
|
||||||
return ip, nil
|
return ip, nil
|
||||||
} else if dnsType == D.TypeA && len(ip) == net.IPv4len {
|
} else if dnsType == D.TypeA && isIPv4 {
|
||||||
return ip, nil
|
return ip, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue