From 099efadd92fd90527163e26ededfd26db0315dcb Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 10 Feb 2021 18:35:44 -0800 Subject: [PATCH] lncfg: use net.ParseIP to detect IPv6 addresses --- lncfg/address.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lncfg/address.go b/lncfg/address.go index 0681be96..9f91552f 100644 --- a/lncfg/address.go +++ b/lncfg/address.go @@ -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.