예제 #1
0
        private TreeNode MakeUDPTreeNode(UDPHeader udpHeader)
        {
            TreeNode udpNode = new TreeNode();

            udpNode.Text = "UDP";
            udpNode.Nodes.Add("Source Port: " + udpHeader.SourcePort);
            udpNode.Nodes.Add("Destination Port: " + udpHeader.DestinationPort);
            udpNode.Nodes.Add("Length: " + udpHeader.Length);
            udpNode.Nodes.Add("Checksum: " + udpHeader.Checksum);

            return(udpNode);
        }
예제 #2
0
        private void ParseData(byte[] byteData, int nReceived)
        {
            TreeNode rootNode = new TreeNode();

            IPHeader ipHeader = new IPHeader(byteData, nReceived);

            TreeNode ipNode = MakeIPTreeNode(ipHeader);

            rootNode.Nodes.Add(ipNode);

            switch (ipHeader.ProtocolType)
            {
            case Protocol.TCP:
                if (Filter.tcp != true)
                {
                    return;
                }

                TCPHeader tcpHeader = new TCPHeader(ipHeader.Data, ipHeader.MessageLength);

                TreeNode tcpNode = MakeTCPTreeNode(tcpHeader);

                rootNode.Nodes.Add(tcpNode);

                if (tcpHeader.DestinationPort == "53" || tcpHeader.SourcePort == "53")
                {
                    TreeNode dnsNode = MakeDNSTreeNode(tcpHeader.Data, (int)tcpHeader.MessageLength);
                    rootNode.Nodes.Add(dnsNode);
                }

                HeaderCounter.tcp++;
                break;

            case Protocol.UDP:
                if (Filter.udp != true)
                {
                    return;
                }
                UDPHeader udpHeader = new UDPHeader(ipHeader.Data, (int)ipHeader.MessageLength);

                TreeNode udpNode = MakeUDPTreeNode(udpHeader);

                rootNode.Nodes.Add(udpNode);

                if (udpHeader.DestinationPort == "53" || udpHeader.SourcePort == "53")
                {
                    if (Filter.dns != true)
                    {
                        return;
                    }

                    TreeNode dnsNode = MakeDNSTreeNode(udpHeader.Data,
                                                       Convert.ToInt32(udpHeader.Length) - 8);
                    rootNode.Nodes.Add(dnsNode);

                    HeaderCounter.dns++;
                }

                HeaderCounter.udp++;
                break;

            case Protocol.Unknown:
                if (Filter.unknown != true)
                {
                    return;
                }
                HeaderCounter.unknown++;
                break;
            }

            displayCounter();

            AddTreeNode addTreeNode = new AddTreeNode(OnAddTreeNode);

            rootNode.Text = ipHeader.SourceAddress.ToString() + "-" +
                            ipHeader.DestinationAddress.ToString();

            treeView.Invoke(addTreeNode, new object[] { rootNode });
        }