mirror of
https://github.com/SagerNet/sing-box.git
synced 2026-05-13 13:57:05 +00:00
Fix windows bssid matching
This commit is contained in:
parent
b3606e33a6
commit
3124cdd661
3 changed files with 23 additions and 1 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue