private void ParseExtensionHeaders() { if (_extensionHeaders != null) { return; } if (Length < HeaderLength) { _isValidExtensionHeaders = false; _extensionHeaders = IpV6ExtensionHeaders.Empty; return; } _extensionHeaders = new IpV6ExtensionHeaders(Subsegment(HeaderLength, RealPayloadLength), NextHeader); _isValidExtensionHeaders = _isValidExtensionHeaders && _extensionHeaders.IsValid; }
/// <summary> /// True iff all the extension headers are equal to the given extension headers instance. /// </summary> public bool Equals(IpV6ExtensionHeaders other) { return(other != null && this.SequenceEqual(other)); }
internal static void WriteHeader(byte[] buffer, int offset, byte trafficClass, int flowLabel, ushort payloadLength, IpV4Protocol?nextHeader, IpV4Protocol?nextLayerProtocol, byte hopLimit, IpV6Address source, IpV6Address currentDestination, IpV6ExtensionHeaders extensionHeaders) { buffer.Write(offset + Offset.Version, (uint)((((DefaultVersion << 8) | trafficClass) << 20) | flowLabel), Endianity.Big); buffer.Write(offset + Offset.PayloadLength, payloadLength, Endianity.Big); IpV4Protocol actualNextHeader; if (nextHeader.HasValue) { actualNextHeader = nextHeader.Value; } else if (extensionHeaders.Any()) { actualNextHeader = extensionHeaders.FirstHeader.Value; } else if (nextLayerProtocol.HasValue) { actualNextHeader = nextLayerProtocol.Value; } else { throw new InvalidOperationException("Can't determine next header. No extension headers and no known next layer protocol."); } buffer.Write(offset + Offset.NextHeader, (byte)actualNextHeader); buffer.Write(offset + Offset.HopLimit, hopLimit); buffer.Write(offset + Offset.SourceAddress, source, Endianity.Big); buffer.Write(offset + Offset.DestinationAddress, currentDestination, Endianity.Big); extensionHeaders.Write(buffer, offset + HeaderLength, nextLayerProtocol); }