Change: ipv6 logic
This commit is contained in:
@ -12,13 +12,18 @@ var (
|
||||
// DefaultResolver aim to resolve ip
|
||||
DefaultResolver Resolver
|
||||
|
||||
// DisableIPv6 means don't resolve ipv6 host
|
||||
// default value is true
|
||||
DisableIPv6 = true
|
||||
|
||||
// DefaultHosts aim to resolve hosts
|
||||
DefaultHosts = trie.New()
|
||||
)
|
||||
|
||||
var (
|
||||
ErrIPNotFound = errors.New("couldn't find ip")
|
||||
ErrIPVersion = errors.New("ip version error")
|
||||
ErrIPNotFound = errors.New("couldn't find ip")
|
||||
ErrIPVersion = errors.New("ip version error")
|
||||
ErrIPv6Disabled = errors.New("ipv6 disabled")
|
||||
)
|
||||
|
||||
type Resolver interface {
|
||||
@ -63,6 +68,10 @@ func ResolveIPv4(host string) (net.IP, error) {
|
||||
|
||||
// ResolveIPv6 with a host, return ipv6
|
||||
func ResolveIPv6(host string) (net.IP, error) {
|
||||
if DisableIPv6 {
|
||||
return nil, ErrIPv6Disabled
|
||||
}
|
||||
|
||||
if node := DefaultHosts.Search(host); node != nil {
|
||||
if ip := node.Data.(net.IP).To16(); ip != nil {
|
||||
return ip, nil
|
||||
@ -102,7 +111,12 @@ func ResolveIP(host string) (net.IP, error) {
|
||||
}
|
||||
|
||||
if DefaultResolver != nil {
|
||||
if DisableIPv6 {
|
||||
return DefaultResolver.ResolveIPv4(host)
|
||||
}
|
||||
return DefaultResolver.ResolveIP(host)
|
||||
} else if DisableIPv6 {
|
||||
return ResolveIPv4(host)
|
||||
}
|
||||
|
||||
ip := net.ParseIP(host)
|
||||
|
Reference in New Issue
Block a user