Ejemplo n.º 1
0
        public static InterfaceStatisticsBlock 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.InterfaceStatistics, "Invalid packet type");

            long positionInStream = baseBlock.PositionInStream;

            using (Stream stream = new MemoryStream(baseBlock.Body))
            {
                using (BinaryReader binaryReader = new BinaryReader(stream))
                {
                    int    interfaceID = binaryReader.ReadInt32().ReverseByteOrder(baseBlock.ReverseByteOrder);
                    byte[] timestamp   = binaryReader.ReadBytes(8);
                    if (timestamp.Length < 8)
                    {
                        throw new EndOfStreamException("Unable to read beyond the end of the stream");
                    }
                    TimestampHelper           timestampHelper = new TimestampHelper(timestamp, baseBlock.ReverseByteOrder);
                    InterfaceStatisticsOption options         = InterfaceStatisticsOption.Parse(binaryReader, baseBlock.ReverseByteOrder, ActionOnException);
                    InterfaceStatisticsBlock  statisticBlock  = new InterfaceStatisticsBlock(interfaceID, timestampHelper, options, positionInStream);
                    return(statisticBlock);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The Interface Statistics Block contains the capture statistics for a given interface and it is optional. The statistics are referred
        /// to the interface defined in the current Section identified by the Interface ID field. An Interface Statistics Block is normally
        /// placed at the end of the file, but no assumptions can be taken about its position - it can even appear multiple times for the same
        /// interface.
        /// </summary>
        public InterfaceStatisticsBlock(int InterfaceID, TimestampHelper Timestamp, InterfaceStatisticsOption Options, long PositionInStream = 0)
        {
            //Contract.Requires<ArgumentNullException>(Timestamp != null, "Timestamp cannot be null");
            //Contract.Requires<ArgumentNullException>(Options != null, "Options cannot be null");

            this.InterfaceID      = InterfaceID;
            this.Timestamp        = Timestamp;
            this.options          = Options;
            this.PositionInStream = PositionInStream;
        }