private TreeNode MakeTCPTreeNode(TCPHeader tcpHeader) { TreeNode tcpNode = new TreeNode(); tcpNode.Text = "TCP"; tcpNode.Nodes.Add("Source Port: " + tcpHeader.SourcePort); tcpNode.Nodes.Add("Destination Port: " + tcpHeader.DestinationPort); tcpNode.Nodes.Add("Sequence Number: " + tcpHeader.SequenceNumber); if (tcpHeader.AcknowledgementNumber != "") { tcpNode.Nodes.Add("Acknowledgement Number: " + tcpHeader.AcknowledgementNumber); } tcpNode.Nodes.Add("Header Length: " + tcpHeader.HeaderLength); tcpNode.Nodes.Add("Flags: " + tcpHeader.Flags); tcpNode.Nodes.Add("Window Size: " + tcpHeader.WindowSize); tcpNode.Nodes.Add("Checksum: " + tcpHeader.Checksum); if (tcpHeader.UrgentPointer != "") { tcpNode.Nodes.Add("Urgent Pointer: " + tcpHeader.UrgentPointer); } return(tcpNode); }
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 }); }