Beispiel #1
0
        protected virtual PacketsSet<T> GetPacketsSet(CapturedPacket packet)
        {
            var sourceDestination = new SourceDestination
            {
                IPSource = packet.IPSource,
                PortSource = packet.Source.Port,
                IPDestination = packet.IPDestination,
                PortDestination = packet.Destination.Port
            };

            if (packetsBytes.TryGetValue(sourceDestination, out PacketsSet<T> packetsSet))
            {
                return packetsSet;
            }

            packetsSet = new PacketsSet<T>();

            packetsBytes.Add(sourceDestination, packetsSet);

            return packetsSet;
        }
Beispiel #2
0
        protected virtual IList<CapturedPacket> ExtractPackets(CapturedPacket packet, PacketsSet<T> packetsSet)
        {
            var packets = new List<CapturedPacket>();
            var packetLength = 0;
            var offset = 0;

            if (!IsStartingPacket(packet.Bytes))
            {
                var lengthToComplete = packetsSet.GetLengthToCompletePacket();

                if (lengthToComplete == 0 ||
                    lengthToComplete >= packet.Bytes.Length)
                {
                    packets.Add(packet);
                    return packets;
                }

                var additionalPacket = packet.Bytes.Skip(lengthToComplete).ToArray();

                if (IsStartingPacket(additionalPacket))
                {
                    packetLength = lengthToComplete;
                }
            }
            else if ((packetLength = ReadPacketLength(packet.Bytes)) >= packet.Bytes.Length || packetLength == 0)
            {
                packets.Add(packet);
                return packets;
            }

            var sequenceNumber = packet.SequenceNumber;

            while (offset < packet.Bytes.Length)
            {
                var bytes = packet.Bytes.Skip(offset).ToArray();

                if (offset != 0)
                {
                    if (!IsStartingPacket(bytes))
                    {
                        break;
                    }

                    packetLength = ReadPacketLength(bytes);
                }

                var subPacket = new CapturedPacket
                {
                    Bytes = bytes.Take(packetLength).ToArray(),
                    CreatedTimeStamp = packet.CreatedTimeStamp,
                    Destination = packet.Destination,
                    SequenceNumber = sequenceNumber++,
                    Source = packet.Source
                };

                packets.Add(subPacket);

                offset += packetLength;

                if (packetLength == 0)
                {
                    break;
                }
            }

            return packets;
        }