Skip to main content

OctetRail

OctetRail is a Rust rewrite of dpkt, working toward a compatible Python API. It currently provides native offline pcap and PCAPNG readers, bounded output subsets and an experimental octetrail Python wheel. It is not a drop-in dpkt replacement.

The classic reader supports ordinary pcap 2.4, both byte orders and microsecond or nanosecond timestamps. It preserves raw packet bytes, original lengths, capture metadata and exact integer timestamp components. It has no runtime dependencies and forbids unsafe Rust.

The separate PCAPNG reader supports a measured Enhanced Packet Block subset, section-local interface clocks and explicit resource limits. The classic-PCAP writer emits validated offline records, with explicit rounding and I/O behavior. The PCAPNG writer supports one section, one interface and Enhanced Packet Blocks with bounded metadata options. Modified pcap, broad protocol decoding and a dpkt import layer are not implemented. The compatibility contract tracks these separately from import names, distribution metadata and downstream behavior. The explicit capture provider supplies the covered Python reader/writer subset without changing normal dpkt imports. The UniversalReader guide describes measured 1.9.8-style format selection over the native readers.

Ethernet II, IPv4 and opaque TCP/UDP objects can be composed and decoded offline. See the composition guide for dispatch, options, checksum update rules, resource bounds and measured compatibility limits.

See the 0.2.0 release notes for the composition changes and their compatibility limits.

Use the classic-pcap reader

Install Rust with rustup. rust-toolchain.toml pins Rust 1.85.1 and its formatting and lint components. The crate declares a Rust 1.85 floor; only the pinned toolchain has been tested. Run commands from this directory.

cargo build --locked
cargo run --locked --bin pcap-read -- /path/to/synthetic.pcap
cargo run --locked --bin pcap-read -- --max-packet-bytes 1048576 /path/to/synthetic.pcap

The CLI writes JSON lines: one metadata object, then one object per packet with seconds, fraction, original_len and hex fields. Check its exit status. Output before a read error describes only the prefix processed successfully. Payload hex is for inspection and differential testing, not a performance API. The command reads a local file and does no live collection or protocol work.

The library accepts any synchronous std::io::Read:

use octetrail::{Limits, Reader};
use std::fs::File;

fn inspect() -> Result<(), Box<dyn std::error::Error>> {
    let reader = Reader::new(File::open("synthetic.pcap")?, Limits::default())?;
    println!("link type: {}", reader.header().linktype);
    for packet in reader {
        let packet = packet?;
        println!("{} captured bytes", packet.data.len());
    }
    Ok(())
}

Construction consumes the 24-byte global header. Each iterator step consumes one record. EOF and record errors are terminal; no resynchronization is tried. No seek is required. into_inner() returns the owned input at its current logical position. An input adapter such as BufReader may buffer bytes internally. Stopping early leaves subsequent records unread by the parser. Dropping the reader drops its owned input. Borrow an input with &mut to keep ownership.

The default maximum captured packet length is 16 MiB. A limit of zero permits only empty packets. Captured length must not exceed snap length or original length. Versions other than 2.4, zero snap length, out-of-range fractions and incomplete headers or payloads are errors. Unknown link types and nonzero reserved header fields are retained without interpretation. These checks deliberately differ from dpkt on some inputs. The core does not map errors to Python classes.

The parser holds at most one packet buffer and fixed headers. Memory also depends on input buffering and any outputs the caller retains. There is no process-wide memory cap, total capture-size cap, packet-count cap or wall-clock timeout. A caller-provided Read can block; the host must supply its own I/O policy.

Verify

cargo fmt --check
cargo clippy --locked --workspace --all-targets -- -D warnings
cargo test --locked --workspace
cargo test --locked --doc
cargo build --locked
python3 -m compileall -q tools python tests/python

Use separate environments for the two published reference versions. The test harness runs the reference interpreter in isolated mode and verifies its import origin and installed distribution version. Install only the hash-pinned wheels:

python3 -m venv .venv-oracle-198
.venv-oracle-198/bin/python -m pip install --require-hashes --only-binary=:all: -r tools/oracle-1.9.8.txt
python3 tools/differential.py --python "$PWD/.venv-oracle-198/bin/python"

python3 -m venv .venv-oracle-196
.venv-oracle-196/bin/python -m pip install --require-hashes --only-binary=:all: -r tools/oracle-1.9.6.txt
python3 tools/differential.py --python "$PWD/.venv-oracle-196/bin/python" --version 1.9.6

After wheel installation the harness is offline. For an offline installation, first download the pinned wheels to a local wheelhouse and add --no-index --find-links /path/to/wheelhouse to the installation commands.

The Python reader guide covers local wheel builds, isolated installation and verification commands. The capture API reference lists supported behavior and exclusions. The reader and writer guides describe streaming, timestamp, ownership and resource-limit semantics. No performance, whole-library parity or package resolver substitution is claimed.

License

Original work is under the BSD 3-Clause license. dpkt attribution and its applicable upstream license are retained in NOTICE and licenses/dpkt.txt. The synthetic fixtures are original test data. No CAPE source or tests are redistributed here.

Metadata

Release files for octetrail 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for octetrail 0.2.0
File Interpreter ABI Platform Actions
octetrail-0.2.0-cp313-cp313-manylinux_2_34_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.34+ x86-64 Details for octetrail-0.2.0-cp313-cp313-manylinux_2_34_x86_64.whl
octetrail-0.2.0-cp312-cp312-manylinux_2_34_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.34+ x86-64 Details for octetrail-0.2.0-cp312-cp312-manylinux_2_34_x86_64.whl

Total release size: 613.8 kB

Release files / octetrail-0.2.0-cp313-cp313-manylinux_2_34_x86_64.whl

Download URL octetrail-0.2.0-cp313-cp313-manylinux_2_34_x86_64.whl
Size 306.6 kB
Tags CPython 3.13 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
bb2ba1c3e292594e71c4c672df8996d4a10169480cf4d110c07398b4c0876465
BLAKE2b-256 checksum
How to use checksums
fd6d36900870fad9630e8603fb9180222f0602e8a304a769eddb581d65b567c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release files / octetrail-0.2.0-cp312-cp312-manylinux_2_34_x86_64.whl

Download URL octetrail-0.2.0-cp312-cp312-manylinux_2_34_x86_64.whl
Size 307.2 kB
Tags CPython 3.12 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
aaeaf46482bc320426d5c6f8a63a14a8dfc2006809adab31cac1276390036a87
BLAKE2b-256 checksum
How to use checksums
446c3406d42b55b2d2ad18d0563ff8e137e74fb9514d86ac3d576c5c67e4271e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Security for octetrail 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page