예제 #1
0
        /// <summary>
        /// 双击协议名称单元格时新建窗口并显示数据包详细信息
        /// </summary>
        /// <param name="index"></param>
        public static void ShowDetail(int index)
        {
            RawCapture rawCapture = null;

            try
            {
                rawCapture = queue[index];
            }
            catch (Exception)
            {
                MessageBox.Show("Error while displying details");
                return;
            }
            Packet        packet      = Packet.ParsePacket(rawCapture.LinkLayerType, rawCapture.Data);
            PacketDetials pd          = new PacketDetials(packet);
            CellDetails   cellDetails = new CellDetails();

            cellDetails.rawCapture = rawCapture;
            if (pd.ethernetPacket != null)
            {
                cellDetails.richTextBox.Text = pd.ethernetPacket.ToString(StringOutputType.VerboseColored) + Environment.NewLine + pd.ethernetPacket.PrintHex();
            }
            cellDetails.Show();
        }
예제 #2
0
        /// <summary>
        /// 收到数据包之后判断包类型
        /// 一方面放在缓存队列里,另一方面显示在主界面
        /// 异步方式防止滚动条失效
        /// </summary>
        /// <param name="rawcapture"></param>
        public void PushPacket(RawCapture rawcapture)
        {
            Packet packet = Packet.ParsePacket(rawcapture.LinkLayerType, rawcapture.Data);

            object[] para = new object[6];
            if (Common.queue.Count > Common.queueSize)
            {
                lock (Common.queue)
                {
                    Common.queue.RemoveRange(0, 100);
                    if (this.InvokeRequired)
                    {
                        lock (this)
                        {
                            this.BeginInvoke(new MethodInvoker(() =>
                            {
                                for (int i = 0; i < 100; i++)
                                {
                                    dataGridView.Rows.RemoveAt(0);
                                }
                            }));
                        }
                    }
                }

                //dataGridView.Rows.RemoveAt(0);
            }
            lock (Common.queue)
            {
                Common.queue.Add(rawcapture);
                Interlocked.Increment(ref Common.cnt);
            }
            PacketDetials pd = new PacketDetials(packet);

            //DataGridViewRow dr = new DataGridViewRow();
            if (pd.typeName == null)
            {
                return;
            }
            para[0] = Common.cnt;
            para[1] = pd.typeName;
            if (pd.typeName == "TCP" || pd.typeName == "UDP")
            {
                para[2] = pd.ipPacket.SourceAddress;
                para[3] = pd.ipPacket.DestinationAddress;
                para[4] = pd.ethernetPacket.SourceHwAddress;
                para[5] = pd.ethernetPacket.DestinationHwAddress;
            }
            else if (pd.typeName == "ARP")
            {
                para[2] = pd.arpPacket.SenderProtocolAddress;
                para[3] = pd.arpPacket.TargetProtocolAddress;
                para[4] = pd.arpPacket.SenderHardwareAddress;
                para[5] = pd.arpPacket.TargetHardwareAddress;
            }
            else if (pd.typeName == "ICMPv4")
            {
                //para[2] = para[3] = para[4] = para[5] = null;
                para[2] = pd.icmpv4Packet.BytesHighPerformance;
                para[3] = pd.icmpv4Packet.PrintHex();
                para[3] = pd.icmpv4Packet.ToString(StringOutputType.Normal);
            }
            else if (pd.typeName == "IGMPv2")
            {
                para[2] = pd.igmpv2Packet.BytesHighPerformance;
                para[3] = pd.igmpv2Packet.PrintHex();
                para[4] = pd.igmpv2Packet.ToString(StringOutputType.Normal);
            }
            if (this.InvokeRequired)
            {
                lock (this)
                {
                    this.BeginInvoke(new MethodInvoker(() =>
                    {
                        dataGridView.Rows.Add(para);
                    }), null, null);
                }
            }
            else
            {
                dataGridView.Rows.Add(para);
            }
        }