Skip to content

Commit 1a85bd3

Browse files
committed
Add DefaultInterface func
1 parent 56a9b85 commit 1a85bd3

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

monitor.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type DefaultInterfaceMonitor interface {
3232
Close() error
3333
DefaultInterfaceName(destination netip.Addr) string
3434
DefaultInterfaceIndex(destination netip.Addr) int
35+
DefaultInterface(destination netip.Addr) (string, int)
3536
OverrideAndroidVPN() bool
3637
AndroidVPNEnabled() bool
3738
RegisterCallback(callback DefaultInterfaceUpdateCallback) *list.Element[DefaultInterfaceUpdateCallback]

monitor_shared.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,20 @@ func (m *defaultInterfaceMonitor) DefaultInterfaceIndex(destination netip.Addr)
150150
return m.defaultInterfaceIndex
151151
}
152152

153+
func (m *defaultInterfaceMonitor) DefaultInterface(destination netip.Addr) (string, int) {
154+
for _, address := range m.networkAddresses {
155+
for _, prefix := range address.addresses {
156+
if prefix.Contains(destination) {
157+
return address.interfaceName, address.interfaceIndex
158+
}
159+
}
160+
}
161+
if m.defaultInterfaceIndex == -1 {
162+
m.checkUpdate()
163+
}
164+
return m.defaultInterfaceName, m.defaultInterfaceIndex
165+
}
166+
153167
func (m *defaultInterfaceMonitor) OverrideAndroidVPN() bool {
154168
return m.options.OverrideAndroidVPN
155169
}

0 commit comments

Comments
 (0)