From 3af7305b853e5474f1dbfd3f40721c147d477351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Fri, 18 Jul 2025 11:00:19 +0800 Subject: [PATCH] Fix darwin WritePacket --- tun_darwin_gvisor.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tun_darwin_gvisor.go b/tun_darwin_gvisor.go index 7879bb5..ef940c3 100644 --- a/tun_darwin_gvisor.go +++ b/tun_darwin_gvisor.go @@ -3,6 +3,7 @@ package tun import ( + "github.com/sagernet/gvisor/pkg/tcpip/header" "github.com/sagernet/gvisor/pkg/tcpip/link/qdisc/fifo" "github.com/sagernet/gvisor/pkg/tcpip/stack" "github.com/sagernet/sing-tun/internal/fdbased_darwin" @@ -15,6 +16,11 @@ var _ GVisorTun = (*NativeTun)(nil) func (t *NativeTun) WritePacket(pkt *stack.PacketBuffer) (int, error) { iovecs := t.iovecsOutputDefault + if pkt.NetworkProtocolNumber == header.IPv4ProtocolNumber { + iovecs = append(iovecs, packetHeaderVec4) + } else { + iovecs = append(iovecs, packetHeaderVec6) + } var dataLen int for _, packetSlice := range pkt.AsSlices() { dataLen += len(packetSlice)