Public API

The jNetWorks Public API is designed for simplicity, fluency, and performance. It provides a builder-style, type-safe interface for configuring capture sessions, creating streams, applying filters, and managing parallel processing — all while hiding the complexity of high-speed backends.

The core entry point is the Net interface.

Core Classes and Interfaces

Class/Interface
Purpose

Net

Main factory and session manager. Create streams, configure capture.

PacketStream

Untyped stream of raw Packet objects. Ideal for custom processing.

ProtocolStream<T>

Typed stream delivering fully dissected protocol objects (e.g., IpDatagram, TcpSegment).

PacketStreamSettings

Optional fine-tuning (buffer sizes, memory pools, etc.).

PortFilter

Fluent interface for selecting capture interfaces.

HashType

Flow distribution strategies (3-tuple, 5-tuple, etc.).

Creating a Net Session

try (Net net = new PcapBackend()) {        // Development/testing
// try (Net net = new DpdkBackend()) {     // Production high-speed
// try (Net net = new NtapiBackend()) {    // Napatech SmartNIC

    // Your capture code here
}

The same code works across all backends — switch with a single line.

Creating Streams

Single Stream

PacketStream stream = net.createPacketStream("main");

Typed Protocol Streams

Configuring and Starting Capture

The capture builder is fully fluent:

Key Builder Methods

Method
Description

.capture(...)

Specify interfaces via PortFilter or string varargs

.filter(String bpf)

Apply libpcap-style BPF filter

.hash(HashType)

Distribute flows: HASH_3_TUPLE, HASH_5_TUPLE, etc.

.slice(int bytes)

Truncate capture to first N bytes (reduces memory bandwidth)

.pipe(PacketStream...)

Route packets to one or more streams

.pipe(ProtocolStream...)

Route directly to typed protocol streams

.onPortSelection(Consumer)

Callback when ports are selected

.apply()

Activate and return a Registration (for later cancellation)

Processing Packets

Always release packets when done:

For typed streams:

For medium-term usage, clone packets:

Structured Concurrency with TaskScope

Safely manage timeouts and parallel workers:

Next Steps

The public API is intentionally concise — most users need only a handful of methods to achieve line-rate performance.

Last updated