Skip to content

Commit

Permalink
lncfg: use net.ParseIP to detect IPv6 addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
Roasbeef committed Feb 11, 2021
1 parent 80eb5db commit 099efad
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lncfg/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 099efad

Please sign in to comment.