How google/gopacket works
Project type and purpose
• GoPacket is an open-source Go library (not a standalone application) designed to capture, parse, decode, and reassemble network packets at multiple layers.
• Its primary use case is to give Go developers a unified API to read packets from various sources (libpcap files, live captures, Linux AF_PACKET, BSD BPF, PF_RING), decode them into Go structs, reassemble streams, and feed the results into user code or higher-level tools.
File structure
• Top-level “capture” modules (each implementing a different packet source):
• pcap/ & pcapgo/ (libpcap‐based capture and pcap file read/write)
• afpacket/ (Linux AF_PACKET)
• bsdbpf/ (BSD BPF sniffer)
• pfring/ (PF_RING integration)
• Core decode pipeline files:
• packet.go, parser.go, decode.go – orchestrate reading raw bytes and invoking layer decoding
• layers/ – definitions of every protocol layer (Ethernet, IP, TCP, TLS, etc.) plus autogenerated enums and tests
• Stream reassembly modules:
• reassembly/ – generic TCP stream assembler, memory management
• tcpassembly/ – higher-level API to feed assembled streams to user callbacks
• defrag/ & ip4defrag/ – IP fragment reassembly utilities
• Utilities and examples:
• bytediff/, dumpcommand/, examples/, benchmark_test.go
• Build & CI config: .travis.*, go.mod, scripts, documentation stubs.
README for additional insights
• Confirms it’s a library for packet decoding.
• Points to godoc for API details.
• Notes Go version requirements.