From ceff4185dce902d2a220622794340faff859c787 Mon Sep 17 00:00:00 2001 From: RPRX <63339210+rprx@users.noreply.github.com> Date: Tue, 26 Jan 2021 23:53:01 +0000 Subject: [PATCH] Improve the request for UDP Associate in Socks5 --- proxy/socks/protocol.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/proxy/socks/protocol.go b/proxy/socks/protocol.go index 9086e519..5701678e 100644 --- a/proxy/socks/protocol.go +++ b/proxy/socks/protocol.go @@ -465,8 +465,12 @@ func ClientHandshake(request *protocol.RequestHeader, reader io.Reader, writer i command = byte(cmdUDPAssociate) } common.Must2(b.Write([]byte{socks5Version, command, 0x00 /* reserved */})) - if err := addrParser.WriteAddressPort(b, request.Address, request.Port); err != nil { - return nil, err + if request.Command == protocol.RequestCommandUDP { + common.Must2(b.Write([]byte{1, 0, 0, 0, 0, 0, 0 /* RFC 1928 */})) + } else { + if err := addrParser.WriteAddressPort(b, request.Address, request.Port); err != nil { + return nil, err + } } if err := buf.WriteAllBytes(writer, b.Bytes()); err != nil {