Features
Everything you need for packet engineering — from crafting to sniffing with a clean, idiomatic Go API.
🔨 Builder API
Fluent method chaining for type-safe, explicit packet construction with compile-time guarantees.
⚡ Shortcut Functions
One-liners for common protocol stacks with sensible defaults. Build packets in a single function call.
🔬 Packet Dissect
Parse raw bytes into structured packets with automatic protocol detection and layer extraction.
📡 Send & Receive
Send and receive packets via raw sockets at both L2 (Ethernet) and L3 (IP) levels.
👃 Sniffing
Capture live traffic with callback or channel-based APIs, plus BPF filter support.
✅ Auto Checksums
IP, TCP, UDP, and ICMP checksums are computed automatically during serialization.
🔗 Layer Binding
Automatic field inference between adjacent layers — IP over Ethernet sets EtherType automatically.
💻 Cross-Platform
Works on macOS (Darwin) and Linux with platform-specific raw socket implementations.
Supported Protocols
Comprehensive coverage across the network stack layers.
| Layer | Protocols |
|---|---|
| Link | Ethernet (CSMA/CD), ARP |
| Network | IPv4 |
| Transport | TCP, UDP, ICMP |
| Payload | Raw bytes |
Get Started in Seconds
Add goscapy to your project with a single command.
# Install the latest version go get github.com/smallnest/goscapy
Build a Packet in One Line
🔨 Builder API
// Ethernet + IP + ICMP Echo Request pkt, err := goscapy.NewEthernet(). SrcMAC("aa:bb:cc:dd:ee:ff"). DstMAC("ff:ff:ff:ff:ff:ff"). Over(goscapy.NewIP(). SrcIP("192.168.1.1"). DstIP("8.8.8.8")). Over(goscapy.NewICMP(). Type(8).Code(0)). Build()
⚡ Shortcut
// Same packet, in one line pkt, err := goscapy.EtherIPICMP( "ff:ff:ff:ff:ff:ff", "8.8.8.8", 8, 0, )
🔬 Dissect Raw Bytes
// Parse raw bytes into structured packet raw := []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, ...} pkt, err := packet.Dissect(raw, packet.DissectEthernet) fmt.Println(pkt.String()) // "Ethernet / IP / ICMP"