mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-10-20 08:14:24 +00:00
Add libbox API to detect tun inbounds
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"net/netip"
|
||||
"os"
|
||||
"reflect"
|
||||
"slices"
|
||||
|
||||
box "github.com/sagernet/sing-box"
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
@@ -269,3 +270,13 @@ func FormatConfig(configContent string) (*StringBox, error) {
|
||||
}
|
||||
return wrapString(buffer.String()), nil
|
||||
}
|
||||
|
||||
func HasTunInbound(configContent string) (bool, error) {
|
||||
options, err := parseConfig(baseContext(nil), configContent)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return slices.ContainsFunc(options.Inbounds, func(inbound option.Inbound) bool {
|
||||
return inbound.Type == C.TypeTun
|
||||
}), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user