/// <summary> /// </summary> /// <returns>0 for no data present, 1 if a packet was read, negative upon error</returns> private GetPacketStatus SendPacketArrivalEvent() { PacketCapture e; var retval = GetNextPacket(out e); if (retval == GetPacketStatus.PacketRead) { OnPacketArrival?.Invoke(this, e); } return(retval); }
protected void CaptureThread(CancellationToken cancellationToken) { try { while (!cancellationToken.IsCancellationRequested) { var packet = GetNextPacket(); if (packet == null) { break; } OnPacketArrival?.Invoke(this, new CaptureEventArgs(packet, this)); } OnCaptureStopped?.Invoke(this, CaptureStoppedEventStatus.CompletedWithoutError); } catch (Exception ex) { LastError = ex.Message; OnCaptureStopped?.Invoke(this, CaptureStoppedEventStatus.ErrorWhileCapturing); } }
protected void CaptureThread(CancellationToken cancellationToken) { try { while (!cancellationToken.IsCancellationRequested) { var packets = new List <PacketRecord>(WINDIVERT_BATCH_MAX); var retval = GetNextPackets(packets, WINDIVERT_BATCH_MAX); if (retval == GetPacketStatus.PacketRead) { foreach (var p in packets) { OnPacketArrival?.Invoke(this, p.GetPacketCapture(this)); } } } OnCaptureStopped?.Invoke(this, CaptureStoppedEventStatus.CompletedWithoutError); } catch (Exception ex) { LastError = ex.Message; OnCaptureStopped?.Invoke(this, CaptureStoppedEventStatus.ErrorWhileCapturing); } }
/// <summary> /// Notify the OnPacketArrival delegates about a newly captured packet /// </summary> /// <param name="p"> /// A <see cref="RawCapture"/> /// </param> protected virtual void SendPacketArrivalEvent(RawCapture p) { OnPacketArrival?.Invoke(this, new CaptureEventArgs(p, this)); }
/// <summary> /// Notify the OnPacketArrival delegates about a newly captured packet /// </summary> /// <param name="header"></param> /// <param name="data"></param> protected virtual void SendPacketArrivalEvent(PcapHeader header, Span <byte> data) { OnPacketArrival?.Invoke(this, new PacketCapture(this, header, data)); }