Oakrey.Network.Abstractions
2.0.3
dotnet add package Oakrey.Network.Abstractions --version 2.0.3
NuGet\Install-Package Oakrey.Network.Abstractions -Version 2.0.3
<PackageReference Include="Oakrey.Network.Abstractions" Version="2.0.3" />
<PackageVersion Include="Oakrey.Network.Abstractions" Version="2.0.3" />
<PackageReference Include="Oakrey.Network.Abstractions" />
paket add Oakrey.Network.Abstractions --version 2.0.3
#r "nuget: Oakrey.Network.Abstractions, 2.0.3"
#:package Oakrey.Network.Abstractions@2.0.3
#addin nuget:?package=Oakrey.Network.Abstractions&version=2.0.3
#tool nuget:?package=Oakrey.Network.Abstractions&version=2.0.3
Oakrey.Network.Abstractions
A .NET library providing foundational abstractions for parsing and working with raw network packets. It covers the Ethernet, network (IPv4/IPv6), and transport (TCP/UDP) layers through a layered class hierarchy, and exposes strongly-typed protocol enumerations, address range types, and byte-level formatting utilities.
The library is used as a shared contract layer across other Oakrey.Network.* packages.
Features
Packet header parsing
| Class | Layer | Key members |
|---|---|---|
MacPacketHead |
Ethernet (L2) | Source, Destination, Type (EtherType), IsIPv4, IsIPv6 |
IPv4PacketHead |
Network (L3) | Source, Destination, Protocol, TTL, DSCP, ECN, FragmentOffset, HeaderChecksum, TotalLength |
IPv6PacketHead |
Network (L3) | Source, Destination, Protocol, HopLimit, FlowLabel, PayloadLength |
TcpHeader |
Transport (L4) | SourcePort, DestinationPort, Seq, Ack, WindowSize, Flags, Checksum |
UdpHeader |
Transport (L4) | SourcePort, DestinationPort, Length, Checksum |
Layer abstractions
PacketDescriptionBase
NetworkLayerBase (IAddress, IpProtocol)
IPv4PacketHead
IPv6PacketHead
TransportLayerBase (IPorts)
TcpHeader
UdpHeader
MacPacketHead (IAddress)
Protocol enumerations
EtherType- full IEEE-assigned EtherType registry (IPv4, IPv6, ARP, VLAN, MPLS, PPPoE, and more).IpProtocol- full IANA IP protocol number registry (ICMP, TCP, UDP, IGMP, GRE, OSPF, and more).IPType- IP version discriminator.FlagsEnum- TCP flag bits (SYN, ACK, FIN, RST, PSH, URG).
Address and range types
IpAddressRange- defines a scannable IPv4 address range (three fixed octets + start/stop for the last octet). Constructors accept octet values,System.Net.IPAddress, or a"x.x.x.start-stop"string.IpAddressRangeViewModel-INotifyPropertyChangedwrapper overIpAddressRangefor WPF/MVVM binding.IAddress- common interface exposingSourceandDestinationstrings.IPorts- common interface exposingSourcePortandDestinationPort.
Raw packet interface
IRawPacket represents a captured frame with:
Data- raw byte array.LinkLayerType-PacketDotNet.LinkLayersvalue.TimeValue- capture timestamp.GetPayload()/GetPayloadString()- helpers to extract the application payload beyond the standard 74-byte header.
Utilities
Formatter- extension methods onbyte[]for reading MAC addresses, IPv4/IPv6 addresses,uint16/uint32values (big-endian), andEtherType.TimeValue- lightweight struct (seconds+microseconds) matching thepcaptimestamp layout, with aTimeSpanconversion.
Architecture
classDiagram
class IRawPacket {
+byte[] Data
+LinkLayers LinkLayerType
+TimeValue TimeValue
+GetPayload() byte[]
+GetPayloadString() string
}
class PacketDescriptionBase {
+byte[] Payload
+int PayloadSize
+TimeValue TimeStamp
+int TotalPacketSize
#byte[] header
#int HeaderSize
}
class MacPacketHead {
+string Source
+string Destination
+EtherType Type
+bool IsIPv4
+bool IsIPv6
}
class NetworkLayerBase {
+string Source
+string Destination
+IpProtocol Protocol
}
class IPv4PacketHead {
+byte TTL
+byte DSCP
+byte ECN
+short FragmentOffset
+uint HeaderChecksum
}
class IPv6PacketHead {
+byte HopLimit
+byte NextHeader
+uint PayloadLength
+byte[] FlowLabel
}
class TransportLayerBase {
+ushort SourcePort
+ushort DestinationPort
}
class TcpHeader {
+uint Seq
+uint Ack
+ushort WindowSize
+FlagsEnum Flags
+ushort Checksum
}
class UdpHeader {
+ushort Length
+ushort Checksum
}
PacketDescriptionBase <|-- MacPacketHead
PacketDescriptionBase <|-- NetworkLayerBase
PacketDescriptionBase <|-- TransportLayerBase
NetworkLayerBase <|-- IPv4PacketHead
NetworkLayerBase <|-- IPv6PacketHead
TransportLayerBase <|-- TcpHeader
TransportLayerBase <|-- UdpHeader
IRawPacket --> MacPacketHead : parsed by
Requirements
- .NET 10 or higher
Installation
NuGet Package Manager
- Open Visual Studio.
- Go to Tools > NuGet Package Manager > Manage NuGet Packages for Solution.
- Search for
Oakrey.Network.Abstractionsand click Install.
.NET CLI
dotnet add package Oakrey.Network.Abstractions
Package Manager Console
Install-Package Oakrey.Network.Abstractions
Example usage
The typical usage pattern is to parse a raw captured frame layer by layer.
// rawPacket implements IRawPacket (e.g. from Oakrey.Network.PacketCapture)
MacPacketHead mac = new(rawPacket);
Console.WriteLine(mac); // src: AA:BB:CC:DD:EE:FF -> dst: 11:22:33:44:55:66 (IPv4)
if (mac.IsIPv4)
{
IPv4PacketHead ipv4 = new(mac);
Console.WriteLine(ipv4); // src: 192.168.1.1 -> dst: 192.168.1.2 (TCP)
if (ipv4.Protocol == IpProtocol.TCP)
{
TcpHeader tcp = new(ipv4);
Console.WriteLine(tcp); // src: 54321 -> dst: 80 (seq=..., ack=..., flags=ACK)
byte[] payload = tcp.Payload;
}
else if (ipv4.Protocol == IpProtocol.UDP)
{
UdpHeader udp = new(ipv4);
Console.WriteLine(udp); // src: 5353 -> dst: 5353 (length=...)
}
}
Scanning an IPv4 address range:
// Scan 192.168.1.1 - 192.168.1.254
IpAddressRange range = new(ipPart3: 192, ipPart2: 168, ipPart1: 1, ipPart0Start: 1, ipPart0Stop: 254);
// Or construct from a string
IpAddressRange range2 = new("192.168.1.1-254");
// Or from an existing address (last octet becomes 0-255)
IpAddressRange range3 = new(IPAddress.Parse("192.168.1.100"));
Development notes
- All header classes read directly from the raw
byte[]without copying. Parsing is zero-allocation beyond the header slice. Formatterextension methods handle big-endian byte order as used on the wire.TimeValueis a blittable struct compatible with thepcap/npcaptimestamp layout.IpAddressRangeViewModeldepends on WPF viaINotifyPropertyChanged; avoid using it in non-UI projects.
License
MIT - Copyright (c) Oakrey 2016-present
- Repository: Azure DevOps
- NuGet: Oakrey.Network.Abstractions
6. Contributing
Contributions are welcome! Feel free to open issues or submit pull requests to improve the package.
7. License
This project is licensed under the MIT License. See the LICENSE file for details.
| 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
- Oakrey.BitArray (>= 3.0.0)
- PacketDotNet (>= 1.4.8)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Oakrey.Network.Abstractions:
| Package | Downloads |
|---|---|
|
Oakrey.Network.IpScanner
Asynchronous IPv4 network scanner that pings an IpAddressRange and exposes discovered devices as IObservable<NetworkDeviceInfo>. Uses ICMP (System.Net.NetworkInformation.Ping) with configurable timeout, reports scan progress via IObservable<int> (remaining pings), and resolves each live host to its IP address, MAC address, hostname, and device type. Depends on Oakrey.Network.Abstractions and Oakrey.Network.Tools. |
|
|
Oakrey.Network.PacketCapture.Wrapper
A managed .NET wrapper for WinPcap/Npcap on Windows. Exposes packet capture, Berkeley Packet Filter (BPF) compilation, queue-based transmission, device configuration, and capture statistics via P/Invoke. |
GitHub repositories
This package is not used by any popular GitHub repositories.