mirror of https://github.com/v2ray/v2ray-core
fix IP parsing in local dns client
parent
30b5bffad4
commit
21b3f66b8b
|
@ -21,7 +21,18 @@ func (*Client) Close() error { return nil }
|
|||
|
||||
// LookupIP implements Client.
|
||||
func (*Client) LookupIP(host string) ([]net.IP, error) {
|
||||
return net.LookupIP(host)
|
||||
ips, err := net.LookupIP(host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
parsedIPs := make([]net.IP, 0, len(ips))
|
||||
for _, ip := range parsedIPs {
|
||||
parsed := net.IPAddress(ip)
|
||||
if parsed != nil {
|
||||
parsedIPs = append(parsedIPs, parsed.IP())
|
||||
}
|
||||
}
|
||||
return parsedIPs, nil
|
||||
}
|
||||
|
||||
// LookupIPv4 implements IPv4Lookup.
|
||||
|
@ -30,11 +41,10 @@ func (c *Client) LookupIPv4(host string) ([]net.IP, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var ipv4 []net.IP
|
||||
ipv4 := make([]net.IP, 0, len(ips))
|
||||
for _, ip := range ips {
|
||||
parsed := net.IPAddress(ip)
|
||||
if parsed.Family().IsIPv4() {
|
||||
ipv4 = append(ipv4, parsed.IP())
|
||||
if len(ip) == net.IPv4len {
|
||||
ipv4 = append(ipv4, ip)
|
||||
}
|
||||
}
|
||||
return ipv4, nil
|
||||
|
@ -46,11 +56,10 @@ func (c *Client) LookupIPv6(host string) ([]net.IP, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var ipv6 []net.IP
|
||||
ipv6 := make([]net.IP, 0, len(ips))
|
||||
for _, ip := range ips {
|
||||
parsed := net.IPAddress(ip)
|
||||
if parsed.Family().IsIPv6() {
|
||||
ipv6 = append(ipv6, parsed.IP())
|
||||
if len(ip) == net.IPv6len {
|
||||
ipv6 = append(ipv6, ip)
|
||||
}
|
||||
}
|
||||
return ipv6, nil
|
||||
|
|
Loading…
Reference in New Issue