pub enum Address {
IPv4((Ipv4Addr, u16)),
DomainName((String, u16)),
IPv6((Ipv6Addr, u16)),
}Expand description
Represents a network address in various supported formats.
This enum is used to specify target addresses for SOCKS5 and HTTP proxy connections, supporting IPv4, IPv6, and domain name address types as defined in RFC 1928.
Variants§
IPv4((Ipv4Addr, u16))
An IPv4 address with a port number.
DomainName((String, u16))
A domain name with a port number.
IPv6((Ipv6Addr, u16))
An IPv6 address with a port number.
Implementations§
Source§impl Address
impl Address
Sourcepub async fn decode_from_reader<T>(reader: &mut T) -> Result<(Self, usize)>
pub async fn decode_from_reader<T>(reader: &mut T) -> Result<(Self, usize)>
Decodes a SOCKS5-like address from an asynchronous reader.
This method reads a network address from the provided asynchronous reader using the SOCKS5 address format (RFC 1928). It reads the address type byte, followed by the appropriate address data and port number.
According to RFC 1928, SOCKS5 address format is:
+------+----------+----------+
| ATYP | DST.ADDR | DST.PORT |
+------+----------+----------+
| 1 | Variable | 2 |
+------+----------+----------+ATYP: Address type - 0x01 (IPv4), 0x03 (domain name), 0x04 (IPv6)
ADDR: Destination address, format depends on ATYP
PORT: Destination port, network byte order (big-endian)
Sourcepub async fn encode_to_writer<T>(&self, writer: &mut T) -> Result<usize>where
T: AsyncWrite + Unpin,
pub async fn encode_to_writer<T>(&self, writer: &mut T) -> Result<usize>where
T: AsyncWrite + Unpin,
Encodes the address to a SOCKS5-like format and writes it to an asynchronous writer.
Sourcepub fn decode_from_buf(buf: &[u8]) -> Result<(Self, usize)>
pub fn decode_from_buf(buf: &[u8]) -> Result<(Self, usize)>
Decodes a SOCKS5-like address from a byte buffer.
Sourcepub fn encode_to_buf(&self, buf: &mut [u8]) -> Result<usize>
pub fn encode_to_buf(&self, buf: &mut [u8]) -> Result<usize>
Encodes the address to a SOCKS5-like format and writes it to a byte buffer.
Trait Implementations§
Source§impl From<Address> for String
impl From<Address> for String
Source§fn from(value: Address) -> Self
fn from(value: Address) -> Self
Converts an Address into an HTTP-style text representation.
This implementation formats the address in HTTP-style notation:
- IPv4: “
192.168.1.1:8080” - IPv6: “
[2001:db8::1]:8080” - Domain: “
example.com:443”
This format is suitable for use in HTTP headers and other textual representations.