Skip to main content

parse_header

Function parse_header 

Source
pub fn parse_header(header: &[u8; 19]) -> Result<(usize, u8), HeaderError>
Expand description

Validate a BGP message header without touching the body.

Returns (total_message_length, message_type). The length is the whole message including these 19 octets, exactly as it appears on the wire, and is guaranteed on return to be in [BGP_HEADER_LEN, BGP_MAX_MESSAGE_LEN] — so len - BGP_HEADER_LEN cannot underflow and allocating len bytes is bounded.

The per-type minimums come from RFC 4271 section 4.1: OPEN is at least 29, UPDATE at least 23, NOTIFICATION at least 21, KEEPALIVE exactly 19.