Skip to content

m-peko/phast

Repository files navigation

Ubuntu 22.04 - Clang 14

License

phast - Fast Network Packet Decoding Library

phast is a high-performance, C++20-based library for decoding network packets. Designed for speed and efficiency, it leverages modern C++ features to deliver a robust and scalable solution for network data processing.


Table of Contents


Quick Start

To quickly test phast, follow these steps:

# Clone the repository
git clone https://github.com/m-peko/phast
cd phast

# Build the example
cd examples/basic
mkdir build && cd build
cmake -GNinja ..
ninja

# Run the example
./example <path-to-PCAP-file>

Here’s an example of how packets are processed using phast:

auto const decoded{phast::decode(data, header->caplen)};
if (decoded.is_error()) {
    std::fprintf(stdout, "Error decoding the packet\n");
} else {
    for (auto const &pdu : decoded.value()) {
        std::visit(
            phast::Overloaded{
                [](phast::Ethernet const &eth) {
                    // EthernetII PDU decoded
                },
                [](phast::IPv4 const &ipv4) {
                    // IPv4 PDU decoded
                },
                [](phast::IPv6 const &ipv6) {
                    // IPv6 PDU decoded
                },
                [](phast::TCP const &tcp) {
                    // TCP PDU decoded
                }},
            pdu
        );
    }
}

Benchmark

The performance benchmarks for phast demonstrate its ability to handle network packet decoding at high throughput with minimal latency.

Benchmarks are run regularly on supported toolchains, and detailed results can be found here.


About phast

phast is built to simplify and accelerate the process of network packet decoding. Key features include:

  • High Performance: Optimized decoding routines for efficient packet parsing.
  • Modern C++20 Design: Fully utilizes C++20 language features and the standard library.
  • Extensibility: Easily integrate and extend for custom protocol decoding.
  • Cross-Platform Support: Tested on modern Linux distributions with GCC and Clang compilers.

CMake Integration

Integrating phast into your CMake project is simple. Use the following configuration:

cmake_minimum_required(VERSION 3.14)

project( my_project )

# Fetch the latest phast library
include( FetchContent )
FetchContent_Declare(
    phast
    GIT_REPOSITORY https://github.com/m-peko/phast.git
    GIT_TAG        main
)
FetchContent_MakeAvailable( phast )

add_executable( my_project main.cpp )
target_link_libraries( my_project phast )

This setup ensures phast is automatically fetched and built as part of your project.


Building, Testing, and Installing

Prerequisites

  • C++20 Compiler: GCC (>= 10) or Clang (>= 12). Not tested on MSVC.
  • CMake: Version 3.14 or higher.
  • Build System: Ninja (recommended).

Steps

  1. Clone the Repository:

    git clone https://github.com/m-peko/phast
    cd phast
  2. Build the Library:

    mkdir build && cd build
    cmake -GNinja -DPHAST_ENABLE_TESTS=ON ..
    ninja
  3. Run Tests:

    ctest
  4. Install the Library:

    ninja install

Supported Toolchains

phast has been tested with the following configurations:

  • Ubuntu 22.04:
    • GCC 10+
    • Clang 12+ (tested up to Clang 14)

Other platforms or compilers may work but have not been officially tested.


Contributing

We welcome contributions from the community! If you’d like to contribute, please:

  1. Fork the repository.
  2. Create a feature branch.
  3. Submit a pull request.

For detailed guidelines, see CONTRIBUTING.md.


License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Fast Network Packet Decoding Library

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published