コード例 #1
0
ファイル: PacketParser.cs プロジェクト: thanhltd/sniffer
        /// <summary>
        /// Update ctrl with packet information
        /// Increment frame_id by one
        /// </summary>
        /// <param name="packet">The packet to handle</param>
        /// <param name="frame_id">The frame id, for UI display</param>
        /// <param name="ctrl">The control to display information</param>
        public static void HandlePacket(Packet packet, ref UInt64 frame_id, object[] ctrl)
        {
            EthernetDatagram ethernet = packet.Ethernet;

            if (ethernet == null)
            {
                return;
            }

            switch (ethernet.EtherType)
            {
            case EthernetType.IpV4: {
                IpV4Datagram ip = ethernet.IpV4;
                IPParser.HandleIPV4(packet, ip, ref frame_id, ctrl);
                break;
            }

            case EthernetType.Arp: {
                ArpDatagram arp = ethernet.Arp;
                ArpParser.HandleARP(packet, arp, ref frame_id, ctrl);
                break;
            }

            default:
                break;
            }
        }
コード例 #2
0
ファイル: PacketParser.cs プロジェクト: thanhltd/sniffer
        /// <summary>
        /// Packet parser dispatcher
        /// </summary>
        /// <param name="packet">The packet to be parsed</param>
        /// <param name="ctrl">Contorls to update details with</param>
        public static void ParsePacket(Packet packet, object[] ctrl)
        {
            if (packet == null || ctrl == null ||
                ctrl[0] == null || ctrl[1] == null)
            {
                return;
            }

            EthernetDatagram ethernet = packet.Ethernet;

            List <ListViewItem> items = new List <ListViewItem>();
            ListViewItem        item  = new ListViewItem("Ethernet");
            string estr = "Etype = " + ethernet.EtherType;

            estr += ", DestinationAddress = " + ethernet.Destination;
            estr += ", SourceAddress = " + ethernet.Source;
            item.SubItems.Add(estr);
            items.Add(item);

            ListView f_details = (ListView)ctrl[0];

            f_details.Items.Clear();

            object[] param = new object[2];
            param[0] = f_details;
            param[1] = items;
            f_details.BeginInvoke(new ParserHelper.UIHandler(ParserHelper.UpdateDetailsUI), param);

            switch (ethernet.EtherType)
            {
            case EthernetType.IpV4: {
                IpV4Datagram ip = ethernet.IpV4;
                IPParser.ParseIPPacket(ip, ctrl);
                break;
            }

            case EthernetType.Arp: {
                ArpDatagram arp = ethernet.Arp;
                ArpParser.ParseARPPacket(arp, ctrl);
                break;
            }

            default:
                break;
            }


            // Save packet for layed analyze
            SnifferMain.packet = packet;
        }