-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtun_windows.go
More file actions
63 lines (52 loc) · 1.28 KB
/
tun_windows.go
File metadata and controls
63 lines (52 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package pun
import (
"context"
"golang.org/x/sys/windows"
"golang.zx2c4.com/wireguard/tun"
"golang.zx2c4.com/wireguard/windows/tunnel/winipcfg"
"io"
"net/netip"
)
type winDev struct {
dev tun.Device
}
func (w *winDev) Close() error {
return w.dev.Close()
}
func (w *winDev) Write(b []byte) (int, error) {
return w.dev.Write(b, 0)
}
func (w *winDev) Read(b []byte) (int, error) {
return w.dev.Read(b, 0)
}
func openStreamWithIP(config *Config, parentCtx context.Context) (*Stream, error) {
id := &windows.GUID{
Data2: 0xFFFF,
Data3: 0xFFFF,
Data4: [8]byte{0xFF, 0xe9, 0x76, 0xe5, 0x8c, 0x74, 0x06, 0x3e},
}
dev, err := tun.CreateTUNWithRequestedGUID(config.Name, id, config.MTU)
if err != nil {
return nil, err
}
nativeTunDevice := dev.(*tun.NativeTun)
link := winipcfg.LUID(nativeTunDevice.LUID())
ipPrefix, err := netip.ParsePrefix(config.CIDRv4.String())
if err != nil {
return nil, err
}
err = link.AddIPAddress(ipPrefix)
if err != nil {
return nil, err
}
return newStream(&winDev{dev: dev}, parentCtx), nil
}
func openStream(parentCtx context.Context) (*Stream, error) {
// todo: not implement
panic("`openStream` not implement")
return nil, nil
}
func closeStream(closer io.ReadWriteCloser) {
// todo: not implement
panic("`closeStream` not implement")
}