Пример #1
0
        /// <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);
        }
Пример #2
0
 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);
     }
 }
Пример #3
0
 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);
     }
 }
Пример #4
0
 /// <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));
 }
Пример #5
0
 /// <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));
 }