multicastgroup.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright (C)2013-2020 ZeroTier, Inc.
  3. *
  4. * Use of this software is governed by the Business Source License included
  5. * in the LICENSE.TXT file in the project's root directory.
  6. *
  7. * Change Date: 2025-01-01
  8. *
  9. * On the date above, in accordance with the Business Source License, use
  10. * of this software will be governed by version 2.0 of the Apache License.
  11. */
  12. /****/
  13. package zerotier
  14. import "fmt"
  15. // MulticastGroup represents a normal Ethernet multicast or broadcast address plus 32 additional ZeroTier-specific bits
  16. type MulticastGroup struct {
  17. MAC MAC `json:"mac"`
  18. ADI uint32 `json:"adi"`
  19. }
  20. // String returns MAC#ADI
  21. func (mg *MulticastGroup) String() string {
  22. if mg.ADI != 0 {
  23. return fmt.Sprintf("%s#%.8x", mg.MAC.String(), mg.ADI)
  24. }
  25. return mg.MAC.String()
  26. }
  27. // Less returns true if this MulticastGroup is less than another.
  28. func (mg *MulticastGroup) Less(mg2 *MulticastGroup) bool {
  29. return mg.MAC < mg2.MAC || (mg.MAC == mg2.MAC && mg.ADI < mg2.ADI)
  30. }
  31. // key returns an array usable as a key for a map[]
  32. func (mg *MulticastGroup) key() (k [2]uint64) {
  33. k[0] = uint64(mg.MAC)
  34. k[1] = uint64(mg.ADI)
  35. return
  36. }