mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-12-24 03:40:07 +08:00
fix: darwin calculate correct tunIndex
This commit is contained in:
parent
59fd3cffe3
commit
be3d121ec6
@ -24,6 +24,7 @@ import (
|
|||||||
E "github.com/sagernet/sing/common/exceptions"
|
E "github.com/sagernet/sing/common/exceptions"
|
||||||
F "github.com/sagernet/sing/common/format"
|
F "github.com/sagernet/sing/common/format"
|
||||||
"github.com/sagernet/sing/common/ranges"
|
"github.com/sagernet/sing/common/ranges"
|
||||||
|
"golang.org/x/exp/slices"
|
||||||
)
|
)
|
||||||
|
|
||||||
var InterfaceName = "Meta"
|
var InterfaceName = "Meta"
|
||||||
@ -60,19 +61,21 @@ func CalculateInterfaceName(name string) (tunName string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
tunIndex := 0
|
tunIndex := 0
|
||||||
indexSet := make(map[int]struct{})
|
indexArr := make([]int, 0, len(interfaces))
|
||||||
for _, netInterface := range interfaces {
|
for _, netInterface := range interfaces {
|
||||||
if strings.HasPrefix(netInterface.Name, tunName) {
|
if strings.HasPrefix(netInterface.Name, tunName) {
|
||||||
index, parseErr := strconv.ParseInt(netInterface.Name[len(tunName):], 10, 16)
|
index, parseErr := strconv.ParseInt(netInterface.Name[len(tunName):], 10, 16)
|
||||||
if parseErr == nil {
|
if parseErr == nil {
|
||||||
indexSet[int(index)] = struct{}{}
|
indexArr = append(indexArr, int(index))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for index := range indexSet {
|
slices.Sort(indexArr)
|
||||||
|
indexArr = slices.Compact(indexArr)
|
||||||
|
for _, index := range indexArr {
|
||||||
if index == tunIndex {
|
if index == tunIndex {
|
||||||
tunIndex += 1
|
tunIndex += 1
|
||||||
} else { // indexSet already sorted and distinct, so this tunIndex nobody used
|
} else { // indexArr already sorted and distinct, so this tunIndex nobody used
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user