Table of Contents

Class ChecksumUtils

Namespace
VpnHood.Net.Packets
Assembly
VpnHood.Net.Packets.dll

Provides the Internet checksum (RFC 1071), vectorized where the processor allows.

public static class ChecksumUtils
Inheritance
ChecksumUtils
Inherited Members

Methods

ComputeChecksum(ReadOnlySpan<byte>)

Computes the Internet checksum of some bytes: the complement of the ones' complement sum of their 16-bit words.

public static ushort ComputeChecksum(ReadOnlySpan<byte> data)

Parameters

data ReadOnlySpan<byte>

The bytes to sum, with any checksum field among them zero.

Returns

ushort

The checksum, as a number to write in network byte order.

Remarks

Over bytes that already hold a valid checksum it returns zero.

ComputeChecksum(ReadOnlySpan<byte>, ReadOnlySpan<byte>)

Computes the Internet checksum of a pseudo-header followed by some bytes, as if the two were one buffer.

public static ushort ComputeChecksum(ReadOnlySpan<byte> pseudoHeader, ReadOnlySpan<byte> data)

Parameters

pseudoHeader ReadOnlySpan<byte>

The bytes summed first, such as an IP pseudo-header; may be empty or odd in length.

data ReadOnlySpan<byte>

The bytes summed after them, with any checksum field among them zero.

Returns

ushort

The checksum, as a number to write in network byte order.

Remarks

A computed zero is returned as it is; UDP's rule to send it as 0xFFFF is ComputeChecksum(ReadOnlySpan<byte>, ReadOnlySpan<byte>)'s.