pub enum Addresses {
    Unknown,
    Tcp4(IPv4),
    Tcp6(IPv6),
}
Expand description

The source and destination of a header. Includes IP (v4 or v6) addresses and TCP ports.

Examples

Worst Case

use ppp::v1::{Addresses, Header, UNKNOWN};

let header = "PROXY UNKNOWN ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 65535 65535\r\n";
let addresses = Addresses::Unknown;

assert_eq!(addresses, header.parse().unwrap());
assert_ne!(addresses.to_string().as_str(), header);

UNKNOWN

use ppp::v1::Addresses;

let header = "PROXY UNKNOWN\r\n";
let addresses = Addresses::Unknown;

assert_eq!(addresses, header.parse().unwrap());
assert_eq!(addresses.to_string().as_str(), header);

TCP4

use std::net::Ipv4Addr;
use ppp::v1::Addresses;

let header = "PROXY TCP4 127.0.1.2 192.168.1.101 80 443\r\n";
let addresses = Addresses::new_tcp4(Ipv4Addr::new(127, 0, 1, 2), Ipv4Addr::new(192, 168, 1, 101), 80, 443);

assert_eq!(addresses, header.parse().unwrap());
assert_eq!(addresses.to_string().as_str(), header);

TCP6

use std::net::Ipv6Addr;
use ppp::v1::Addresses;

let header = "PROXY TCP6 1234:5678:90ab:cdef:fedc:ba09:8765:4321 4321:8765:ba09:fedc:cdef:90ab:5678:1234 443 65535\r\n";
let addresses = Addresses::new_tcp6(
    Ipv6Addr::from([0x1234, 0x5678, 0x90AB, 0xCDEF, 0xFEDC, 0xBA09, 0x8765, 0x4321]),
    Ipv6Addr::from([0x4321, 0x8765, 0xBA09, 0xFEDC, 0xCDEF, 0x90AB, 0x5678, 0x01234,]),
    443,
    65535
);

assert_eq!(addresses, header.parse().unwrap());
assert_eq!(addresses.to_string().as_str(), header);

Invalid

use ppp::v1::{Addresses, ParseError};

assert_eq!(Err(ParseError::InvalidProtocol), "PROXY tcp4\r\n".parse::<Addresses>());

Variants

Unknown

Tcp4(IPv4)

Tcp6(IPv6)

Implementations

Create a new IPv4 TCP address.

Create a new IPv6 TCP address.

The protocol portion of this Addresses.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.