mirror of
https://github.com/SagerNet/sing-tun.git
synced 2025-04-05 04:47:41 +03:00
Fix windows read packet
This commit is contained in:
parent
69bc471e19
commit
2895f49fd2
1 changed files with 7 additions and 5 deletions
|
@ -310,21 +310,22 @@ func (e *WintunEndpoint) dispatchLoop() {
|
||||||
defer common.KeepAlive(_buffer)
|
defer common.KeepAlive(_buffer)
|
||||||
buffer := common.Dup(_buffer)
|
buffer := common.Dup(_buffer)
|
||||||
defer buffer.Release()
|
defer buffer.Release()
|
||||||
|
data := buffer.FreeBytes()
|
||||||
for {
|
for {
|
||||||
n, err := e.tun.Read(buffer.FreeBytes())
|
n, err := e.tun.Read(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
var view gBuffer.View
|
packet := make([]byte, n)
|
||||||
view.Append(buffer.To(n))
|
copy(packet, data[:n])
|
||||||
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||||
Payload: view,
|
Payload: gBuffer.NewWithData(packet),
|
||||||
IsForwardedPacket: true,
|
IsForwardedPacket: true,
|
||||||
})
|
})
|
||||||
defer pkt.DecRef()
|
|
||||||
var p tcpip.NetworkProtocolNumber
|
var p tcpip.NetworkProtocolNumber
|
||||||
ipHeader, ok := pkt.Data().PullUp(1)
|
ipHeader, ok := pkt.Data().PullUp(1)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
pkt.DecRef()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
switch header.IPVersion(ipHeader) {
|
switch header.IPVersion(ipHeader) {
|
||||||
|
@ -336,6 +337,7 @@ func (e *WintunEndpoint) dispatchLoop() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
e.dispatcher.DeliverNetworkPacket(p, pkt)
|
e.dispatcher.DeliverNetworkPacket(p, pkt)
|
||||||
|
pkt.DecRef()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue