瀏覽代碼

Improve the request for UDP Associate in Socks5

RPRX 4 年之前
父節點
當前提交
ceff4185dc
共有 1 個文件被更改,包括 6 次插入2 次删除
  1. 6 2
      proxy/socks/protocol.go

+ 6 - 2
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 {