slice.Max has a bug, writing my own Max()
parent
f1c46ed9f1
commit
636434a0cf
24
interface.go
24
interface.go
|
@ -165,19 +165,9 @@ func (b *AbstractBridge) IsAssigned() bool {
|
|||
var (
|
||||
ief *net.Interface
|
||||
addrs []net.Addr
|
||||
ipv4Addr net.IP
|
||||
err error
|
||||
bridgeip string
|
||||
)
|
||||
|
||||
brIp, _, err := net.ParseCIDR(b.BridgeIpCIDR)
|
||||
if err != nil {
|
||||
log.Println("IsActive : problem parsing the IP/CIDR: ", err.Error())
|
||||
return false
|
||||
} else {
|
||||
bridgeip = brIp.String()
|
||||
}
|
||||
|
||||
interfaceName := b.ExistingInterface
|
||||
|
||||
if ief, err = net.InterfaceByName(interfaceName); err != nil { // get interface
|
||||
|
@ -196,20 +186,14 @@ func (b *AbstractBridge) IsAssigned() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
for _, addr := range addrs { // get ipv4 address
|
||||
if ipv4Addr = addr.(*net.IPNet).IP.To4(); ipv4Addr != nil {
|
||||
log.Printf("Error reading IPs for interface %s\n", interfaceName)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
for _, addr := range addrs {
|
||||
if addr.String() == bridgeip {
|
||||
log.Printf("Ip %s is assigned to interface %s", bridgeip, interfaceName)
|
||||
log.Println("Address found is: ", addr.String())
|
||||
if addr.String() == b.BridgeIpCIDR {
|
||||
log.Printf("Ip %s is assigned to interface %s", b.BridgeIpCIDR, interfaceName)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("Ip %s is NOT assigned to interface %s", bridgeip, interfaceName)
|
||||
log.Printf("Ip %s is NOT assigned to interface %s", b.BridgeIpCIDR, interfaceName)
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -22,9 +22,16 @@ func (mip *AbstractMulticast) AddUniqueAndSort(hier int64) {
|
|||
|
||||
func (mip *AbstractMulticast) IsAlpha(hier int64) bool {
|
||||
|
||||
alpha := slices.Max(mip.HierarchyArray)
|
||||
log.Println("Maximum element is :", alpha)
|
||||
slices.Sort(mip.HierarchyArray)
|
||||
indexMax := len(mip.HierarchyArray) - 1
|
||||
if indexMax < 0 {
|
||||
log.Println("Empty array , no elements")
|
||||
return false
|
||||
}
|
||||
|
||||
alpha := mip.HierarchyArray[indexMax]
|
||||
log.Println("Maximum element is :", alpha)
|
||||
log.Println("Array is :", mip.HierarchyArray)
|
||||
return alpha == hier
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue