public void Performance() { captureFilename = capturePre + captureFN; // open the offline file var dev = new CaptureFileReaderDevice(captureFilename); dev.Open(); Assert.True(dev != null, "failed to open " + captureFilename); TcpStream tcpStream = new TcpStream(); int i = 1; // to match the packet numbering in wireshark RawCapture rawCapture; const int packetsToAppend = 100000; while ((rawCapture = dev.GetNextPacket()) != null) { var p = Packet.ParsePacket(rawCapture.LinkLayerType, rawCapture.Data); var tcpPacket = p.Extract <TcpPacket>(); for (int x = 0; x < packetsToAppend; x++) { tcpStream.AppendPacket(tcpPacket); // advance to the next packet tcpStream.AdvanceToNextPacket(); tcpStream = tcpStream.TrimUnusedPackets(); } i++; } dev.Close(); }
public void TestAdvanceToNextPacketandTrimUnusedPackets() { captureFilename = capturePre + captureFN; // open the offline file var dev = new CaptureFileReaderDevice(captureFilename); dev.Open(); Assert.True(dev != null, "failed to open " + captureFilename); TcpStream tcpStream = new TcpStream(); int i = 1; // to match the packet numbering in wireshark PacketCapture e; GetPacketStatus status; while ((status = dev.GetNextPacket(out e)) == GetPacketStatus.PacketRead) { var rawCapture = e.GetPacket(); var p = Packet.ParsePacket(rawCapture.LinkLayerType, rawCapture.Data); var tcpPacket = p.Extract <TcpPacket>(); tcpStream.AppendPacket(tcpPacket); i++; } dev.Close(); long expected_position; // verify our position is 0 expected_position = 0; Assert.Equal(expected_position, tcpStream.Position); // advance to the next packet tcpStream.AdvanceToNextPacket(); // is our current position correct expected_position = 38; Assert.Equal(expected_position, tcpStream.Position); // test that if we advance to the next packet and no packet is available that // we will end up at the end of the stream tcpStream.AdvanceToNextPacket(); Assert.True(tcpStream.Position == tcpStream.Length, "stream position and length don't match"); // now trim any unused packets tcpStream = tcpStream.TrimUnusedPackets(); }