Many applications that depend on network resources (such as games connecting to game servers) do not allow the user to set a proxy. There are a lot of ways to force the usage of a proxy regardless, I personally have always been a fan of a local SOCKS tunnel.
Instead of connecting directly, an application on your local machine listens on a locally bound address and relays any connection to a fixed endpoint using a remote SOCKS proxy.
Example: Let our target be 220.127.116.11:5555, and our remote socks proxy be 18.104.22.168:5555. Our application listens on 127.0.0.1:5555. Our route now looks like this:
connect to 127.0.0.1:5555 - relays via SOCKS proxy > 22.214.171.124:5555 - to > 126.96.36.199:5555
Your goal is to implement the local application relaying connections to the target.
Three address/port pairs representing the bind, proxy and target address.
- You may deviate from the order (but specify if you do).
- Address parsing is up to your language/tools of choice, but should at the very minimum support IPv4 (188.8.131.52).
- You may use builtin types of your language. (like
struct in_addrin C, etc.)
No rules for output due to networking.
- This is code-golf, shortest answer in bytes wins.
- Standard rules apply, default loopholes are forbidden.
- You do not have to support more than 1 connection. The program may terminate after the first connection finishes.
- Program behaviour under network failures is undefined; you may crash the entire program, reject the incoming connection, do whatever you want.
- You may assume the remote SOCKS proxy's version (4/4a/5).
- Using libraries/inbuilts/etc. is encouraged, but not required.
- Stay in input scope (f.e. don't proxy all connections on the machine).