Skip to content

Commit

Permalink
Fix: socks4 server handshake (#2700)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaling888 authored Apr 25, 2023
1 parent 6eee226 commit 48b77b2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions transport/socks4/socks4.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func ServerHandshake(rw io.ReadWriter, authenticator auth.Authenticator) (addr s
return
}

dstAddr := r.ReadIPv4()
dstPort := r.ReadUint16be()
dstAddr := r.ReadIPv4()
if isReservedIP(dstAddr) {
var target []byte
if target, err = readUntilNull(rw); err != nil {
Expand All @@ -96,8 +96,8 @@ func ServerHandshake(rw io.ReadWriter, authenticator auth.Authenticator) (addr s
reply := protobytes.BytesWriter(make([]byte, 0, 8))
reply.PutUint8(0) // reply code
reply.PutUint8(code) // result code
reply.PutSlice(dstAddr.AsSlice())
reply.PutUint16be(dstPort)
reply.PutSlice(dstAddr.AsSlice())

_, wErr := rw.Write(reply.Bytes())
if err == nil {
Expand Down Expand Up @@ -128,7 +128,7 @@ func ClientHandshake(rw io.ReadWriter, addr string, command Command, userID stri
req.PutUint8(Version)
req.PutUint8(command)
req.PutUint16be(uint16(port))
req.Write(ip.AsSlice())
req.PutSlice(ip.AsSlice())
req.PutString(userID)
req.PutUint8(0) /* NULL */

Expand Down

0 comments on commit 48b77b2

Please sign in to comment.