Пример #1
0
        private void DGVUpdate(IPDisplayPacket packet)
        {
            // Remove rows if there are too many
            if (DGV.Items.Count > _maxBuffer)
            {
                var firstItem = _displayPackets.Dequeue();
                DGV.RemoveObject(firstItem);
            }

            _displayPackets.Enqueue(packet);
            DGV.AddObject(packet);
        }
Пример #2
0
        /// <summary>
        /// This function parses the incoming packets and extracts the data based upon
        /// the protocol being carried by the IP datagram.
        /// </summary>
        /// <param name="byteData">Incoming bytes</param>
        /// <param name="nReceived">The number of bytes received</param>
        private IPDisplayPacket GetDisplayPacket(IpV4Header ipHeader)
        {
            IPDisplayPacket retVal;

            // Since all protocol packets are encapsulated in the IP datagram
            // so we start by parsing the IP header and see what protocol data
            // is being carried by it.
            // Now according to the protocol being carried by the IP datagram we parse
            // the data field of the datagram.
            switch (ipHeader.ProtocolType)
            {
            case Protocol.TCP:
            {
                TcpHeader tcpHeader = new TcpHeader(ipHeader.Data, ipHeader.MessageLength);
                retVal = new TCPDisplayPacket(ipHeader, tcpHeader);
            }
            break;

            case Protocol.UDP:
            {
                UdpHeader udpHeader = new UdpHeader(ipHeader.Data, (int)ipHeader.MessageLength);
                retVal = new UDPDisplayPacket(ipHeader, udpHeader);
            }
            break;

            case Protocol.ICMP:
            {
                IcmpHeader icmpHeader = new IcmpHeader(ipHeader.Data, (int)ipHeader.MessageLength);
                retVal = new IcmpDisplayPacket(ipHeader, icmpHeader);
            }
            break;

            case Protocol.IGMP:
            {
                IgmpHeader igmpHeader = new IgmpHeader(ipHeader.Data, (int)ipHeader.MessageLength);
                retVal = new IgmpDisplayPacket(ipHeader, igmpHeader);
            }
            break;

            case Protocol.DCCP:
            {
                DCCPHeader icmpHeader = new DCCPHeader(ipHeader.Data, (int)ipHeader.MessageLength);
                retVal = new DCCPDisplayPacket(ipHeader, icmpHeader);
            }
            break;

            case Protocol.EIGRP:
            {
                EIGRPHeader icmpHeader = new EIGRPHeader(ipHeader.Data, (int)ipHeader.MessageLength);
                retVal = new EIGRPDisplayPacket(ipHeader, icmpHeader);
            }
            break;

            case Protocol.GREs:
            {
                GREHeader icmpHeader = new GREHeader(ipHeader.Data, (int)ipHeader.MessageLength);
                retVal = new GREDisplayPacket(ipHeader, icmpHeader);
            }
            break;

            case Protocol.OSPF:
            {
                OSPFHeader icmpHeader = new OSPFHeader(ipHeader.Data, (int)ipHeader.MessageLength);
                retVal = new OSPFDisplayPacket(ipHeader, icmpHeader);
            }
            break;

            default:
            case Protocol.Unknown:
                retVal = new IPDisplayPacket(ipHeader);
                break;
            }
            return(retVal);
        }