[−][src]Function ppp::parse_v2_header
pub fn parse_v2_header(input: &[u8]) -> ParseResult<&[u8]>
Parse the first 16 bytes of the protocol header; the only required payload. The 12 byte signature and 4 bytes used to describe the connection and header information.
Examples
TCP over IPv6 with some TLVs
let mut input: Vec<u8> = Vec::new(); input.extend_from_slice(b"\r\n\r\n\0\r\nQUIT\n"); input.push(0x21); input.push(0x21); input.extend(&[0, 45]); input.extend(&[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]); input.extend(&[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF1]); input.extend(&[0, 80]); input.extend(&[1, 187]); input.extend(&[1, 0, 1, 5]); input.extend(&[2, 0, 2, 5, 5]); input.extend(&[1, 1, 1]); assert_eq!(ppp::parse_v2_header(&input[..]), Ok((&[1, 1, 1][..], ppp::model::Header::new( ppp::model::Version::Two, ppp::model::Command::Proxy, ppp::model::Protocol::Stream, vec![ppp::model::Tlv::new(1, vec![5]), ppp::model::Tlv::new(2, vec![5, 5])], ( [0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF], [0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFF1], 80, 443 ).into(), ))))
UDP over IPv4 with some TLVs
let mut input: Vec<u8> = Vec::new(); input.extend_from_slice(b"\r\n\r\n\0\r\nQUIT\n"); input.push(0x20); input.push(0x12); input.extend(&[0, 21]); input.extend(&[127, 0, 0, 1]); input.extend(&[192, 168, 1, 1]); input.extend(&[0, 80]); input.extend(&[1, 187]); input.extend(&[1, 0, 1, 5]); input.extend(&[2, 0, 2, 5, 5]); input.extend(&[1, 2, 3, 4, 5]); assert_eq!(ppp::parse_v2_header(&input[..]), Ok((&[1, 2, 3, 4, 5][..], ppp::model::Header::new( ppp::model::Version::Two, ppp::model::Command::Local, ppp::model::Protocol::Datagram, vec![ppp::model::Tlv::new(1, vec![5]), ppp::model::Tlv::new(2, vec![5, 5])], ([127, 0, 0, 1], [192, 168, 1, 1], 80, 443).into(), ))))
Stream over Unix with some TLVs
let mut input: Vec<u8> = Vec::new(); input.extend_from_slice(b"\r\n\r\n\0\r\nQUIT\n"); input.push(0x20); input.push(0x31); input.extend(&[0, 225]); input.extend(&[0xFFu8; 108][..]); input.extend(&[0xAAu8; 108][..]); input.extend(&[1, 0, 1, 5]); input.extend(&[2, 0, 2, 5, 5]); input.extend(&[1, 2, 3, 4, 5]); assert_eq!(ppp::parse_v2_header(&input[..]), Ok((&[1, 2, 3, 4, 5][..], ppp::model::Header::new( ppp::model::Version::Two, ppp::model::Command::Local, ppp::model::Protocol::Stream, vec![ppp::model::Tlv::new(1, vec![5]), ppp::model::Tlv::new(2, vec![5, 5])], ([0xFFFFFFFFu32; 27], [0xAAAAAAAAu32; 27]).into(), ))))
Unspecified protocol over IPv6 with some TLVs
let mut input: Vec<u8> = Vec::new(); input.extend_from_slice(b"\r\n\r\n\0\r\nQUIT\n"); input.push(0x21); input.push(0x20); input.extend(&[0, 41]); input.extend(&[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]); input.extend(&[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF1]); input.extend(&[1, 0, 1, 5]); input.extend(&[2, 0, 2, 5, 5]); input.extend(&[42]); assert_eq!(ppp::parse_v2_header(&input[..]), Ok((&[42][..], ppp::model::Header::new( ppp::model::Version::Two, ppp::model::Command::Proxy, ppp::model::Protocol::Unspecified, vec![ppp::model::Tlv::new(1, vec![5]), ppp::model::Tlv::new(2, vec![5, 5])], ( [0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF], [0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFF1] ).into() ))))