From 91df97aee204cf5f9dfb5f66807d45a51e44132e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Tue, 9 May 2023 12:11:38 +0800 Subject: [PATCH] Fix macos monitor --- monitor.go | 3 ++- monitor_darwin.go | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/monitor.go b/monitor.go index 0fe6396..910570a 100644 --- a/monitor.go +++ b/monitor.go @@ -39,5 +39,6 @@ type DefaultInterfaceMonitor interface { } type DefaultInterfaceMonitorOptions struct { - OverrideAndroidVPN bool + OverrideAndroidVPN bool + UnderNetworkExtension bool } diff --git a/monitor_darwin.go b/monitor_darwin.go index 296ba54..1df1f21 100644 --- a/monitor_darwin.go +++ b/monitor_darwin.go @@ -122,11 +122,16 @@ func (m *defaultInterfaceMonitor) checkUpdate() error { break } if defaultInterface == nil { - defaultInterface, err = getDefaultInterfaceBySocket() - if err != nil { - return err + if m.options.UnderNetworkExtension { + defaultInterface, err = getDefaultInterfaceBySocket() + if err != nil { + return err + } } } + if defaultInterface == nil { + return ErrNoRoute + } oldInterface := m.defaultInterfaceName oldIndex := m.defaultInterfaceIndex m.defaultInterfaceIndex = defaultInterface.Index