lxd/util/net.go
func IsAddressCovered(address1, address2 string) bool {
	if address1 == address2 {
		return true
	}

	host1, port1, err := net.SplitHostPort(address1)
	if err != nil {
		return false
	}

	host2, port2, err := net.SplitHostPort(address2)
	if err != nil {
		return false
	}

	// If the ports are different, then address1 is clearly not covered by
	// address2.
	if port2 != port1 {
		return false
	}

	// If address2 is using an IPv4 wildcard for the host, then address2 is
	// only covered if it's an IPv4 address.
	if host2 == "0.0.0.0" {
		ip := net.ParseIP(host1)
		if ip != nil && ip.To4() != nil {
			return true
		}
		return false
	}

	// If address2 is using an IPv6 wildcard for the host, then address2 is
	// always covered.
	if host2 == "::" || host2 == "" {
		return true
	}

	return false
}
func IsAddressCovered(address1, address2 string) bool {
	if address1 == address2 {
		return true
	}

	host1, port1, err := net.SplitHostPort(address1)
	if err != nil {
		return false
	}

	host2, port2, err := net.SplitHostPort(address2)
	if err != nil {
		return false
	}

	// If the ports are different, then address1 is clearly not covered by
	// address2.
	if port2 != port1 {
		return false
	}

	// If address2 is using an IPv4 wildcard for the host, then address2 is
	// only covered if it's an IPv4 address.
	if host2 == "0.0.0.0" {
		ip := net.ParseIP(host1)
		if ip != nil && ip.To4() != nil {
			return true
		}
		return false
	}

	// If address2 is using an IPv6 wildcard for the host, then address2 is
	// always covered.
	if host2 == "::" || host2 == "" {
		return true
	}

	return false
}
func IsAddressCovered ( address1 , address2 string ) bool { if address1 == address2 { return true } host1 , port1 , err := net . SplitHostPort ( address1 ) if err != nil { return false } host2 , port2 , err := net . SplitHostPort ( address2 ) if err != nil { return false } // If the ports are different, then address1 is clearly not covered by // address2. if port2 != port1 { return false } // If address2 is using an IPv4 wildcard for the host, then address2 is // only covered if it's an IPv4 address. if host2 == " " { ip := net . ParseIP ( host1 ) if ip != nil && ip . To4 ( ) != nil { return true } return false } // If address2 is using an IPv6 wildcard for the host, then address2 is // always covered. if host2 == " " || host2 == " " { return true } return false }
// IsAddressCovered detects if network address1 is actually covered by
// address2, in the sense that they are either the same address or address2 is
// specified using a wildcard with the same port of address1.
IsAddressCovered detects if network address1 is actually covered by address2 in the sense that they are either the same address or address2 is specified using a wildcard with the same port of address1 .