Skip to content

Commit

Permalink
Fix socks5 udp associate address
Browse files Browse the repository at this point in the history
  • Loading branch information
dyhkwong committed Apr 10, 2024
1 parent 2fa0399 commit c471471
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions protocol/socks/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ func ClientHandshake5(conn io.ReadWriter, command byte, destination M.Socksaddr,
} else if authResponse.Method != socks5.AuthTypeNotRequired {
return socks5.Response{}, E.New("socks5: unsupported auth method: ", authResponse.Method)
}
if command == socks5.CommandUDPAssociate {
if destination.IsIPv6() {
destination = M.SocksaddrFrom(netip.IPv6Unspecified(), 0)
} else {
destination = M.SocksaddrFrom(netip.IPv4Unspecified(), 0)
}
}
err = socks5.WriteRequest(conn, socks5.Request{
Command: command,
Destination: destination,
Expand Down Expand Up @@ -215,6 +222,11 @@ func HandleConnection0(ctx context.Context, conn net.Conn, version byte, authent
if err != nil {
return err
}
if request.Destination.IsIPv6() {
request.Destination = M.SocksaddrFrom(netip.IPv6Unspecified(), 0)
} else {
request.Destination = M.SocksaddrFrom(netip.IPv4Unspecified(), 0)
}
metadata.Protocol = "socks5"
metadata.Destination = request.Destination
var innerError error
Expand Down

0 comments on commit c471471

Please sign in to comment.