Пример #1
0
        private void ParseExtensionHeaders()
        {
            if (_extensionHeaders != null)
            {
                return;
            }

            List <IpV6ExtensionHeader> extensionHeaders = new List <IpV6ExtensionHeader>();

            if (HeaderLength > RealPayloadLength)
            {
                _isValid          = false;
                _extensionHeaders = extensionHeaders.AsReadOnly();
                return;
            }
            int          extendedHeaderLength = HeaderLength;
            IpV4Protocol?nextHeader           = NextHeader;

            while (extendedHeaderLength + 8 <= RealPayloadLength && nextHeader.HasValue && IsExtensionHeader(nextHeader.Value))
            {
                int numBytesRead;
                IpV6ExtensionHeader extensionHeader = IpV6ExtensionHeader.CreateInstance(nextHeader.Value,
                                                                                         Subsegment(extendedHeaderLength, Length - extendedHeaderLength),
                                                                                         out numBytesRead);
                if (extensionHeader == null)
                {
                    break;
                }
                nextHeader            = extensionHeader.NextHeader;
                extendedHeaderLength += numBytesRead;
            }
            _isValid                = (!nextHeader.HasValue || !IsExtensionHeader(nextHeader.Value)) && (HeaderLength + _extensionHeadersLength == PayloadLength);
            _extensionHeaders       = extensionHeaders.AsReadOnly();
            _extensionHeadersLength = extendedHeaderLength - HeaderLength;
        }