mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-05-14 00:51:12 +03:00
Fix windows bssid matching
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package adapter
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
@@ -51,6 +54,24 @@ type WIFIState struct {
|
||||
BSSID string
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
type NetworkInterface struct {
|
||||
control.Interface
|
||||
Type C.InterfaceType
|
||||
|
||||
@@ -424,6 +424,7 @@ func (r *NetworkManager) WIFIState() adapter.WIFIState {
|
||||
}
|
||||
|
||||
func (r *NetworkManager) onWIFIStateChanged(state adapter.WIFIState) {
|
||||
state.BSSID = adapter.NormalizeWIFIBSSID(state.BSSID)
|
||||
r.wifiStateMutex.Lock()
|
||||
if state != r.wifiState {
|
||||
r.wifiState = state
|
||||
|
||||
@@ -18,7 +18,7 @@ type WIFIBSSIDItem struct {
|
||||
func NewWIFIBSSIDItem(networkManager adapter.NetworkManager, bssidList []string) *WIFIBSSIDItem {
|
||||
bssidMap := make(map[string]bool)
|
||||
for _, bssid := range bssidList {
|
||||
bssidMap[bssid] = true
|
||||
bssidMap[adapter.NormalizeWIFIBSSID(bssid)] = true
|
||||
}
|
||||
return &WIFIBSSIDItem{
|
||||
bssidList,
|
||||
|
||||
Reference in New Issue
Block a user