private void Build_Tree_View(TreeNode rootNode, FMTP_Parser.FMPT_Header_and_Data FMTP_Data, string Source, string Destination) { TreeNode fmtpNode = MakeFMTPTreeNode(FMTP_Data); rootNode.Nodes.Add(fmtpNode); AddTreeNode addTreeNode = new AddTreeNode(OnAddTreeNode); string Date_Time = DateTime.Now.ToShortDateString() + " / " + DateTime.Now.ToLongTimeString(); rootNode.Text = Date_Time + ": " + Source + " -> " + Destination; //Thread safe adding of the nodes treeView.Invoke(addTreeNode, new object[] { rootNode }); }
//Helper function which returns the information contained in the TCP header as a //tree node private TreeNode MakeFMTPTreeNode(FMTP_Parser.FMPT_Header_and_Data FMPT_Data) { TreeNode tcpNode = new TreeNode(); tcpNode.Text = "OLDI"; if (Properties.Settings.Default.Msg_Version) { tcpNode.Nodes.Add("Msg Version: " + FMPT_Data.version); } if (Properties.Settings.Default.Msg_Length) { tcpNode.Nodes.Add("Msg Length: " + FMPT_Data.msg_length + " bytes"); } if (Properties.Settings.Default.Msg_Type) { tcpNode.Nodes.Add("Msg Type: " + FMPT_Data.msg_type); } if (Properties.Settings.Default.Msg_Content) { tcpNode.Nodes.Add("Msg Content: " + FMPT_Data.msg_content); } return(tcpNode); }
// Parses incomming message, determines IP version and then if the // message is operational forwards it to Etic batch mode that will // then forward messages the specified destination private void ParseAndForwardData(byte[] byteData, int nReceived) { TreeNode rootNode = new TreeNode(); Common_Header_Data ipHeader = new Common_Header_Data(); IPHeader_IPV4 ipHeader_IPV4; if (!Is_IPV6) { ipHeader_IPV4 = new IPHeader_IPV4(byteData, nReceived); ipHeader.Data = ipHeader_IPV4.Data; ipHeader.DestinationAddress = ipHeader_IPV4.DestinationAddress; ipHeader.SourceAddress = ipHeader_IPV4.SourceAddress; ipHeader.ProtocolType = ipHeader_IPV4.ProtocolType; ipHeader.MessageLength = ipHeader_IPV4.MessageLength; } else { // In .NET for IPV6 no header data is provided // so we just take in TCP part. ipHeader.Data = byteData; ipHeader.MessageLength = (ushort)nReceived; ipHeader.ProtocolType = Protocol.TCP; } // Only process TCP if (ipHeader.ProtocolType == Protocol.TCP) { TCPHeader tcpHeader = new TCPHeader(ipHeader.Data, //IPHeader.Data stores the data being carried by the IP datagram ipHeader.MessageLength); //Length of the data field // Make sure the data is belongs to the FMTP specifed port (usually 8500) if (tcpHeader.SourcePort == Properties.Settings.Default.SourcePort || tcpHeader.DestinationPort == Properties.Settings.Default.SourcePort) { // Parse the data in order to determine data validity and message type // { Operational, Operator, Identification, System } FMTP_Parser.FMPT_Header_and_Data FMTP_Data = FMTP_Parser.FMTP_Msg_Parser(tcpHeader.Data); if (FMTP_Data.Valid_FMTP_Data) { string Source; string Destination; if (tcpHeader.SourcePort == Properties.Settings.Default.SourcePort) { Source = Properties.Settings.Default.Sender; Destination = Properties.Settings.Default.Receiver; } else { Destination = Properties.Settings.Default.Sender; Source = Properties.Settings.Default.Receiver; } switch (FMTP_Data.msg_type) { case FMTP_Parser.FMPT_Header_and_Data.Message_Type.Operational: bool Filter_By_Sender_Passed = true; // Check if fiter by sender name is enabled if (this.checkBoxFilterBySender.Checked) { if (OLDI_Decoder.Sender_Name(FMTP_Data.msg_content) != Properties.Settings.Default.Sender) { Filter_By_Sender_Passed = false; } } if (Filter_By_Sender_Passed) { // Check if Auto forward to ETIC is requested if (this.radioButtonClient.Checked && (Source == Properties.Settings.Default.Receiver)) { ETIC_Forwarder.Forward_To_ETIC_Operational_Msg(FMTP_Data.msg_content); } else if (this.radioButtonServer.Checked && Source == Properties.Settings.Default.Sender) { ETIC_Forwarder.Forward_To_ETIC_Operational_Msg(FMTP_Data.msg_content); } } if (Properties.Settings.Default.Show_Operational) { Build_Tree_View(rootNode, FMTP_Data, Source, Destination); } break; case FMTP_Parser.FMPT_Header_and_Data.Message_Type.Identification: if (Properties.Settings.Default.Show_Identification) { Build_Tree_View(rootNode, FMTP_Data, Source, Destination); } break; case FMTP_Parser.FMPT_Header_and_Data.Message_Type.Operator: if (Properties.Settings.Default.Show_Operator) { Build_Tree_View(rootNode, FMTP_Data, Source, Destination); } break; case FMTP_Parser.FMPT_Header_and_Data.Message_Type.System: if (Properties.Settings.Default.Show_System) { Build_Tree_View(rootNode, FMTP_Data, Source, Destination); } break; } } } } }