📜 Reading Protocol Specs
5 exercises — interpret real protocol specifications: ABNF grammar notation, the WebSocket opening handshake, the TCP state machine, IPv4 header field definitions and URI syntax.
Protocol spec notation
- ABNF →
/= alternatives,[x]= optional,*x= zero+,n*m x= between n and m - State machine → read each edge as state → (event; action) → next-state
- Handshake → ordered steps; the exact primitive (SHA-1 vs SHA-256) matters
- Field definition → note width, unit and constraints (e.g. length in 32-bit words)
0 / 5 completed
1 / 5
RFC 5234 — ABNF Grammar
RFC 5234 — Augmented BNF for Syntax Specifications: ABNF
Example grammar for a US postal address
postal-address = name-part street zip-part
name-part = *(personal-part SP) last-name [SP suffix] CRLF
personal-part = first-name / (initial ".")
street = [apt SP] house-num SP street-name CRLF
zip-part = town-name "," SP state 1*2SP zip-code CRLF
Notation reminders:
/ alternatives (one of)
[foo] optional element
*foo zero or more repetitions
1*2foo between one and two repetitions
n*m between n and m repetitions In the rule
zip-part = town-name "," SP state 1*2SP zip-code CRLF, what does 1*2SP specify?1*2SP = between one and two repetitions of SP:In ABNF the repetition form is
n*m element, meaning "at least n and at most m occurrences." The reminder block spells it out: 1*2foo → "between one and two repetitions." So 1*2SP allows one or two spaces — not zero, and not three.*foo→ zero or more (n and m both default away)1*foo→ one or more (no upper bound) — this is option D, the wrong one2foo→ exactly two[foo]→ optional (equivalent to*1foo)
* (minimum) and after it (maximum). Mixing up 1*2 (one-to-two) with 1* (one-or-more) is the most common ABNF misreading, so always check whether a maximum is present.