NetworkInspector.Sources
0.17.0
dotnet add package NetworkInspector.Sources --version 0.17.0
NuGet\Install-Package NetworkInspector.Sources -Version 0.17.0
<PackageReference Include="NetworkInspector.Sources" Version="0.17.0" />
<PackageVersion Include="NetworkInspector.Sources" Version="0.17.0" />
<PackageReference Include="NetworkInspector.Sources" />
paket add NetworkInspector.Sources --version 0.17.0
#r "nuget: NetworkInspector.Sources, 0.17.0"
#:package NetworkInspector.Sources@0.17.0
#addin nuget:?package=NetworkInspector.Sources&version=0.17.0
#tool nuget:?package=NetworkInspector.Sources&version=0.17.0
NetworkInspector.Sources
Read capture files fast and safely: PCAP, PCAPNG, Vector BLF, and Vector ASC, from a file with random access or
from any stream. Every source produces the same Frame values (bytes, timestamp, link type, interface) for the
NetworkInspector parser, exporters, and sessions.
Highlights
- Four formats, one interface.
IFrameSource.NextFrame()works the same for PCAP, PCAPNG, BLF, and ASC. - Millions of frames per second. Up to 7.5 M frames/s from a stream and 3.7 M frames/s from a memory-mapped file (measurements below).
- Opens instantly. For PCAPNG and BLF a lazy scan reads only the header on
Open; the frame index grows while you read. - Random access while reading.
FrameByIdis thread-safe and works during the lazy scan. - Large files. Small files are loaded into memory and served as zero-copy slices; larger files are memory mapped; files above 2 GiB are scanned in windows.
- Hardened against hostile input. Malformed records are skipped or stop the read (your choice) and are always reported. BLF containers are checked against a decompression-bomb limit before allocation.
- Bus details preserved. CAN DLC 9–15, the LIN protected identifier, PCAPNG interface options, and unknown
link types survive a read → write round trip with
NetworkInspector.Exporters. - No native dependencies. Fully managed; the parser stack (
NetworkInspector.Protocols) is not required.
Install
dotnet add package NetworkInspector.Sources
To parse the frames into packets, add the dissectors:
dotnet add package NetworkInspector.Protocols
Quick Start
Read Frames
using NetworkInspector.Core;
using NetworkInspector.Sources.Pcapng;
using PcapngSource source = PcapngSource.Open("capture.pcapng"); // PCAPNG and legacy PCAP
// Every source registers its interfaces in a registry before the first frame.
FrameInterfaceRegistry registry = new();
source.Start(registry.RegisterSource(source), registry);
while (source.NextFrame() is { } frame)
{
Console.WriteLine($"{frame.Timestamp} {frame.LinkType} {frame.Data.Length} bytes");
}
Open throws for a missing file (FileNotFoundException), an unreadable file (IOException), or an invalid
header (PcapException, BlfException). Problems inside the file are handled by the error tolerance mode.
Read And Parse Every Frame
using NetworkInspector.Core;
using NetworkInspector.Core.Ids;
using NetworkInspector.Core.Settings;
using NetworkInspector.Protocols;
using NetworkInspector.Sources.Pcapng;
// The source must be started with the registry the stack was built with.
FrameInterfaceRegistry registry = new();
StackBuilder builder = new(new SettingsManager(), registry);
builder.RegisterStandardProtocols();
using Stack stack = builder.Build();
using PcapngSource source = PcapngSource.Open("capture.pcapng");
source.Start(registry.RegisterSource(source), registry);
// First-parse packet ids must be dense (0, 1, 2, ...): advance only on success.
ParseOptions options = new();
int nextId = 0;
while (source.NextFrame() is { } frame)
{
if (!Packet.TryParse(new PacketId(nextId), stack, frame, in options, out Packet? packet, out ParseFailure failure)
|| packet is null)
{
Console.Error.WriteLine($"frame {frame.Id.Value}: {failure}");
continue;
}
nextId++;
Console.WriteLine($"#{packet.Id.Value} {packet.Info}");
}
Read From A Stream
using NetworkInspector.Core;
using NetworkInspector.Sources.Asc;
using FileStream fileStream = File.OpenRead("trace.asc");
using AscStreamSource source = AscStreamSource.FromStream(fileStream, "ASC stream", leaveOpen: true);
FrameInterfaceRegistry registry = new();
source.Start(registry.RegisterSource(source), registry);
while (source.NextFrame() is { } frame)
{
// Hand the frame to the parser or an exporter.
}
Choose A Source
| Need | Source |
|---|---|
| File with random access by frame id | PcapngSource, BlfSource, AscSource |
| Forward-only stream (network, pipe, archive entry) | PcapngStreamSource, BlfStreamSource, AscStreamSource |
| Synthetic test traffic | RandomFrameSource (NetworkInspector.Sources.Random) |
| Random access over a stream source | CachedFrameSource (NetworkInspector.Sources.Cached) |
Namespaces: NetworkInspector.Sources.Pcapng, .Blf, .Asc, .Random, .Cached. All file sources also offer
FromData(...) for captures already in memory. There is no live capture from network interfaces.
Common Tasks
Use Random Access
PcapngSource, BlfSource, AscSource, RandomFrameSource, and CachedFrameSource implement FrameById. It is
thread-safe and may run while another thread reads sequentially, also during a lazy scan: it returns the frame for
every id the scan has indexed and null for ids not reached yet. From a preloaded file it returns a zero-copy
slice; from a memory-mapped file it copies the frame into its own array.
Configure Large BLF Files
BLF log containers are decompressed into memory. Bound the peak with BlfSourceOptions:
using NetworkInspector.Sources.Blf;
BlfSourceOptions options = new()
{
// Reject containers larger than 128 MiB before allocation (default).
// Set to 0 only when you trust the capture source.
MaxUncompressedContainerSize = BlfSourceOptions.DefaultMaxUncompressedContainerSize,
// Limit simultaneous decompressions (default: ProcessorCount).
MaxDecompressionConcurrency = 2,
// Memory-map instead of preloading files larger than 64 MiB (default: 256 MiB on 64-bit).
PreloadBudget = 64L * 1024 * 1024,
// Bound the 2Q container cache (default: 32 MiB).
CacheBudget = 16 * 1024 * 1024,
};
using BlfSource source = BlfSource.Open("bus.blf", options);
For streams, pass the same options to BlfStreamSource.FromStream(stream, options: options). File-only members
(scan mode, preload, cache) are ignored there.
Read Vector Files With Local Time
The BLF start date and ASC header dates have no time zone. They are read as UTC by default
(BlfSourceOptions.TimestampTimeZone, AscSourceOptions.TimestampTimeZone). Vector tools write local civil time:
set TimeZoneInfo.Local, or the recording zone, for files from those tools.
Choose The Error Tolerance
ErrorTolerance on every options class selects the behavior for malformed records:
ErrorToleranceMode.Tolerant(default): skip the record, raiseFrameSkipped, continue.ErrorToleranceMode.Strict: return the frames in front of the first error, then stop.FrameSkippedis still raised, in file order.
Reduce Allocations With Frame Slabs
FrameSlabSize (on PcapngSourceOptions, BlfSourceOptions, AscSourceOptions; default 0 = off) groups the
bytes of sequentially read frames into shared slabs of 1 KiB to 16 MiB. Frames above a quarter of the slab keep
their own array. Fewer, larger allocations help most when the consumer keeps the frames; the cost is retention:
one held frame keeps its whole slab alive. Preloaded files already serve zero-copy slices, so slabs only affect
memory-mapped and stream reading.
Measured on 50 000 PCAPNG frames with 64 KiB slabs (NetworkInspector.Profiling scenarios read-pcapng-*;
"mapped" with PreloadBudget = null):
| Path | Off | 64 KiB slabs |
|---|---|---|
| mapped, frames dropped | 3.55 M/s | 3.72 M/s |
| mapped, frames held | 2.09 M/s | 2.40 M/s |
| stream, frames dropped | 6.3 M/s | 7.55 M/s |
| stream, frames held | 2.55 M/s | 3.45 M/s |
Format Notes
- PCAP / PCAPNG: frames expose the captured bytes (
Frame.Length/Frame.Data); the on-wire original length is not kept. A DLT outside theLinkTypeenum is passed through as its raw number. IDBif_namebecomes the interfaceUiName(an unusable name falls back toInterface {n}),if_descriptionitsDescription; the optionsif_hardware,if_os,if_speed,if_txspeed,if_rxspeed,if_filter,if_fcslenbecome interface properties (if.*). Legacy PCAP records are bounded by the snaplen; a record cut by the end of the file raisesTruncatedStream. A section holds at most 65 536 interfaces. - BLF: frames are produced for classic CAN, CAN FD, CAN XL (Type 139), LIN, FlexRay, and Ethernet Types 71,
102, and 120–123. Ethernet status and PHY objects (103/133) and AppText are metadata; AppText channel names
become interface names. Objects that cannot be read raise
FrameSkipped. - ASC: CAN, CAN FD, CAN XL, LIN, FlexRay, and Ethernet (
ETH, AFDX data).ETH STAT,ETH RxEr, AFDX status, and AFDX bus statistics are not frames. ASC always scans the full file on open. - Streams:
PcapngStreamSourceandBlfStreamSourcewrap a stream that is neither aMemoryStreamnor aBufferedStreamin a 64 KiBBufferedStream.AscStreamSourcereads 4 MiB chunks into its own buffer. - A file larger than
Array.MaxLengthis never preloaded, even withPreloadBudget = long.MaxValue.
Limits And Thread-Safety Notes
NextFrameis single-consumer: call it from one thread.FrameByIdand the statistics may be used from any thread.CachedFrameSourcekeeps the innerFrameand does not copy payload bytes; if the inner mapping is released, its frames'Datais no longer valid. It rejects a random-access inner source unlessallowRandomAccessInner: trueis passed.- Use stream sources or preload budgets to bound memory for very large captures.
Safe Usage (STRIDE)
- Spoofing: File names and extensions can mislead; the readers validate magic numbers and headers.
- Tampering: Malformed headers and partial records are expected input; handle
FrameSkipped. - Repudiation: Keep source metadata when downstream workflows need traceability.
- Information disclosure: Captures can contain secrets; protect them like the traffic they record.
- Denial of service: Keep the BLF container limit, bound preload and cache budgets, and use cancellation.
- Elevation of privilege: Run readers with least-required file-system permissions.
Learn More
- Source guide: backends, lazy scan, frame slabs, error tolerance, threading, volatile fields
- Exporters · Sessions · Core · Root overview
- GitHub repository · Issue tracker
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- NetworkInspector.Core (>= 0.17.0)
- ZeroAlloc (>= 0.6.2)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on NetworkInspector.Sources:
| Package | Downloads |
|---|---|
|
NetworkInspector.Sessions
Session orchestration for NetworkInspector. Coordinates frame sources, protocol stack parsing, pull-based listeners, and background jobs. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.17.0 | 43 | 10/17/2026 |
| 0.16.0 | 43 | 10/17/2026 |
| 0.15.0 | 89 | 10/9/2026 |
| 0.14.0 | 89 | 10/8/2026 |
| 0.13.0 | 113 | 9/27/2026 |
| 0.12.0 | 123 | 9/17/2026 |
| 0.11.0 | 151 | 9/10/2026 |
| 0.10.0 | 122 | 9/8/2026 |
| 0.9.0 | 116 | 9/2/2026 |
| 0.8.0 | 159 | 8/28/2026 |
| 0.7.0 | 122 | 8/27/2026 |
| 0.6.0 | 143 | 8/21/2026 |
| 0.5.0 | 148 | 7/11/2026 |
| 0.4.0 | 173 | 6/2/2026 |
| 0.3.0 | 146 | 5/21/2026 |
| 0.2.0 | 132 | 5/19/2026 |