pub fn encode_v2(
command: ProxyCommand,
source: Option<SocketAddr>,
destination: Option<SocketAddr>,
tlvs: &[Tlv<'_>],
with_crc: bool,
out: &mut [u8],
) -> Result<usize, ProxyError>Available on crate feature
proxy only.Expand description
Writes a v2 header; returns its length. None for either address sends UNSPEC,
which is what ProxyCommand::Local means. with_crc adds a CRC32C TLV.
use net_io::{ProxyCommand, ProxyParser, ProxyProgress, ProxyVersions};
let mut out = [0u8; 64];
let n = net_io::encode_v2(
ProxyCommand::Proxy,
Some("192.0.2.1:5000".parse().unwrap()),
Some("192.0.2.2:80".parse().unwrap()),
&[],
true,
&mut out,
)?;
assert!(n > 16);ยงErrors
FamilyMismatch, OutputTooSmall, V2LengthTooLarge when it cannot fit 65,535 bytes.