ZeroTierOne/go/pkg/zerotier/multicastgroup.go
2019-09-30 11:10:47 -07:00

40 lines
1.0 KiB
Go

/*
* Copyright (c)2019 ZeroTier, Inc.
*
* Use of this software is governed by the Business Source License included
* in the LICENSE.TXT file in the project's root directory.
*
* Change Date: 2023-01-01
*
* On the date above, in accordance with the Business Source License, use
* of this software will be governed by version 2.0 of the Apache License.
*/
/****/
package zerotier
import "fmt"
// MulticastGroup represents a normal Ethernet multicast or broadcast address plus 32 additional ZeroTier-specific bits
type MulticastGroup struct {
MAC MAC
ADI uint32
}
// String returns MAC#ADI
func (mg *MulticastGroup) String() string {
return fmt.Sprintf("%s#%.8x", mg.MAC.String(), mg.ADI)
}
// Less returns true if this MulticastGroup is less than another.
func (mg *MulticastGroup) Less(mg2 *MulticastGroup) bool {
return mg.MAC < mg2.MAC || (mg.MAC == mg2.MAC && mg.ADI < mg2.ADI)
}
// key returns an array usable as a key for a map[]
func (mg *MulticastGroup) key() (k [2]uint64) {
k[0] = uint64(mg.MAC)
k[1] = uint64(mg.ADI)
return
}