1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-16 09:26:21 -05:00
This commit is contained in:
Darien Raymond 2018-11-22 19:07:49 +01:00
parent 9d17221266
commit 39a092b178
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 10 additions and 7 deletions

View File

@ -76,8 +76,9 @@ func NewStaticHosts(hosts []*Config_HostMapping, legacy map[string]*net.IPOrDoma
func filterIP(ips []net.IP, option IPOption) []net.IP { func filterIP(ips []net.IP, option IPOption) []net.IP {
filtered := make([]net.IP, 0, len(ips)) filtered := make([]net.IP, 0, len(ips))
for _, ip := range ips { for _, ip := range ips {
if (len(ip) == net.IPv4len && option.IPv4Enable) || (len(ip) == net.IPv6len && option.IPv6Enable) { parsed := net.IPAddress(ip)
filtered = append(filtered, ip) if (parsed.Family().IsIPv4() && option.IPv4Enable) || (parsed.Family().IsIPv6() && option.IPv6Enable) {
filtered = append(filtered, parsed.IP())
} }
} }
if len(filtered) == 0 { if len(filtered) == 0 {

View File

@ -2,8 +2,8 @@ package localdns
import ( import (
"context" "context"
"net"
"v2ray.com/core/common/net"
"v2ray.com/core/features/dns" "v2ray.com/core/features/dns"
) )
@ -43,8 +43,9 @@ func (c *Client) LookupIPv4(host string) ([]net.IP, error) {
} }
var ipv4 []net.IP var ipv4 []net.IP
for _, ip := range ips { for _, ip := range ips {
if len(ip) == net.IPv4len { parsed := net.IPAddress(ip)
ipv4 = append(ipv4, ip) if parsed.Family().IsIPv4() {
ipv4 = append(ipv4, parsed.IP())
} }
} }
return ipv4, nil return ipv4, nil
@ -57,8 +58,9 @@ func (c *Client) LookupIPv6(host string) ([]net.IP, error) {
} }
var ipv6 []net.IP var ipv6 []net.IP
for _, ip := range ips { for _, ip := range ips {
if len(ip) == net.IPv6len { parsed := net.IPAddress(ip)
ipv6 = append(ipv6, ip) if parsed.Family().IsIPv6() {
ipv6 = append(ipv6, parsed.IP())
} }
} }
return ipv6, nil return ipv6, nil