mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-05-14 10:00:34 +00:00
TUN inbound: Generate deterministic GUID on Windows (#5811)
Closes https://github.com/XTLS/Xray-core/issues/5810
This commit is contained in:
@@ -3,8 +3,9 @@
|
|||||||
package tun
|
package tun
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/md5"
|
||||||
"errors"
|
"errors"
|
||||||
_ "unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
"golang.zx2c4.com/wintun"
|
"golang.zx2c4.com/wintun"
|
||||||
@@ -66,7 +67,9 @@ func NewTun(options TunOptions) (Tun, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func open(name string) (*wintun.Adapter, error) {
|
func open(name string) (*wintun.Adapter, error) {
|
||||||
var guid *windows.GUID
|
// generate a deterministic GUID from the adapter name
|
||||||
|
id := md5.Sum([]byte(name))
|
||||||
|
guid := (*windows.GUID)(unsafe.Pointer(&id[0]))
|
||||||
// try to open existing adapter by name
|
// try to open existing adapter by name
|
||||||
adapter, err := wintun.OpenAdapter(name)
|
adapter, err := wintun.OpenAdapter(name)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user