Files
sing-box-extended-mirror/adapter/network.go
T

82 lines
1.8 KiB
Go
Raw Normal View History

2024-11-10 12:11:21 +08:00
package adapter
import (
2026-04-19 23:45:12 +08:00
"encoding/hex"
"net"
"strings"
2024-11-12 19:37:10 +08:00
"time"
C "github.com/sagernet/sing-box/constant"
2024-11-10 12:11:21 +08:00
"github.com/sagernet/sing-tun"
"github.com/sagernet/sing/common/control"
)
type NetworkManager interface {
2024-11-10 16:46:59 +08:00
Lifecycle
2025-12-07 11:05:43 +08:00
Initialize(ruleSets []RuleSet)
2024-11-10 12:11:21 +08:00
InterfaceFinder() control.InterfaceFinder
UpdateInterfaces() error
2024-11-11 16:23:45 +08:00
DefaultNetworkInterface() *NetworkInterface
NetworkInterfaces() []NetworkInterface
2024-11-10 12:11:21 +08:00
AutoDetectInterface() bool
AutoDetectInterfaceFunc() control.Func
2024-11-12 19:37:10 +08:00
ProtectFunc() control.Func
DefaultOptions() NetworkOptions
2024-11-10 12:11:21 +08:00
RegisterAutoRedirectOutputMark(mark uint32) error
AutoRedirectOutputMark() uint32
AutoRedirectOutputMarkFunc() control.Func
2024-11-10 12:11:21 +08:00
NetworkMonitor() tun.NetworkUpdateMonitor
InterfaceMonitor() tun.DefaultInterfaceMonitor
PackageManager() tun.PackageManager
2025-12-07 11:05:43 +08:00
NeedWIFIState() bool
2024-11-10 12:11:21 +08:00
WIFIState() WIFIState
2025-02-20 14:42:09 +08:00
UpdateWIFIState()
2025-12-07 11:05:43 +08:00
ResetNetwork()
2024-11-10 12:11:21 +08:00
}
2024-11-11 16:23:45 +08:00
2024-11-12 19:37:10 +08:00
type NetworkOptions struct {
2025-01-12 12:45:27 +08:00
BindInterface string
RoutingMark uint32
DomainResolver string
DomainResolveOptions DNSQueryOptions
NetworkStrategy *C.NetworkStrategy
NetworkType []C.InterfaceType
FallbackNetworkType []C.InterfaceType
FallbackDelay time.Duration
2024-11-12 19:37:10 +08:00
}
2024-11-11 16:23:45 +08:00
type InterfaceUpdateListener interface {
InterfaceUpdated()
}
type WIFIState struct {
SSID string
BSSID string
}
2026-04-19 23:45:12 +08:00
func NormalizeWIFIBSSID(bssid string) string {
bssid = strings.TrimSpace(bssid)
if bssid == "" {
return ""
}
parsed, err := net.ParseMAC(bssid)
if err == nil && len(parsed) == 6 {
return parsed.String()
}
if len(bssid) == 12 {
decoded, err := hex.DecodeString(bssid)
if err == nil {
return net.HardwareAddr(decoded).String()
}
}
return bssid
}
2024-11-11 16:23:45 +08:00
type NetworkInterface struct {
control.Interface
2024-11-13 19:05:28 +08:00
Type C.InterfaceType
2024-11-11 16:23:45 +08:00
DNSServers []string
Expensive bool
Constrained bool
}