multicastgroup.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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: 2024-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. return fmt.Sprintf("%s#%.8x", mg.MAC.String(), mg.ADI)
  23. }
  24. // Less returns true if this MulticastGroup is less than another.
  25. func (mg *MulticastGroup) Less(mg2 *MulticastGroup) bool {
  26. return mg.MAC < mg2.MAC || (mg.MAC == mg2.MAC && mg.ADI < mg2.ADI)
  27. }
  28. // key returns an array usable as a key for a map[]
  29. func (mg *MulticastGroup) key() (k [2]uint64) {
  30. k[0] = uint64(mg.MAC)
  31. k[1] = uint64(mg.ADI)
  32. return
  33. }