fengyouchao / sockslib

A Java library of SOCKS5 protocol including client and server
Apache License 2.0
284 stars 104 forks source link

Socks5DatagramSocket fails to redefine connect #20

Open pelzvieh opened 5 years ago

pelzvieh commented 5 years ago

When trying to use DatagramSocket.connect on a derived Socks5DatagramSocket, you will run into IllegalArgumentException "connected address and packet address differ". This is because the connect method is not overloaded to connect to the relayInetSocketAddress. This way, the socket is actually connected to the final destination address, leading to an address conflict with the encapsulated DatagramPacket. To fix, overload connect() to transparently connect to relayInetSocketAddress instead. Additionally, you should store the InetSocketAddress given to connect by the caller and check equals in the overloaded send methods.