# seladb/pcapplusplus architecture

> Architecture diagram of the GitHub repository seladb/pcapplusplus, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/seladb/pcapplusplus
- Repository: https://github.com/seladb/pcapplusplus

## Overview

##### Main Components Overview

a) Packet++ Library (Core Parsing)
- Packet parsing/creation/editing
- Protocol implementations
- Layer management

b) Pcap++ Library (Capture Engine Wrapper)
- Packet capture interfaces
- Multiple capture engine support (libpcap, WinPcap, DPDK, etc.)
- File reading/writing

c) Common++ Library (Utilities)
- Shared utilities
- Common functionality

##### Key Architectural Elements

a) Engines Layer:
- libpcap/WinPcap/Npcap
- DPDK
- PF_RING
- Raw Sockets
- AF_XDP

b) Protocol Stack Layer:
- L2 (Data Link) protocols
- L3 (Network) protocols
- L4 (Transport) protocols
- L5-L7 (Session/Presentation/Application) protocols

c) File I/O Layer:
- PCAP reader/writer
- PCAPNG reader/writer

d) Advanced Features:
- TCP Reassembly
- IP Fragmentation
- TLS Fingerprinting
- Packet Filtering

##### Relationships and Data Flow

- Data flow between capture engines and protocol parsers
- Interaction between different libraries
- Processing pipeline from capture to analysis

##### Implementation Details

Technical notes for:
- Cross-platform support
- Thread safety considerations
- Performance optimization points
- Extension points

**[External Capture Engines]**
- ↓
**[Pcap++ Abstraction Layer]**
- ↓
**[Packet Processing Pipeline]**
- ↙     ↓     ↘
**[File I/O] [Protocol Stack] [Advanced Features]**
- ↓
**[Application Layer Interface]**

Key Design Principles to Highlight:
##### High-performance packet processing capabilities

This design captures the essence of PcapPlusPlus as a comprehensive packet processing framework while showing its modular and extensible nature.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef library fill:#e1f5fe,stroke:#01579b
    classDef capture fill:#fff3e0,stroke:#e65100
    classDef protocol fill:#f3e5f5,stroke:#4a148c
    classDef fileio fill:#e8f5e9,stroke:#1b5e20
    classDef advanced fill:#fce4ec,stroke:#880e4f
    classDef external fill:#f5f5f5,stroke:#212121

    %% Main Libraries
    CommonLib["Common++ Library<br/>(Utilities)"]:::library
    PacketLib["Packet++ Library<br/>(Core Parsing)"]:::library
    PcapLib["Pcap++ Library<br/>(Capture Engine Wrapper)"]:::library

    %% External Capture Engines
    subgraph Engines["Capture Engines"]
        LibPcap["libpcap/WinPcap/Npcap"]:::external
        DPDK["DPDK"]:::external
        PF_RING["PF_RING"]:::external
        RawSock["Raw Sockets"]:::external
        AF_XDP["AF_XDP"]:::external
    end

    %% Protocol Stack
    subgraph Protocols["Protocol Stack"]
        L2["L2 (Data Link)<br/>Protocols"]:::protocol
        L3["L3 (Network)<br/>Protocols"]:::protocol
        L4["L4 (Transport)<br/>Protocols"]:::protocol
        L5_7["L5-7 (Application)<br/>Protocols"]:::protocol
    end

    %% File I/O Components
    subgraph FileIO["File I/O"]
        PcapRW["PCAP Reader/Writer"]:::fileio
        PcapNGRW["PCAPNG Reader/Writer"]:::fileio
    end

    %% Advanced Features
    subgraph Advanced["Advanced Features"]
        TcpReasm["TCP Reassembly"]:::advanced
        IpFrag["IP Fragmentation"]:::advanced
        TlsFP["TLS Fingerprinting"]:::advanced
        PacketFilter["Packet Filtering"]:::advanced
    end

    %% Relationships
    LibPcap & DPDK & PF_RING & RawSock & AF_XDP --> PcapLib
    PcapLib --> PacketLib
    PacketLib --> Protocols
    PacketLib --> Advanced
    CommonLib --> PacketLib
    CommonLib --> PcapLib
    PcapLib --> FileIO

    %% Click Events
    click CommonLib "https://github.com/seladb/pcapPlusPlus/tree/master/Common++/"
    click PacketLib "https://github.com/seladb/pcapPlusPlus/tree/master/Packet++/"
    click PcapLib "https://github.com/seladb/pcapPlusPlus/tree/master/Pcap++/"
    click DPDK "https://github.com/seladb/pcapPlusPlus/blob/master/Pcap++/header/DpdkDevice.h"
    click PF_RING "https://github.com/seladb/pcapPlusPlus/blob/master/Pcap++/header/PfRingDevice.h"
    click RawSock "https://github.com/seladb/pcapPlusPlus/blob/master/Pcap++/header/RawSocketDevice.h"
    click AF_XDP "https://github.com/seladb/pcapPlusPlus/blob/master/Pcap++/header/XdpDevice.h"
    click PcapRW "https://github.com/seladb/pcapPlusPlus/blob/master/Pcap++/header/PcapFileDevice.h"
    click PcapNGRW "https://github.com/seladb/pcapPlusPlus/tree/master/3rdParty/LightPcapNg/"
    click TcpReasm "https://github.com/seladb/pcapPlusPlus/blob/master/Packet++/header/TcpReassembly.h"
    click IpFrag "https://github.com/seladb/pcapPlusPlus/blob/master/Packet++/header/IPReassembly.h"
    click TlsFP "https://github.com/seladb/pcapPlusPlus/blob/master/Packet++/header/SSLLayer.h"
    click L2 "https://github.com/seladb/pcapPlusPlus/tree/master/Packet++/header/"
    click L3 "https://github.com/seladb/pcapPlusPlus/tree/master/Packet++/header/"
    click L4 "https://github.com/seladb/pcapPlusPlus/tree/master/Packet++/header/"
    click L5_7 "https://github.com/seladb/pcapPlusPlus/tree/master/Packet++/header/"

    %% Legend
    subgraph Legend
        L1["Core Libraries"]:::library
        L2["Capture Components"]:::capture
        L3["Protocol Components"]:::protocol
        L4["File I/O Components"]:::fileio
        L5["Advanced Features"]:::advanced
        L6["External Dependencies"]:::external
    end
```
