lncfg: use net.ParseIP to detect IPv6 addresses

This commit is contained in:
Olaoluwa Osuntokun 2021-02-10 18:35:44 -08:00
parent 80eb5dbece
commit 099efadd92
No known key found for this signature in database
GPG Key ID: 3BBD59E99B280306

@ -123,8 +123,14 @@ func IsLoopback(addr string) bool {
// isIPv6Host returns true if the host is IPV6 and false otherwise.
func isIPv6Host(host string) bool {
// An IPv4 host without the port shouldn't have a colon.
return strings.Contains(host, ":")
v6Addr := net.ParseIP(host)
if v6Addr == nil {
return false
}
// The documentation states that if the IP address is an IPv6 address,
// then To4() will return nil.
return v6Addr.To4() == nil
}
// IsUnix returns true if an address describes an Unix socket address.