Address

Enum Address 

Source
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

Source

pub async fn decode_from_reader<T>(reader: &mut T) -> Result<(Self, usize)>
where T: AsyncRead + Unpin,

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)

Source

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.

Source

pub fn decode_from_buf(buf: &[u8]) -> Result<(Self, usize)>

Decodes a SOCKS5-like address from a byte buffer.

Source

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 Clone for Address

Source§

fn clone(&self) -> Address

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Address

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&Address> for String

Source§

fn from(address: &Address) -> Self

Converts an &Address into an HTTP-style text representation.

Source§

impl From<Address> for String

Source§

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.

Source§

impl Hash for Address

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Address

Source§

fn eq(&self, other: &Address) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<&str> for Address

Source§

fn try_from(string: &str) -> Result<Self, Self::Error>

Attempts to parse an HTTP-style text address into an Address.

Source§

type Error = AddrError

The type returned in the event of a conversion error.
Source§

impl TryFrom<String> for Address

Source§

fn try_from(value: String) -> Result<Self, Self::Error>

Attempts to parse an HTTP-style text address into an Address.

Source§

type Error = AddrError

The type returned in the event of a conversion error.
Source§

impl Eq for Address

Source§

impl StructuralPartialEq for Address

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.