protected IEnumerable <Frame> GetFramesFromPcapWithoutDefragmentation(String pcapFileName) { var frames = new List <Frame>(); foreach (var(packet, timestampTicks) in this.GetPacketsFromPcap(pcapFileName)) { var frame = FrameFactory.CreateFromPacket(packet, timestampTicks); frames.Add(frame); } return(frames); }
public void Frame1() { var frames = this.GetPacketsFromPcap(TestPcapFile.IsaHttpRetransmission).ToList(); var(packet, timestampTicks) = frames[5]; var frame = FrameFactory.CreateFromPacket(packet, timestampTicks); Assert.Equal(60, frame.Data.Length); Assert.Equal(0, frame.L7PayloadDataSegmentLength); Assert.True(frame.TcpFAck); Assert.Equal(3594821724, frame.TcpSequenceNumber); }
// TODO extract to project protected IEnumerable <Frame> GetFramesFromPcap(Uri pcapUri) { var frames = new List <Frame>(); var pcapLoader = this._services.GetService <IPcapLoader>(); using (pcapLoader) { RawCapture rawCapture; pcapLoader.Open(pcapUri); while ((rawCapture = pcapLoader.GetNextPacket()) != null) { var packet = Packet.ParsePacket(pcapLoader.LinkType, rawCapture.Data); var frame = FrameFactory.CreateFromPacket(packet, rawCapture.Timeval.Date.Ticks); frames.Add(frame); } } return(frames); }
private void OnRawPacketBatchRequest(RawPacketBatchRequest rawPacketBatchRequest) { var ack = new RawPacketBatchAck { MessageId = rawPacketBatchRequest.MessageId }; this.Contractor.Tell(ack); try { foreach (var rawPacket in rawPacketBatchRequest.RawPackets) { if (rawPacket.RawPacketData == null) { this._logger.Error("RawPacket has no packet data"); continue; } var parsedPacket = Packet.ParsePacket(rawPacket.LinkType, rawPacket.RawPacketData); if (!(parsedPacket.PayloadPacket is IPPacket)) { //this._logger.Debug("Ignoring non-IP packet"); continue; } var frame = FrameFactory.CreateFromPacket(parsedPacket, rawPacket.DateTimeTicks); if (frame.IsValidTransportPacket || frame.IsIpv4Fragmented) { this.CaptureTrackingActor.Tell(frame); } //else //TODO ALL NON TCP or UDP traffic //{ // this._logger.Error($"Frame is invalid: {frame}"); //} } } catch (Exception e) { this._logger.Error(e, "Exception during Raw packet parsing."); } }
private void OnRawPacketBatchRequest(RawPacketBatchRequest rawPacketBatchRequest) { var ack = new RawPacketBatchAck { MessageId = rawPacketBatchRequest.MessageId }; this.Contractor.Tell(ack); foreach (var rawPacket in rawPacketBatchRequest.RawPackets) { if (rawPacket.RawPacketData == null) { this._logger.Error("RawPacket has no packet data"); continue; } try { var parsedPacket = Packet.ParsePacket(rawPacket.LinkType, rawPacket.RawPacketData); if (!(parsedPacket.PayloadPacket is IPPacket)) { //this._logger.Debug("Ignoring non-IP packet"); continue; } var frame = FrameFactory.CreateFromPacket(parsedPacket, rawPacket.DateTimeTicks); if (frame.IsValidTransportPacket || frame.IsIpv4Fragmented) { this.CaptureTrackingActor.Tell(frame); } } catch (Exception e) { this._logger.Error(e, $"Parsing of a raw packet ({rawPacket}) caused exception."); } } }