private void loadPcapContent(BinaryReader binaryReader, bool dontList)
        {
            PcapHeader pcapHeader = PcapHeader.read(binaryReader);

            while (binaryReader.BaseStream.Position != binaryReader.BaseStream.Length)
            {
                curPacket++;

                if (binaryReader.BaseStream.Length - binaryReader.BaseStream.Position < 16)
                {
                    //MessageBox.Show("Stream cut short (packet " + curPacket + "), stopping read: " + (binaryReader.BaseStream.Length - binaryReader.BaseStream.Position));
                    break;
                }

                PcapRecordHeader recordHeader = PcapRecordHeader.read(binaryReader);

                if (recordHeader.inclLen > 50000)
                {
                    //MessageBox.Show("Enormous packet (packet " + curPacket + "), stopping read: " + recordHeader.inclLen);
                    break;
                }

                // Make sure there's enough room for an ethernet header
                if (recordHeader.inclLen < 14)
                {
                    binaryReader.BaseStream.Position += recordHeader.inclLen;
                    continue;
                }

                if (readPacketRecordData(binaryReader, recordHeader.inclLen, recordHeader.tsSec, curPacket, dontList) == 2)
                {
                    break;
                }
            }
        }
Exemple #2
0
        private static PcapRecordHeader readPcapRecordHeader(BinaryReader binaryReader, int curPacket)
        {
            if (binaryReader.BaseStream.Length - binaryReader.BaseStream.Position < 16)
            {
                throw new InvalidDataException("Stream cut short (packet " + curPacket + "), stopping read: " +
                                               (binaryReader.BaseStream.Length - binaryReader.BaseStream.Position));
            }

            PcapRecordHeader recordHeader = PcapRecordHeader.read(binaryReader);

            if (recordHeader.inclLen > 50000)
            {
                throw new InvalidDataException("Enormous packet (packet " + curPacket + "), stopping read: " +
                                               recordHeader.inclLen);
            }

            // Make sure there's enough room for an ethernet header
            if (recordHeader.inclLen < 14)
            {
                binaryReader.BaseStream.Position += recordHeader.inclLen;
                return(null);
            }

            return(recordHeader);
        }
Exemple #3
0
        private static List <PacketRecord> loadPcapContent(BinaryReader binaryReader, ref bool abort)
        {
            List <PacketRecord> results = new List <PacketRecord>();

            /*PcapHeader pcapHeader = */
            PcapHeader.read(binaryReader);

            int curPacket = 0;

            while (binaryReader.BaseStream.Position != binaryReader.BaseStream.Length)
            {
                if (abort)
                {
                    break;
                }

                curPacket++;

                if (binaryReader.BaseStream.Length - binaryReader.BaseStream.Position < 16)
                {
                    //MessageBox.Show("Stream cut short (packet " + curPacket + "), stopping read: " + (binaryReader.BaseStream.Length - binaryReader.BaseStream.Position));
                    break;
                }

                PcapRecordHeader recordHeader = PcapRecordHeader.read(binaryReader);

                if (recordHeader.inclLen > 50000)
                {
                    //MessageBox.Show("Enormous packet (packet " + curPacket + "), stopping read: " + recordHeader.inclLen);
                    break;
                }

                // Make sure there's enough room for an ethernet header
                if (recordHeader.inclLen < 14)
                {
                    binaryReader.BaseStream.Position += recordHeader.inclLen;
                    continue;
                }

                var packetRecord = readPacketRecordData(binaryReader, recordHeader.inclLen, recordHeader.tsSec, curPacket);

                if (packetRecord == null)
                {
                    break;
                }

                results.Add(packetRecord);
            }

            return(results);
        }