Std TcpStream with proxy

Hello,
I am currently working on a project where I have a std::net::TcpStream and I want this stream to use a proxy, have you a solution for me?
Thank's by advance.

As far as I understand, TCP is mostly in the transport layer (see https://en.wikipedia.org/wiki/OSI_model), where proxies normally are in the Application layer.

As such, TCP itself has no concept of a proxy. HTTP has, SSH and others, but not TCP. You could have a TCP proxy if you make a TCP stream to the proxy and the proxy makes a TCP connection to the other end. You would have to tell it somehow what you want to connect to outside of the TCP protocol.

You still wouldn't really have a proxied TCP connection, because all control packets like acknowledgements would be concerning the connection to your proxy and not to your end destination, as TCP is on the transport layer.

What proxy do you want to use? You can create a proxy at the session layer with SOCKS, but then it's external usually, at the routing. You just connect normally in rust, but then route the network packet to the SOCKS proxy which will make the connection to the final IP and implement the network address translation. Using a routing table or a firewall.

There is a crate called socks, which seems to allow you to create a socks client, and it allows access to the inner TCP stream from what I can tell from it's documentation.