3
1
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.
What's that?
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 11.22.33.44:5555, and our remote socks proxy be 99.88.77.66: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 > 99.88.77.66:5555 - to > 11.22.33.44:5555
Your goal is to implement the local application relaying connections to the target.
Input
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 (11.22.33.44).
- You may use builtin types of your language. (like
InetSocketAddress
in Java,struct in_addr
in C, etc.)
Output
No rules for output due to networking.
Additional
- 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).
So the task is to create a local SOCKS server that accepts local connections (e.g. from a suitably configured browser) and connects to a remote SOCKS proxy that forwards the connection to the far end (e.g. web server)? - its not entirely clear to me. – Digital Trauma – 2017-03-29T20:27:10.333
@DigitalTrauma Not a local SOCKS server, but more a local tunnel server using a fixed SOCKS proxy to forward connections to a fixed end. – F. George – 2017-03-29T21:15:09.683
1So just a simple local TCP port forward then? - that itself knows nothing of the SOCKS protocol? This is not really clear to me – Digital Trauma – 2017-03-29T22:48:18.580
I'm not sure what else there is to explain? From the point of the connecting application it is effectively a port forward. The impementing application obviously has to know about the SOCKS protocol. I've even given a sample answer in Kotlin. – F. George – 2017-03-30T07:10:00.620