1
1
package tun
2
2
3
3
import (
4
+ "context"
4
5
"errors"
5
6
"fmt"
6
7
"github.com/lysShub/wintun-go"
31
32
)
32
33
33
34
func init () {
34
- wintun .Load (wintun .DLL )
35
+ wintun .MustLoad (wintun .DLL )
35
36
}
36
37
37
38
func CreateTUN (ifname string , mtu int ) (Device , error ) {
@@ -60,12 +61,12 @@ func (tun *NativeTun) Read(buff []byte, offset int) (int, error) {
60
61
}
61
62
62
63
for {
63
- packet , err := tun .wt .ReceivePacket ( )
64
+ packet , err := tun .wt .Recv ( context . Background () )
64
65
switch err {
65
66
case nil :
66
67
packetSize := len (packet )
67
68
copy (buff [offset :], packet )
68
- tun .wt .ReleasePacket (packet )
69
+ tun .wt .Release (packet )
69
70
// tun.rate.update(uint64(packetSize))
70
71
return packetSize , nil
71
72
case windows .ERROR_HANDLE_EOF :
@@ -83,12 +84,12 @@ func (tun *NativeTun) Write(buff []byte, offset int) (int, error) {
83
84
return 0 , os .ErrClosed
84
85
}
85
86
86
- packetSize := uint32 ( len (buff ) - offset )
87
+ packetSize := len (buff ) - offset
87
88
88
- packet , err := tun .wt .AllocateSendPacket (packetSize )
89
+ packet , err := tun .wt .Alloc (packetSize )
89
90
if err == nil {
90
91
copy (packet , buff [offset :])
91
- err = tun .wt .SendPacket (packet )
92
+ err = tun .wt .Send (packet )
92
93
if err != nil {
93
94
return 0 , err
94
95
}
0 commit comments