pub struct Header { /* private fields */ }Expand description
PROXY protocol v2 header.
Implementations§
Source§impl Header
impl Header
Sourcepub fn new(
command: Command,
transport_protocol: TransportProtocol,
address_family: AddressFamily,
src: impl Into<SocketAddr>,
dst: impl Into<SocketAddr>,
) -> Header
pub fn new( command: Command, transport_protocol: TransportProtocol, address_family: AddressFamily, src: impl Into<SocketAddr>, dst: impl Into<SocketAddr>, ) -> Header
Constructs a new PROXY protocol v2 header.
§Panics
Panics if address_family does not match src and dst.
Sourcepub fn new_unspecified(command: Command) -> Header
pub fn new_unspecified(command: Command) -> Header
Constructs a new header without address information.
Sourcepub fn new_unix(
command: Command,
transport_protocol: TransportProtocol,
source: [u8; 108],
destination: [u8; 108],
) -> Header
pub fn new_unix( command: Command, transport_protocol: TransportProtocol, source: [u8; 108], destination: [u8; 108], ) -> Header
Constructs a new UNIX socket header.
Sourcepub fn new_tcp_ipv4_proxy(
src: impl Into<SocketAddr>,
dst: impl Into<SocketAddr>,
) -> Header
pub fn new_tcp_ipv4_proxy( src: impl Into<SocketAddr>, dst: impl Into<SocketAddr>, ) -> Header
Constructs a new TCP/IPv4 PROXY command header.
Sourcepub fn new_tcp_ipv6_proxy(
src: impl Into<SocketAddr>,
dst: impl Into<SocketAddr>,
) -> Header
pub fn new_tcp_ipv6_proxy( src: impl Into<SocketAddr>, dst: impl Into<SocketAddr>, ) -> Header
Constructs a new TCP/IPv6 PROXY command header.
Sourcepub const fn transport_protocol(&self) -> TransportProtocol
pub const fn transport_protocol(&self) -> TransportProtocol
Returns the transport protocol.
Sourcepub fn address_family(&self) -> AddressFamily
pub fn address_family(&self) -> AddressFamily
Returns the address family.
Sourcepub fn source_addr(&self) -> Option<SocketAddr>
pub fn source_addr(&self) -> Option<SocketAddr>
Returns the source socket address for IP headers.
Sourcepub fn destination_addr(&self) -> Option<SocketAddr>
pub fn destination_addr(&self) -> Option<SocketAddr>
Returns the destination socket address for IP headers.
Sourcepub fn tlvs(&self) -> impl Iterator<Item = (u8, &[u8])>
pub fn tlvs(&self) -> impl Iterator<Item = (u8, &[u8])>
Returns raw TLVs as (type, value) pairs.
Sourcepub fn add_typed_tlv<T>(&mut self, tlv: T)where
T: Tlv,
pub fn add_typed_tlv<T>(&mut self, tlv: T)where
T: Tlv,
Adds a typed TLV entry.
Sourcepub fn write_to(&self, wrt: &mut impl Write) -> Result<(), Error>
pub fn write_to(&self, wrt: &mut impl Write) -> Result<(), Error>
Writes this header to an I/O writer.
Sourcepub async fn write_to_tokio(
&self,
wrt: &mut (impl AsyncWrite + Unpin),
) -> Result<(), Error>
pub async fn write_to_tokio( &self, wrt: &mut (impl AsyncWrite + Unpin), ) -> Result<(), Error>
Writes this header to a Tokio async writer.
Sourcepub fn try_from_bytes(slice: &[u8]) -> Result<(&[u8], Header), ParseError>
pub fn try_from_bytes(slice: &[u8]) -> Result<(&[u8], Header), ParseError>
Attempts to parse a PROXY protocol v2 header from bytes.
Sourcepub fn has_tlv<T>(&self) -> boolwhere
T: Tlv,
pub fn has_tlv<T>(&self) -> boolwhere
T: Tlv,
Returns true when this header contains a TLV with type T.
Sourcepub fn add_crc32c_checksum(&mut self)
pub fn add_crc32c_checksum(&mut self)
Calculates and adds a crc32c TLV to the PROXY header.
Uses method defined in spec.
If this is not called last thing it will be wrong.
Sourcepub fn validate_crc32c_tlv(&self) -> Option<bool>
pub fn validate_crc32c_tlv(&self) -> Option<bool>
Validates the CRC32c TLV, returning None when no CRC32c TLV is present.