Skip to content

Commit

Permalink
fix: darwin calculate correct tunIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
wwqgtxx committed May 21, 2024
1 parent 3195c67 commit 43bdc76
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions listener/sing_tun/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,23 @@ func CalculateInterfaceName(name string) (tunName string) {
if err != nil {
return
}
var tunIndex int
tunIndex := 0
indexSet := make(map[int]struct{})
for _, netInterface := range interfaces {
if strings.HasPrefix(netInterface.Name, tunName) {
index, parseErr := strconv.ParseInt(netInterface.Name[len(tunName):], 10, 16)
if parseErr == nil {
tunIndex = int(index) + 1
indexSet[int(index)] = struct{}{}
}
}
}
for index := range indexSet {
if index == tunIndex {
tunIndex += 1
} else { // indexSet already sorted and distinct, so this tunIndex nobody used
break
}
}
tunName = F.ToString(tunName, tunIndex)
return
}
Expand Down

0 comments on commit 43bdc76

Please sign in to comment.