lncfg: use net pkg IsLoopback method

Use the IsLoopback method provided by the net package instead of using
hardcoded loopback addresses.
This commit is contained in:
Elle Mouton committed 2022-03-30 13:21:50 +02:00
1 parent c6e96c67ce
commit c582438a4e
1 file changed
+10 -10
+10 -10
View File
@@ -14,10 +14,6 @@ import (
"github.com/lightningnetwork/lnd/tor"
)
var (
loopBackAddrs = []string{"localhost", "127.0.0.1", "[::1]"}
)
// TCPResolver is a function signature that resolves an address on a given
// network.
type TCPResolver = func(network, addr string) (*net.TCPAddr, error)
@@ -112,14 +108,18 @@ func TLSListenOnAddress(addr net.Addr,
}
// IsLoopback returns true if an address describes a loopback interface.
func IsLoopback(addr string) bool {
for _, loopback := range loopBackAddrs {
if strings.Contains(addr, loopback) {
return true
}
func IsLoopback(host string) bool {
if strings.Contains(host, "localhost") {
return true
}
return false
rawHost, _, _ := net.SplitHostPort(host)
addr := net.ParseIP(rawHost)
if addr == nil {
return false
}
return addr.IsLoopback()
}
// isIPv6Host returns true if the host is IPV6 and false otherwise.