Add InterfaceFinder.Interfaces() []control.Interface

This commit is contained in:
世界 2024-05-27 19:36:37 +08:00
parent d9f2559214
commit 47cc308abf
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
2 changed files with 7 additions and 0 deletions

View file

@ -5,6 +5,7 @@ import (
)
type InterfaceFinder interface {
Interfaces() []Interface
InterfaceIndexByName(name string) (int, error)
InterfaceNameByIndex(index int) (string, error)
InterfaceByAddr(addr netip.Addr) (*Interface, error)

View file

@ -9,6 +9,8 @@ import (
M "github.com/sagernet/sing/common/metadata"
)
var _ InterfaceFinder = (*DefaultInterfaceFinder)(nil)
type DefaultInterfaceFinder struct {
interfaces []Interface
}
@ -43,6 +45,10 @@ func (f *DefaultInterfaceFinder) UpdateInterfaces(interfaces []Interface) {
f.interfaces = interfaces
}
func (f *DefaultInterfaceFinder) Interfaces() []Interface {
return f.interfaces
}
func (f *DefaultInterfaceFinder) InterfaceIndexByName(name string) (int, error) {
for _, netInterface := range f.interfaces {
if netInterface.Name == name {