Skip to content

Commit

Permalink
Fix monitor for ios
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Apr 17, 2023
1 parent 8848c0e commit 499c0ae
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions monitor_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"net"
"net/netip"
"os"
"runtime"
"strings"
"sync"
"syscall"

Expand Down Expand Up @@ -85,6 +87,13 @@ func (m *defaultInterfaceMonitor) checkUpdate() error {
}
for _, rawRouteMessage := range routeMessages {
routeMessage := rawRouteMessage.(*route.RouteMessage)
routeInterface, err := net.InterfaceByIndex(routeMessage.Index)
if err != nil {
return err
}
if runtime.GOOS == "ios" && strings.HasPrefix(routeInterface.Name, "utun") {
continue
}
if common.Any(common.FilterIsInstance(routeMessage.Addrs, func(it route.Addr) (*route.Inet4Addr, bool) {
addr, loaded := it.(*route.Inet4Addr)
return addr, loaded
Expand All @@ -95,11 +104,7 @@ func (m *defaultInterfaceMonitor) checkUpdate() error {
oldIndex := m.defaultInterfaceIndex

m.defaultInterfaceIndex = routeMessage.Index
defaultInterface, err := net.InterfaceByIndex(routeMessage.Index)
if err != nil {
return err
}
m.defaultInterfaceName = defaultInterface.Name
m.defaultInterfaceName = routeInterface.Name
if oldInterface == m.defaultInterfaceName && oldIndex == m.defaultInterfaceIndex {
return nil
}
Expand Down

0 comments on commit 499c0ae

Please sign in to comment.