コード例 #1
0
        public static SectionHeaderBlock Parse(BaseBlock baseBlock, Action <Exception> ActionOnException)
        {
            Contract.Requires <ArgumentNullException>(baseBlock != null, "BaseBlock cannot be null");
            Contract.Requires <ArgumentNullException>(baseBlock.Body != null, "BaseBlock.Body cannot be null");
            Contract.Requires <ArgumentException>(baseBlock.BlockType == BaseBlock.Types.SectionHeader, "Invalid packet type");

            long positionInStream = baseBlock.PositionInStream;

            using (Stream stream = new MemoryStream(baseBlock.Body))
            {
                using (BinaryReader binaryReader = new BinaryReader(stream))
                {
                    uint tempMagicNumber = binaryReader.ReadUInt32().ReverseByteOrder(baseBlock.ReverseByteOrder);

                    if (!Enum.IsDefined(typeof(MagicNumbers), tempMagicNumber))
                    {
                        throw new ArgumentException(string.Format("[SectionHeaderBlock.Parse] Unrecognized pcapNG magic number: {0}", tempMagicNumber.ToString("x")));
                    }

                    MagicNumbers        magicNumber   = (MagicNumbers)tempMagicNumber;
                    ushort              majorVersion  = binaryReader.ReadUInt16().ReverseByteOrder(baseBlock.ReverseByteOrder);
                    ushort              minorVersion  = binaryReader.ReadUInt16().ReverseByteOrder(baseBlock.ReverseByteOrder);
                    long                sectionLength = binaryReader.ReadInt64().ReverseByteOrder(baseBlock.ReverseByteOrder);
                    SectionHeaderOption options       = SectionHeaderOption.Parse(binaryReader, baseBlock.ReverseByteOrder, ActionOnException);
                    SectionHeaderBlock  headerBlock   = new SectionHeaderBlock(magicNumber, majorVersion, minorVersion, sectionLength, options, positionInStream);
                    return(headerBlock);
                }
            }
        }
コード例 #2
0
        public static SectionHeaderBlock GetEmptyHeader(bool ReverseByteOrder)
        {
            Assembly            assembly     = Assembly.GetExecutingAssembly();
            AssemblyName        assemblyName = assembly.GetName();
            string              app          = string.Format("{0} {1}", assemblyName.Name, assemblyName.Version.ToString());
            SectionHeaderOption options      = new SectionHeaderOption(UserApplication: app);

            return(new SectionHeaderBlock(ReverseByteOrder ? MagicNumbers.Swapped : MagicNumbers.Identical, 1, 0, -1, options));
        }
コード例 #3
0
        /// <summary>
        /// The Section Header Block is mandatory. It identifies the beginning of a section of the capture dump file. The Section Header Block
        /// does not contain data but it rather identifies a list of blocks (interfaces, packets) that are logically correlated.
        /// </summary>
        public SectionHeaderBlock(MagicNumbers MagicNumber, UInt16 MajorVersion, UInt16 MinorVersion, Int64 SectionLength, SectionHeaderOption Options, long PositionInStream = 0)
        {
            Contract.Requires <ArgumentNullException>(Options != null, "Options cannot be null");

            this.MagicNumber      = MagicNumber;
            this.MajorVersion     = MajorVersion;
            this.MinorVersion     = MinorVersion;
            this.SectionLength    = SectionLength;
            this.options          = Options;
            this.PositionInStream = PositionInStream;
        }