Lion Cipher Lab

Write a packet sniffer from scratch (raw AF_PACKET socket, parse Ethernet/IP/TCP by hand)

Why it matters

Every packet-analysis tool you will ever touch -- Wireshark, tcpdump, Zeek, an IDS, your cloud provider's flow logs -- is, underneath the pretty columns, doing exactly what you are about to do by hand: pull raw bytes off an interface and decode fixed-offset headers into meaning. Most learners only ever meet those bytes as a coloured row in a GUI, which means when something is weird -- a malformed header, a tunnelled protocol, a field the tool does not decode -- they are stuck, because they have never seen the layout underneath the label. Writing a sniffer from scratch fixes that permanently.…

What you'll learn

Steps in this lab

  1. What a raw socket is, and why capture needs root
  2. Open the raw AF_PACKET socket (build the sniffer, part 1)
  3. Parse the Ethernet frame by hand (part 2)
  4. Parse the IPv4 header, then TCP/UDP ports (part 3)
  5. Run it and make traffic to watch it work
  6. The named failure modes that separate a toy from a tool
  7. The judgment: when to write raw, and how the pros do it

Open the full interactive lab →