slice.Max has a bug, writing my own Max()
parent
f1c46ed9f1
commit
636434a0cf
30
interface.go
30
interface.go
|
@ -163,21 +163,11 @@ func (b *AbstractBridge) IsAssigned() bool {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ief *net.Interface
|
ief *net.Interface
|
||||||
addrs []net.Addr
|
addrs []net.Addr
|
||||||
ipv4Addr net.IP
|
err error
|
||||||
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
|
interfaceName := b.ExistingInterface
|
||||||
|
|
||||||
if ief, err = net.InterfaceByName(interfaceName); err != nil { // get interface
|
if ief, err = net.InterfaceByName(interfaceName); err != nil { // get interface
|
||||||
|
@ -196,20 +186,14 @@ func (b *AbstractBridge) IsAssigned() bool {
|
||||||
return false
|
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 {
|
for _, addr := range addrs {
|
||||||
if addr.String() == bridgeip {
|
log.Println("Address found is: ", addr.String())
|
||||||
log.Printf("Ip %s is assigned to interface %s", bridgeip, interfaceName)
|
if addr.String() == b.BridgeIpCIDR {
|
||||||
|
log.Printf("Ip %s is assigned to interface %s", b.BridgeIpCIDR, interfaceName)
|
||||||
return true
|
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
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,16 @@ func (mip *AbstractMulticast) AddUniqueAndSort(hier int64) {
|
||||||
|
|
||||||
func (mip *AbstractMulticast) IsAlpha(hier int64) bool {
|
func (mip *AbstractMulticast) IsAlpha(hier int64) bool {
|
||||||
|
|
||||||
alpha := slices.Max(mip.HierarchyArray)
|
slices.Sort(mip.HierarchyArray)
|
||||||
log.Println("Maximum element is :", alpha)
|
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
|
return alpha == hier
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue