Fix IP Address Order Bug

This commit is contained in:
qzydustin 2023-07-23 07:48:30 -07:00 committed by Kristoffer Dalby
parent 23a3adf8d2
commit 6567af7730
2 changed files with 43 additions and 0 deletions

View file

@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net/netip"
"sort"
"strings"
"time"
@ -73,7 +74,23 @@ type (
type MachineAddresses []netip.Addr
func (ma MachineAddresses) Sort() {
sort.Slice(ma, func(index1, index2 int) bool {
if ma[index1].Is4() && ma[index2].Is6() {
return true
}
if ma[index1].Is6() && ma[index2].Is4() {
return false
}
return ma[index1].Compare(ma[index2]) < 0
})
}
func (ma MachineAddresses) StringSlice() []string {
ma.Sort()
strSlice := make([]string, 0, len(ma))
for _, addr := range ma {
strSlice = append(strSlice, addr.String())