Пример #1
0
        /// <summary>
        /// Gets one or more packets from the capture file, beginning at the specified packet index
        /// </summary>
        /// <param name="index">the index of the first record in the packet index file</param>
        /// <param name="count">the number of packets to collect</param>
        /// <returns>a new packet collection object</returns>
        public PacketCollection GetPackets(long index, int count = 1)
        {
            PacketCollection collection = new PacketCollection();

            long curr = index;

            for (int k = 0; k < count; k++)
            {
                _filestream.Seek(curr, SeekOrigin.Begin);
                byte[] header = new byte[16];
                _filestream.Read(header, 0, 16);

                DateTime time = new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(BitConverter.ToInt32(header, 0));
                time = time.AddMilliseconds(BitConverter.ToInt32(header, 4));
                int incl = BitConverter.ToInt32(header, 8);
                int orig = BitConverter.ToInt32(header, 12);

                byte[] payload = new byte[incl];
                _filestream.Read(payload, 0, incl);
                collection.AddPacket(new Packet(time, orig, payload));

                curr += incl + 16;
            }

            return(collection);
        }
Пример #2
0
 public void Merge(PacketCollection collection)
 {
     foreach (var packet in collection.Collection)
     {
         _packetCollection.Add(packet);
     }
 }
Пример #3
0
        /// <summary>
        /// Gets the amount of elapsed time between packets at index1 and index2
        /// </summary>
        /// <param name="index1">the index of the packet starting the time span</param>
        /// <param name="index2">the index of the packet concluding the time span</param>
        /// <returns>the time span as a TimeSpan object</returns>
        public TimeSpan GetTimeSpan(long index1, long index2)
        {
            PacketCollection packets = GetPackets(index1);

            packets.Merge(GetPackets(index2));

            return(packets.Collection[1].ArrivalTime.Subtract(packets.Collection[0].ArrivalTime));
        }