Ejemplo n.º 1
0
 /// <summary>
 /// Delivers the SniffedPacketAvailable event.
 /// </summary>
 /// <param name="e">Class containing information about the packet being received.</param>
 public void OnSniffedPacketAvailable(SniffedPacketEventArgs e)
 {
     if (this.PacketAvailable != null)
     {
         this.PacketAvailable(this, e);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// This method receives all the packets with their origin and decides what to do (if collapse them or not) following the <c>IsCollapsingSameOrigin</c> property.
 /// </summary>
 /// <param name="origin">Where the packet comes from.</param>
 /// <param name="packet">Byte array forming the packet.</param>
 private void ManagePacket(Origin origin, byte[] packet)
 {
     if (this.IsCollapsingSameOrigin)
     {
         if (this.lastOrigin == Origin.Undefined)
         {
             this.bytesArrivedSameOrigin = new List <byte>();
             this.lastOrigin             = origin;
         }
         else
         {
             if (origin == this.lastOrigin)
             {
                 this.bytesArrivedSameOrigin.AddRange(packet);
             }
             else
             {
                 SniffedPacketEventArgs eventArgs = new SniffedPacketEventArgs(DateTime.Now, this.lastOrigin, this.bytesArrivedSameOrigin);
                 this.OnSniffedPacketAvailable(eventArgs);
                 this.bytesArrivedSameOrigin.Clear();
                 this.bytesArrivedSameOrigin.AddRange(packet);
                 this.lastOrigin = origin;
             }
         }
     }
     else
     {
         SniffedPacketEventArgs eventArgs = new SniffedPacketEventArgs(DateTime.Now, origin, packet);
         this.OnSniffedPacketAvailable(eventArgs);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Computes a string that shows a decoded version of the sniffed packet.
        /// </summary>
        /// <param name="e">Argument object containing the packed to be decoded.</param>
        /// <param name="start">Start time when the packet has been sniffed. This time is reliable when the <see cref="GlobalParameters.IsShowCollapsed"/> is false. When
        /// it is true, it should be considered that the packet could be composed of strings of characters loaded non contiguously.</param>
        /// <returns>>The decoded version of the sniffed packet.</returns>
        public static string DecodeArrivedPacket(SniffedPacketEventArgs e, DateTime start)
        {
            string preamble;

            if (GlobalParameters.IsShowTime)
            {
                preamble = string.Format(
                    "{0:yyyy-MM-dd HH mm ss.fff} {1} ",
                    e.When,
                    e.Origin == Origin.FromReal ? '<' : '>');
            }
            else
            {
                preamble = string.Format(
                    System.Globalization.CultureInfo.InvariantCulture,
                    "{0,10:0.000} {1} ",
                    e.When.Subtract(start).TotalMilliseconds,
                    e.Origin == Origin.FromReal ? '<' : '>');
            }

            return(e.Content.ToHex(preamble, GlobalParameters.OutputFormat, GlobalParameters.BytesPerLine));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Delivers the SniffedPacketAvailable event.
 /// </summary>
 /// <param name="e">Class containing information about the packet being received.</param>
 public void OnSniffedPacketAvailable(SniffedPacketEventArgs e)
 {
     this.PacketAvailable?.Invoke(this, e);
 }