diff --git a/monitor.go b/monitor.go index b424256..2a0a419 100644 --- a/monitor.go +++ b/monitor.go @@ -32,6 +32,7 @@ type DefaultInterfaceMonitor interface { Close() error DefaultInterfaceName(destination netip.Addr) string DefaultInterfaceIndex(destination netip.Addr) int + DefaultInterface(destination netip.Addr) (string, int) OverrideAndroidVPN() bool AndroidVPNEnabled() bool RegisterCallback(callback DefaultInterfaceUpdateCallback) *list.Element[DefaultInterfaceUpdateCallback] diff --git a/monitor_shared.go b/monitor_shared.go index 70634ae..a1b2387 100644 --- a/monitor_shared.go +++ b/monitor_shared.go @@ -150,6 +150,20 @@ func (m *defaultInterfaceMonitor) DefaultInterfaceIndex(destination netip.Addr) return m.defaultInterfaceIndex } +func (m *defaultInterfaceMonitor) DefaultInterface(destination netip.Addr) (string, int) { + for _, address := range m.networkAddresses { + for _, prefix := range address.addresses { + if prefix.Contains(destination) { + return address.interfaceName, address.interfaceIndex + } + } + } + if m.defaultInterfaceIndex == -1 { + m.checkUpdate() + } + return m.defaultInterfaceName, m.defaultInterfaceIndex +} + func (m *defaultInterfaceMonitor) OverrideAndroidVPN() bool { return m.options.OverrideAndroidVPN }