sing icon indicating copy to clipboard operation
sing copied to clipboard

Socks: `AssociatePacketConn.WriteTo` returns `n` with header length

Open xchacha20-poly1305 opened this issue 8 months ago • 0 comments

https://github.com/SagerNet/sing/blob/59dfe1dbfdbf319db27d2f00432f023b66f12c6d/protocol/socks/packet.go#L59-L73

My observation is that because the buffer passed to WriteTo includes the header, the returned n (number of bytes written) reflects the total length, including this header.

I have referred to other popular SOCKS implementations, and it seems they do not include the header length in the returned n for similar operations.

https://github.com/wzshiming/socks5/blob/c06aae6747c6d36ee8c5994675d7b223cdcf6540/udp.go#L53-L71

https://github.com/txthinking/socks5/blob/4230056ae3012ccd47e9d0699fb0c47c1b924554/client.go#L131-L152

https://github.com/v2fly/v2ray-core/blob/28f558601fb8b6ab1bf4cdbdd3b8848047393e77/proxy/socks/protocol.go#L435-L448

Their n are all payload's length.

This difference in behavior leads me to wonder if this is an intended feature of the SagerNet/sing implementation, or if there's another reason for this design choice.

Could you please clarify if this behavior is by design and, if so, the rationale behind it?

xchacha20-poly1305 avatar May 01 '25 09:05 xchacha20-poly1305