Skip to content

socks: report payload bytes from associate packet writes - #116

Open
omrzk wants to merge 1 commit into
SagerNet:devfrom
omrzk:fix/socks-write-payload-count-83
Open

omrzk wants to merge 1 commit into
SagerNet:devfrom
omrzk:fix/socks-write-payload-count-83

Conversation

@omrzk

@omrzk omrzk commented Nov 2, 2026

Copy link
Copy Markdown

AssociatePacketConn.WriteTo returns the SOCKS UDP header length together with the payload count. This also affects Write, so a seven-byte IPv4 payload reports 17 bytes and an empty payload reports 10.

Subtract the serialized header from the underlying write count, clamping incomplete-header writes to zero and preserving the original write error. UDP framing and the buffer-based packet API are unchanged.

Fixes #83.

Validation: real UDP loopback tests exercise Write and WriteTo, IPv4/IPv6/domain destinations, and empty/nonempty payloads; controlled write errors cover no bytes, incomplete headers, partial payloads, and complete writes with errors. These regressions fail on current dev before the change. go test -race ./... and Linux golangci-lint pass. Android, Darwin and FreeBSD lint also pass. Windows lint reports the same pre-existing missing t.Parallel() in common/winiphlpapi/nsi_test.go:34 on the base and patch. make test passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Socks: AssociatePacketConn.WriteTo returns n with header length

1 participant