# cgb/ndpi_example architecture

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

- Interactive diagram: https://gitdiagram.com/cgb/ndpi_example
- Repository: https://github.com/cgb/ndpi_example

## Overview

This is a small command-line example that reads a saved packet capture, tracks IP identities and flows, and reports protocol-detection totals using nDPI. The main workflow runs from option parsing through offline capture processing to a printed summary. The excerpts show capture dispatch and setup, but omit part of packet_processing, so its handoff to nDPI is shown as unverified. The graph focuses on runtime behavior, not build files.

Main entry points: [`ndpiex.c`](https://github.com/cgb/ndpi_example/blob/master/ndpiex.c) (Packet processing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Capture input"]
  node_options["Option parsing<br/>[ndpiex.c]"]
  node_pcap_reader["Offline capture<br/>[ndpiex.c]"]
  node_callback["Packet callback<br/>[ndpiex.c]"]
end

subgraph group_analysis["Packet analysis"]
  node_packet_processing["Packet processing<br/>[ndpiex.c]"]
  node_flow_tracking["Flow tracking<br/>[ndpiex.c]"]
  node_id_tracking["Identity tracking<br/>[ndpiex.c]"]
  node_detection_setup["Detection setup<br/>[ndpiex.c]"]
end

subgraph group_reporting["Results"]
  node_counters[("Protocol counters<br/>[ndpiex.c]")]
  node_results["Printed results<br/>[ndpiex.c]"]
end

node_user(("Operator"))
node_pcap["PCAP file"]
node_ndpi["nDPI library"]

node_user -->|"supplies options"| node_options
node_user -->|"selects capture"| node_pcap
node_options -->|"sets capture path"| node_pcap_reader
node_pcap_reader -->|"reads packets"| node_pcap
node_pcap_reader -->|"dispatches packets"| node_callback
node_callback -->|"processes packet"| node_packet_processing
node_packet_processing -->|"gets identities"| node_id_tracking
node_packet_processing -->|"gets flow"| node_flow_tracking
node_packet_processing -.->|"classifies traffic"| node_ndpi
node_detection_setup -->|"initializes"| node_ndpi
node_packet_processing -.->|"updates totals"| node_counters
node_counters -->|"summarizes"| node_results

click node_options "https://github.com/cgb/ndpi_example/blob/master/ndpiex.c"
click node_pcap_reader "https://github.com/cgb/ndpi_example/blob/master/ndpiex.c"
click node_callback "https://github.com/cgb/ndpi_example/blob/master/ndpiex.c"
click node_packet_processing "https://github.com/cgb/ndpi_example/blob/master/ndpiex.c"
click node_flow_tracking "https://github.com/cgb/ndpi_example/blob/master/ndpiex.c"
click node_id_tracking "https://github.com/cgb/ndpi_example/blob/master/ndpiex.c"
click node_detection_setup "https://github.com/cgb/ndpi_example/blob/master/ndpiex.c"
click node_counters "https://github.com/cgb/ndpi_example/blob/master/ndpiex.c"
click node_results "https://github.com/cgb/ndpi_example/blob/master/ndpiex.c"

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_options,node_pcap_reader,node_callback toneBlue
class node_packet_processing,node_flow_tracking,node_id_tracking,node_detection_setup toneAmber
class node_counters,node_results toneMint
class node_user,node_pcap,node_ndpi toneIndigo
```

## Components

### Capture input

- [Option parsing](https://github.com/cgb/ndpi_example/blob/master/ndpiex.c): `ndpiex.c`
- [Offline capture](https://github.com/cgb/ndpi_example/blob/master/ndpiex.c): `ndpiex.c`
- [Packet callback](https://github.com/cgb/ndpi_example/blob/master/ndpiex.c): `ndpiex.c`

### Packet analysis

- [Packet processing](https://github.com/cgb/ndpi_example/blob/master/ndpiex.c): `ndpiex.c`
- [Flow tracking](https://github.com/cgb/ndpi_example/blob/master/ndpiex.c): `ndpiex.c`
- [Identity tracking](https://github.com/cgb/ndpi_example/blob/master/ndpiex.c): `ndpiex.c`
- [Detection setup](https://github.com/cgb/ndpi_example/blob/master/ndpiex.c): `ndpiex.c`

### Results

- [Protocol counters](https://github.com/cgb/ndpi_example/blob/master/ndpiex.c): `ndpiex.c`
- [Printed results](https://github.com/cgb/ndpi_example/blob/master/ndpiex.c): `ndpiex.c`

### Other components

- **Operator**
- **PCAP file**
- **nDPI library**

## Connections

- Operator → Option parsing: supplies options (evidence: `README.md`)
- Operator → PCAP file: selects capture (evidence: `README.md`)
- Option parsing → Offline capture: sets capture path (evidence: `ndpiex.c`)
- Offline capture → PCAP file: reads packets (evidence: `ndpiex.c`)
- Offline capture → Packet callback: dispatches packets (evidence: `ndpiex.c`)
- Packet callback → Packet processing: processes packet (evidence: `ndpiex.c`)
- Packet processing → Identity tracking: gets identities (evidence: `ndpiex.c`)
- Packet processing → Flow tracking: gets flow (evidence: `ndpiex.c`)
- Packet processing → nDPI library: classifies traffic
- Detection setup → nDPI library: initializes (evidence: `ndpiex.c`)
- Packet processing → Protocol counters: updates totals (evidence: `ndpiex.c`)
- Protocol counters → Printed results: summarizes (evidence: `ndpiex.c`)
