Example #1
0
        private TreeNode MakeIPTreeNode(IPHeader ipHeader)
        {
            TreeNode ipNode = new TreeNode();

            ipNode.Text = "IP";
            ipNode.Nodes.Add("Ver: " + ipHeader.Version);
            ipNode.Nodes.Add("Header Length: " + ipHeader.HeaderLength);
            ipNode.Nodes.Add("Differntiated Services: " + ipHeader.DifferentiatedServices);
            ipNode.Nodes.Add("Total Length: " + ipHeader.TotalLength);
            ipNode.Nodes.Add("Identification: " + ipHeader.Identification);
            ipNode.Nodes.Add("Flags: " + ipHeader.Flags);
            ipNode.Nodes.Add("Fragmentation Offset: " + ipHeader.FragmentationOffset);
            ipNode.Nodes.Add("Time to live: " + ipHeader.TTL);
            switch (ipHeader.ProtocolType)
            {
            case Protocol.TCP:
                ipNode.Nodes.Add("Protocol: " + "TCP");
                break;

            case Protocol.UDP:
                ipNode.Nodes.Add("Protocol: " + "UDP");
                break;

            case Protocol.Unknown:
                ipNode.Nodes.Add("Protocol: " + "Unknown");
                break;
            }
            ipNode.Nodes.Add("Checksum: " + ipHeader.Checksum);
            ipNode.Nodes.Add("Source: " + ipHeader.SourceAddress.ToString());
            ipNode.Nodes.Add("Destination: " + ipHeader.DestinationAddress.ToString());

            return(ipNode);
        }
Example #2
0
        private string Parse(byte[] buf, int len)
        {
            IPHeader ipHeader = new IPHeader(buf, len);

            return(string.Format("\n\n+---------------------------------------------+\n" +
                                 "|From: {0}\tTo: {1}\n" +
                                 "|Protocol: {3}\tLength: {2}\n" +
                                 "+---------------------------------------------+\n",
                                 ipHeader.SourceAddress,
                                 ipHeader.DestinationAddress,
                                 ipHeader.TotalLength,
                                 ipHeader.ProtocolType.ToString()));
        }
Example #3
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 });
        }
Example #4
0
 private string Parse(byte[] buf, int len)
 {
     IPHeader ipHeader = new IPHeader(buf,len);
     return string.Format("\n\n+---------------------------------------------+\n" +
                          "|From: {0}\tTo: {1}\n" +
                          "|Protocol: {3}\tLength: {2}\n" +
                          "+---------------------------------------------+\n",
                          ipHeader.SourceAddress,
                          ipHeader.DestinationAddress,
                          ipHeader.TotalLength,
                          ipHeader.ProtocolType.ToString());
 }