# buuhis/packet-parser architecture

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

- Interactive diagram: https://gitdiagram.com/buuhis/packet-parser
- Repository: https://github.com/buuhis/packet-parser

## Overview

Packet Parser captures traffic from a selected interface, dispatches each captured frame through link-layer and IPv4 handling, then parses TCP or UDP; UDP traffic on port 53 receives additional DNS analysis. Parser output goes through a shared logger to the console and `output.txt`. The README also describes Ethernet, 802.11 and Radiotap support and live monitoring. The graph follows the sampled calls; deeper connection tracking is documented but not evident in the excerpts.

Main entry points: [`util/src/logger.c`](https://github.com/buuhis/packet-parser/blob/main/util/src/logger.c) (Shared logger), [`src/main.c`](https://github.com/buuhis/packet-parser/blob/main/src/main.c) (Capture entry), [`src/packet_parser.c`](https://github.com/buuhis/packet-parser/blob/main/src/packet_parser.c) (Frame and IP dispatch), [`src/udp_parser.c`](https://github.com/buuhis/packet-parser/blob/main/src/udp_parser.c) (UDP analysis)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Capture and routing"]
  node_main["Capture entry<br/>[main.c]"]
  node_pcap["libpcap capture"]
  node_handler["Frame and IP dispatch<br/>[packet_parser.c]"]
end

subgraph group_protocols["Protocol analysis"]
  node_tcp["TCP analysis<br/>[tcp_parser.c]"]
  node_udp["UDP analysis<br/>[udp_parser.c]"]
  node_dns["DNS deep parsing<br/>[dns_parser.c]"]
end

subgraph group_output["Logging and output"]
  node_logger["Shared logger<br/>[logger.c]"]
  node_console["Console output"]
  node_logfile["Packet log file<br/>[output.txt]"]
end

node_operator(("Operator"))
node_interface(("Network interface"))

node_operator -->|"selects interface"| node_main
node_main -->|"opens for capture"| node_interface
node_main -->|"initializes"| node_logger
node_main -->|"starts capture"| node_pcap
node_pcap -->|"invokes callback"| node_handler
node_handler -->|"dispatches TCP"| node_tcp
node_handler -->|"dispatches UDP"| node_udp
node_udp -->|"parses port 53"| node_dns
node_tcp -->|"logs packet"| node_logger
node_udp -->|"logs packet"| node_logger
node_dns -->|"logs details"| node_logger
node_logger -->|"writes formatted output"| node_console
node_logger -->|"appends and flushes"| node_logfile

click node_main "https://github.com/buuhis/packet-parser/blob/main/src/main.c"
click node_handler "https://github.com/buuhis/packet-parser/blob/main/src/packet_parser.c"
click node_tcp "https://github.com/buuhis/packet-parser/blob/main/src/tcp_parser.c"
click node_udp "https://github.com/buuhis/packet-parser/blob/main/src/udp_parser.c"
click node_dns "https://github.com/buuhis/packet-parser/blob/main/src/dns_parser.c"
click node_logger "https://github.com/buuhis/packet-parser/blob/main/util/src/logger.c"
click node_logfile "https://github.com/buuhis/packet-parser/blob/main/output.txt"

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_main,node_pcap,node_handler toneBlue
class node_tcp,node_udp,node_dns toneAmber
class node_logger,node_console,node_logfile toneMint
class node_operator,node_interface toneIndigo
```

## Components

### Capture and routing

- [Capture entry](https://github.com/buuhis/packet-parser/blob/main/src/main.c): `src/main.c`
- **libpcap capture**
- [Frame and IP dispatch](https://github.com/buuhis/packet-parser/blob/main/src/packet_parser.c): `src/packet_parser.c`

### Protocol analysis

- [TCP analysis](https://github.com/buuhis/packet-parser/blob/main/src/tcp_parser.c): `src/tcp_parser.c`
- [UDP analysis](https://github.com/buuhis/packet-parser/blob/main/src/udp_parser.c): `src/udp_parser.c`
- [DNS deep parsing](https://github.com/buuhis/packet-parser/blob/main/src/dns_parser.c): `src/dns_parser.c`

### Logging and output

- [Shared logger](https://github.com/buuhis/packet-parser/blob/main/util/src/logger.c): `util/src/logger.c`
- **Console output**
- [Packet log file](https://github.com/buuhis/packet-parser/blob/main/output.txt): `output.txt`

### Other components

- **Operator**
- **Network interface**

## Connections

- Operator → Capture entry: selects interface (evidence: `README.md`)
- Capture entry → Network interface: opens for capture (evidence: `src/main.c`)
- Capture entry → Shared logger: initializes (evidence: `src/main.c`)
- Capture entry → libpcap capture: starts capture (evidence: `src/main.c`)
- libpcap capture → Frame and IP dispatch: invokes callback
- Frame and IP dispatch → TCP analysis: dispatches TCP (evidence: `src/packet_parser.c`)
- Frame and IP dispatch → UDP analysis: dispatches UDP (evidence: `src/packet_parser.c`)
- UDP analysis → DNS deep parsing: parses port 53 (evidence: `src/udp_parser.c`)
- TCP analysis → Shared logger: logs packet (evidence: `src/tcp_parser.c`)
- UDP analysis → Shared logger: logs packet (evidence: `src/udp_parser.c`)
- DNS deep parsing → Shared logger: logs details (evidence: `src/dns_parser.c`)
- Shared logger → Console output: writes formatted output (evidence: `util/src/logger.c`)
- Shared logger → Packet log file: appends and flushes (evidence: `util/src/logger.c`)
