# yacine204/snffff architecture

> Architecture diagram of the GitHub repository yacine204/snffff, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yacine204/snffff
- Repository: https://github.com/yacine204/snffff

## Overview

snffff is a minimal Unix packet sniffer: it reads raw AF_PACKET frames, decodes Ethernet and network-layer headers, prints packet details, and parses TCP segments into flows that can be printed on interrupt. The graph follows the sampled call paths; IPv6 TCP dispatch is represented because the parser explicitly supports it. ARP parsing is present, though Ethernet-type-specific ARP dispatch is not shown. Flow storage is an in-memory map, not persistent storage.

Main entry points: [`main.go`](https://github.com/yacine204/snffff/blob/master/main.go) (Raw socket loop), [`internal/l3.go`](https://github.com/yacine204/snffff/blob/master/internal/l3.go) (IP/ARP dispatch), [`internal/l4.go`](https://github.com/yacine204/snffff/blob/master/internal/l4.go) (TCP parser), [`internal/eth.go`](https://github.com/yacine204/snffff/blob/master/internal/eth.go) (Packet output)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Capture"]
  node_capture_loop["Raw socket loop<br/>[main.go]"]
end

subgraph group_decode["Packet decoding"]
  node_ethernet["Ethernet parser<br/>[eth.go]"]
  node_network_dispatch["IP/ARP dispatch<br/>[l3.go]"]
  node_ipv4["IPv4 parser<br/>[l3.go]"]
  node_ipv6["IPv6 parser<br/>[l3.go]"]
  node_arp["ARP parser<br/>[l3.go]"]
  node_tcp_parser["TCP parser<br/>[l4.go]"]
  node_packet_output["Packet output<br/>[eth.go]"]
end

subgraph group_flows["TCP flows"]
  node_tcp_output["TCP output<br/>[l4.go]"]
  node_packet_queue["TCP packet queue<br/>[l4.go]"]
  node_flow_worker["Flow worker<br/>[l4.go]"]
  node_flow_id["Flow ID builder<br/>[l4.go]"]
  node_flow_store[("TCP flow map<br/>[l4.go]")]
  node_interrupt_printer["Interrupt printer<br/>[l4.go]"]
end

node_packets(("Network packets"))

node_packets -->|"supplies frames"| node_capture_loop
node_capture_loop -->|"parses frame"| node_ethernet
node_capture_loop -->|"starts worker"| node_flow_worker
node_capture_loop -->|"starts listener"| node_interrupt_printer
node_ethernet -->|"dispatches payload"| node_network_dispatch
node_ethernet -->|"prints frame"| node_packet_output
node_network_dispatch -->|"parses IPv4"| node_ipv4
node_network_dispatch -->|"parses IPv6"| node_ipv6
node_network_dispatch -->|"parses fallback"| node_arp
node_ipv4 -->|"dispatches TCP"| node_tcp_parser
node_ipv6 -->|"dispatches TCP"| node_tcp_parser
node_ipv4 -->|"prints headers"| node_packet_output
node_ipv6 -->|"prints headers"| node_packet_output
node_arp -->|"prints headers"| node_packet_output
node_tcp_parser -->|"prints segment"| node_tcp_output
node_tcp_parser -->|"enqueues segment"| node_packet_queue
node_packet_queue -->|"delivers segments"| node_flow_worker
node_flow_worker -->|"groups segments"| node_flow_store
node_flow_worker -->|"builds flow key"| node_flow_id
node_interrupt_printer -->|"prints stored flows"| node_flow_store
node_interrupt_printer -->|"prints segments"| node_tcp_output

click node_capture_loop "https://github.com/yacine204/snffff/blob/master/main.go"
click node_ethernet "https://github.com/yacine204/snffff/blob/master/internal/eth.go"
click node_network_dispatch "https://github.com/yacine204/snffff/blob/master/internal/l3.go"
click node_ipv4 "https://github.com/yacine204/snffff/blob/master/internal/l3.go"
click node_ipv6 "https://github.com/yacine204/snffff/blob/master/internal/l3.go"
click node_arp "https://github.com/yacine204/snffff/blob/master/internal/l3.go"
click node_tcp_parser "https://github.com/yacine204/snffff/blob/master/internal/l4.go"
click node_packet_output "https://github.com/yacine204/snffff/blob/master/internal/eth.go"
click node_tcp_output "https://github.com/yacine204/snffff/blob/master/internal/l4.go"
click node_packet_queue "https://github.com/yacine204/snffff/blob/master/internal/l4.go"
click node_flow_worker "https://github.com/yacine204/snffff/blob/master/internal/l4.go"
click node_flow_id "https://github.com/yacine204/snffff/blob/master/internal/l4.go"
click node_flow_store "https://github.com/yacine204/snffff/blob/master/internal/l4.go"
click node_interrupt_printer "https://github.com/yacine204/snffff/blob/master/internal/l4.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_capture_loop toneBlue
class node_ethernet,node_network_dispatch,node_ipv4,node_ipv6,node_arp,node_tcp_parser,node_packet_output toneAmber
class node_tcp_output,node_packet_queue,node_flow_worker,node_flow_id,node_flow_store,node_interrupt_printer toneMint
class node_packets toneIndigo
```

## Components

### Capture

- [Raw socket loop](https://github.com/yacine204/snffff/blob/master/main.go): `main.go`

### Packet decoding

- [Ethernet parser](https://github.com/yacine204/snffff/blob/master/internal/eth.go): `internal/eth.go`
- [IP/ARP dispatch](https://github.com/yacine204/snffff/blob/master/internal/l3.go): `internal/l3.go`
- [IPv4 parser](https://github.com/yacine204/snffff/blob/master/internal/l3.go): `internal/l3.go`
- [IPv6 parser](https://github.com/yacine204/snffff/blob/master/internal/l3.go): `internal/l3.go`
- [ARP parser](https://github.com/yacine204/snffff/blob/master/internal/l3.go): `internal/l3.go`
- [TCP parser](https://github.com/yacine204/snffff/blob/master/internal/l4.go): `internal/l4.go`
- [Packet output](https://github.com/yacine204/snffff/blob/master/internal/eth.go): `internal/eth.go`

### TCP flows

- [TCP output](https://github.com/yacine204/snffff/blob/master/internal/l4.go): `internal/l4.go`
- [TCP packet queue](https://github.com/yacine204/snffff/blob/master/internal/l4.go): `internal/l4.go`
- [Flow worker](https://github.com/yacine204/snffff/blob/master/internal/l4.go): `internal/l4.go`
- [Flow ID builder](https://github.com/yacine204/snffff/blob/master/internal/l4.go): `internal/l4.go`
- [TCP flow map](https://github.com/yacine204/snffff/blob/master/internal/l4.go): `internal/l4.go`
- [Interrupt printer](https://github.com/yacine204/snffff/blob/master/internal/l4.go): `internal/l4.go`

### Other components

- **Network packets**

## Connections

- Network packets → Raw socket loop: supplies frames (evidence: `README.md`)
- Raw socket loop → Ethernet parser: parses frame (evidence: `main.go`)
- Raw socket loop → Flow worker: starts worker (evidence: `main.go`)
- Raw socket loop → Interrupt printer: starts listener (evidence: `main.go`)
- Ethernet parser → IP/ARP dispatch: dispatches payload (evidence: `internal/eth.go`)
- Ethernet parser → Packet output: prints frame (evidence: `internal/eth.go`)
- IP/ARP dispatch → IPv4 parser: parses IPv4 (evidence: `internal/l3.go`)
- IP/ARP dispatch → IPv6 parser: parses IPv6 (evidence: `internal/l3.go`)
- IP/ARP dispatch → ARP parser: parses fallback (evidence: `internal/l3.go`)
- IPv4 parser → TCP parser: dispatches TCP (evidence: `internal/l3.go`)
- IPv6 parser → TCP parser: dispatches TCP (evidence: `internal/l3.go`)
- IPv4 parser → Packet output: prints headers (evidence: `internal/l3.go`)
- IPv6 parser → Packet output: prints headers (evidence: `internal/l3.go`)
- ARP parser → Packet output: prints headers (evidence: `internal/l3.go`)
- TCP parser → TCP output: prints segment (evidence: `internal/l4.go`)
- TCP parser → TCP packet queue: enqueues segment (evidence: `internal/l4.go`)
- TCP packet queue → Flow worker: delivers segments (evidence: `internal/l4.go`)
- Flow worker → TCP flow map: groups segments (evidence: `internal/l4.go`)
- Flow worker → Flow ID builder: builds flow key (evidence: `internal/l4.go`)
- Interrupt printer → TCP flow map: prints stored flows (evidence: `internal/l4.go`)
- Interrupt printer → TCP output: prints segments (evidence: `internal/l4.go`)
