VpnHood.Net.Packets 9.1.874

dotnet add package VpnHood.Net.Packets --version 9.1.874
                    
NuGet\Install-Package VpnHood.Net.Packets -Version 9.1.874
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="VpnHood.Net.Packets" Version="9.1.874" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="VpnHood.Net.Packets" Version="9.1.874" />
                    
Directory.Packages.props
<PackageReference Include="VpnHood.Net.Packets" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add VpnHood.Net.Packets --version 9.1.874
                    
#r "nuget: VpnHood.Net.Packets, 9.1.874"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package VpnHood.Net.Packets@9.1.874
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=VpnHood.Net.Packets&version=9.1.874
                    
Install as a Cake Addin
#tool nuget:?package=VpnHood.Net.Packets&version=9.1.874
                    
Install as a Cake Tool

VpnHood.Net.Packets

A fast, low-allocation IP packet library for .NET: parse and build IPv4, IPv6, TCP, UDP, ICMPv4 and ICMPv6 packets in place, and compute their Internet checksums with SIMD. It is the packet layer of VpnHood, and works on its own for any .NET app that reads or writes raw packets: a TUN device, a raw socket, a capture file.

dotnet add package VpnHood.Net.Packets

How it works

  • A packet is a view over its bytes: IpV4Packet, IpV6Packet, TcpPacket, UdpPacket and the ICMP packets read and write the buffer in place, with no copy.
  • SourceAddressValue and DestinationAddressValue read a packet's addresses as IpAddressValues, with no object made, for code that runs per packet; SourceAddress and DestinationAddress make an IPAddress on first read and keep it.
  • PacketBuilder parses packets and builds new ones in memory rented from a pool. Dispose a packet to return its memory.
  • A packet is made on a PacketMemory. A Memory<byte>, an array or an ArraySegment<byte> converts to one you keep; one made from an IMemoryOwner<byte>, or with PacketMemory.FromRentedArray, gives the packet that memory, which it returns when disposed. A rented array needs no owner object.
  • BuildIp, BuildUdp, BuildTcp, BuildIcmpV4, BuildIcmpV6 and BuildDns compute no checksum: call UpdateAllChecksums() before sending. The echo, reset and ICMP error builders compute them unless told not to.
  • A fragment's TCP, UDP or ICMPv6 checksum covers its whole datagram, so UpdateAllChecksums() leaves it as it is. After changing a fragment's address, UpdatePayloadChecksum(oldAddress, newAddress) brings it in line from the change alone.
  • An IPv6 packet reads through its Hop-by-Hop, Destination Options, Fragment and Authentication headers to the upper layer.

Quick start

Each example below runs as a test in CI (PacketsReadmeExampleTest.cs). Their namespaces are System.Net, VpnHood.Net.Packets, VpnHood.Net.Packets.Extensions and VpnHood.Net.Toolkit.Net.

Build a UDP packet

using var ipPacket = PacketBuilder.BuildUdp(
    new IPEndPoint(IPAddress.Parse("10.0.0.2"), 5353),
    new IPEndPoint(IPAddress.Parse("10.0.0.1"), 53),
    "hello"u8);

ipPacket.UpdateAllChecksums(); // BuildUdp computes no checksum itself
var bytes = ipPacket.Buffer; // the packet's own bytes, ready for a TUN device

Parse a packet

// Parse copies the received bytes into pooled memory; PacketBuilder.Attach would read them in place
using var ipPacket = PacketBuilder.Parse(received);
Console.WriteLine($"{ipPacket.SourceAddress} -> {ipPacket.DestinationAddress}, {ipPacket.Protocol}");

if (ipPacket.Protocol == IpProtocol.Udp && !ipPacket.IsFragment) {
    var udp = ipPacket.ExtractUdp(); // a view over the packet's bytes, not a copy
    Console.WriteLine($"UDP {udp.SourcePort} -> {udp.DestinationPort}, {udp.Payload.Length} bytes, " +
                      $"checksum valid: {udp.IsChecksumValid(ipPacket)}");
}

Answer a ping

using var request = PacketBuilder.BuildIcmpEchoRequest(
    IPAddress.Parse("10.0.0.2"), IPAddress.Parse("10.0.0.1"), "ping"u8,
    identifier: 1, sequenceNumber: 1); // checksums computed

// answer it as a host would: swap the addresses, keep the identifier, sequence number and data
var echo = request.ExtractIcmpV4();
using var reply = PacketBuilder.BuildIcmpEchoReply(
    request.DestinationAddress, request.SourceAddress, echo.Payload.Span,
    echo.Identifier, echo.SequenceNumber);

License

LGPL-2.1-only. See the VpnHood repository.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on VpnHood.Net.Packets:

Package Downloads
VpnHood.Core.Tunneling

The tunnel between a VpnHood client and server, which both share: its requests, channels and streams, and the forwarding of a session's packets.

VpnHood.Core.Filtering.DomainFiltering

Domain filtering at the packet level, by the server name in each TLS connection's SNI.

VpnHood.Net.PacketTransports

Two-way channels of IP packets: send queues, batching, and a fair queue that keeps a flooding flow from starving the others.

VpnHood.Net.TcpStack.Abstractions

The interfaces of VpnHood's user-space TCP stack, for code that takes a stack without depending on VpnHood.Net.TcpStack.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
9.1.874 0 11/15/2026
9.1.864 253 11/3/2026
9.0.860 268 10/31/2026
9.0.859.16-prerelease 226 10/30/2026
9.0.857 273 10/20/2026
9.0.856 259 10/19/2026
9.0.855 260 10/13/2026
8.2.853.11-prerelease 241 10/5/2026
8.2.853 285 9/23/2026
8.2.852 257 9/23/2026