Class IcmpV6Packet
- Namespace
- VpnHood.Net.Packets
- Assembly
- VpnHood.Net.Packets.dll
Represents an ICMPv6 message (RFC 4443) over a buffer, which it reads and writes in place.
public class IcmpV6Packet : IChecksumPayloadPacket, IPayloadPacket
- Inheritance
-
IcmpV6Packet
- Implements
- Inherited Members
Remarks
Changing a field does not update the checksum: call UpdateChecksum(ReadOnlySpan<byte>, ReadOnlySpan<byte>) before sending.
Constructors
IcmpV6Packet(Memory<byte>, bool)
Initializes a new instance of the IcmpV6Packet class over a buffer, to parse a message or to build one.
public IcmpV6Packet(Memory<byte> buffer, bool building)
Parameters
bufferMemory<byte>The message's bytes, header and payload, from 8 to 65535 bytes.
buildingbooltrue to build: the 8-byte header is cleared and the payload is left as it is. false to parse the bytes as they are.
Exceptions
- ArgumentException
bufferis shorter than 8 bytes or longer than 65535.
Properties
Buffer
Gets the packet's bytes, header and payload. When the packet is an IP packet's payload, they are that packet's own bytes, not a copy, and live only as long as its memory.
public Memory<byte> Buffer { get; }
Property Value
Checksum
Gets or sets the checksum field as it is in the header.
public ushort Checksum { get; set; }
Property Value
Code
Gets or sets the message code, whose meaning depends on Type; see IcmpV6Code.
public byte Code { get; set; }
Property Value
Identifier
Gets or sets the identifier of an echo request or reply.
public ushort Identifier { get; set; }
Property Value
Remarks
For another type, the getter returns 0.
Exceptions
- InvalidOperationException
Set on a message that is not an echo request or reply.
IsEcho
Gets a value indicating whether the message is an echo request or an echo reply.
public bool IsEcho { get; }
Property Value
MessageSpecific
Gets or sets the 4 bytes after the checksum, whose meaning depends on Type: an echo's identifier and sequence number, the MTU of a "packet too big" message, or a parameter problem's pointer.
public uint MessageSpecific { get; set; }
Property Value
Payload
Gets the message's payload: the bytes after the 8-byte header, such as an echo's data or the start of the packet an error is about.
public Memory<byte> Payload { get; }
Property Value
SequenceNumber
Gets or sets the sequence number of an echo request or reply.
public ushort SequenceNumber { get; set; }
Property Value
Remarks
For another type, the getter returns 0.
Exceptions
- InvalidOperationException
Set on a message that is not an echo request or reply.
Type
Gets or sets the message type.
public IcmpV6Type Type { get; set; }
Property Value
Methods
ComputeChecksum(ReadOnlySpan<byte>, ReadOnlySpan<byte>)
Computes the checksum the message calls for, without writing it.
public ushort ComputeChecksum(ReadOnlySpan<byte> sourceAddress, ReadOnlySpan<byte> destinationAddress)
Parameters
sourceAddressReadOnlySpan<byte>The source address of the IP packet, 16 bytes.
destinationAddressReadOnlySpan<byte>The destination address of the IP packet, 16 bytes.
Returns
- ushort
The checksum, as a number to write in network byte order.
Remarks
The checksum field is zero while the sum runs and is restored after, so no other thread may use the packet meanwhile.
Exceptions
- ArgumentException
The addresses are not both 4 or both 16 bytes long.
IsChecksumValid(ReadOnlySpan<byte>, ReadOnlySpan<byte>)
Checks the checksum field against the message and the IPv6 pseudo-header.
public bool IsChecksumValid(ReadOnlySpan<byte> sourceAddress, ReadOnlySpan<byte> destinationAddress)
Parameters
sourceAddressReadOnlySpan<byte>The source address of the IP packet, 16 bytes.
destinationAddressReadOnlySpan<byte>The destination address of the IP packet, 16 bytes.
Returns
Exceptions
- ArgumentException
The addresses are not both 4 or both 16 bytes long.
ToString()
Returns a one-line description of the message for logs: its type, code and payload length, with an echo's identifier and sequence number.
public override string ToString()
Returns
- string
The description.
UpdateChecksum(ReadOnlySpan<byte>, ReadOnlySpan<byte>)
Computes the checksum and writes it to Checksum.
public void UpdateChecksum(ReadOnlySpan<byte> sourceAddress, ReadOnlySpan<byte> destinationAddress)
Parameters
sourceAddressReadOnlySpan<byte>The source address of the IP packet, 16 bytes.
destinationAddressReadOnlySpan<byte>The destination address of the IP packet, 16 bytes.
Exceptions
- ArgumentException
The addresses are not both 4 or both 16 bytes long.