pub struct Header<'a> {
pub header: Cow<'a, [u8]>,
pub version: Version,
pub command: Command,
pub protocol: Protocol,
pub addresses: Addresses,
}
Expand description
A proxy protocol version 2 header.
Examples
use ppp::v2::{Addresses, AddressFamily, Command, Header, IPv4, ParseError, Protocol, PROTOCOL_PREFIX, Type, TypeLengthValue, Version};
let mut header = Vec::from(PROTOCOL_PREFIX);
header.extend([
0x21, 0x12, 0, 16, 127, 0, 0, 1, 192, 168, 1, 1, 0, 80, 1, 187, 4, 0, 1, 42
]);
let addresses: Addresses = IPv4::new([127, 0, 0, 1], [192, 168, 1, 1], 80, 443).into();
let expected = Header {
header: header.as_slice().into(),
version: Version::Two,
command: Command::Proxy,
protocol: Protocol::Datagram,
addresses
};
let actual = Header::try_from(header.as_slice()).unwrap();
assert_eq!(actual, expected);
assert_eq!(actual.tlvs().collect::<Vec<Result<TypeLengthValue<'_>, ParseError>>>(), vec![Ok(TypeLengthValue::new(Type::NoOp, &[42]))]);
Fields
header: Cow<'a, [u8]>
version: Version
command: Command
protocol: Protocol
addresses: Addresses
Implementations
sourceimpl<'a> Header<'a>
impl<'a> Header<'a>
sourcepub fn address_family(&self) -> AddressFamily
pub fn address_family(&self) -> AddressFamily
The AddressFamily
of this Header
.
sourcepub fn address_bytes(&self) -> &[u8]ⓘNotable traits for &[u8]impl<'_> Read for &[u8]impl<'_> Write for &mut [u8]
pub fn address_bytes(&self) -> &[u8]ⓘNotable traits for &[u8]impl<'_> Read for &[u8]impl<'_> Write for &mut [u8]
The bytes of the address portion of the payload.
sourcepub fn tlv_bytes(&self) -> &[u8]ⓘNotable traits for &[u8]impl<'_> Read for &[u8]impl<'_> Write for &mut [u8]
pub fn tlv_bytes(&self) -> &[u8]ⓘNotable traits for &[u8]impl<'_> Read for &[u8]impl<'_> Write for &mut [u8]
The bytes of the TypeLengthValue
portion of the payload.
sourcepub fn tlvs(&self) -> TypeLengthValues<'_>ⓘNotable traits for TypeLengthValues<'a>impl<'a> Iterator for TypeLengthValues<'a> type Item = Result<TypeLengthValue<'a>, ParseError>;
pub fn tlvs(&self) -> TypeLengthValues<'_>ⓘNotable traits for TypeLengthValues<'a>impl<'a> Iterator for TypeLengthValues<'a> type Item = Result<TypeLengthValue<'a>, ParseError>;
An Iterator
of TypeLengthValue
s.
Trait Implementations
impl<'a> StructuralPartialEq for Header<'a>
Auto Trait Implementations
impl<'a> RefUnwindSafe for Header<'a>
impl<'a> Send for Header<'a>
impl<'a> Sync for Header<'a>
impl<'a> Unpin for Header<'a>
impl<'a> UnwindSafe for Header<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more