Skip to main content

parse_binding_request

Function parse_binding_request 

Source
pub fn parse_binding_request(
    datagram: &[u8],
) -> Result<TransactionId, StunError>
Expand description

Parse a STUN Binding request datagram, returning its transaction id (SPEC.md §2.5). The server-side counterpart of parse_binding_response, used to answer a peer or the operator/ relay/public UDP tiers with encode_binding_success.

Validates, in order: length ≥ 20 (StunError::Truncated); the magic cookie (StunError::BadMagicCookie); the message type is EXACTLY BINDING_REQUEST (StunError::UnexpectedType otherwise — this single equality check also rejects a message whose top two type bits are non-zero, since BINDING_REQUEST’s own encoding has them clear, so no STUN method or class other than Binding+Request is accepted here; a caller wanting RFC 5389’s “silently ignore anything else” latitude does so by not replying to that error); the declared message length fits the datagram. Attributes present on the request (e.g. SOFTWARE) are accepted and ignored — nothing here needs them.