proxychains-masq 0.1.5

TUN-based proxy chain engine — routes TCP flows through SOCKS4/5, HTTP CONNECT, and HTTPS CONNECT proxy chains via a userspace network stack.
Documentation
pub mod http;
pub mod https;
pub mod raw;
pub mod socks4;
pub mod socks5;

use std::{fmt, net::IpAddr};

use tokio::io::{AsyncRead, AsyncWrite};

/// A type-erased async stream that supports both reading and writing.
///
/// Used throughout the chain engine so that heterogeneous stream types —
/// plain [`tokio::net::TcpStream`], TLS-wrapped streams, etc. — can all flow
/// through the same proxy chaining code without monomorphization.
pub trait AsyncStream: AsyncRead + AsyncWrite + Send + Unpin {}
impl<T: AsyncRead + AsyncWrite + Send + Unpin> AsyncStream for T {}

/// An owned, heap-allocated [`AsyncStream`].
pub type BoxStream = Box<dyn AsyncStream>;

/// The target of a proxy connection: either a resolved IP address or a hostname.
#[derive(Debug, Clone)]
pub enum Target {
    Ip(IpAddr, u16),
    Host(String, u16),
}

impl Target {
    /// Return the destination port.
    pub fn port(&self) -> u16 {
        match self {
            Target::Ip(_, p) | Target::Host(_, p) => *p,
        }
    }
}

impl fmt::Display for Target {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Target::Ip(ip, port) => write!(f, "{ip}:{port}"),
            Target::Host(host, port) => write!(f, "{host}:{port}"),
        }
    }
}