Example #1
0
        /// <summary>
        ///		Log a new UDP packet.
        /// </summary>
        /// <param name="packet">
        ///		The packet to log.
        ///	</param>
        public void LogPacket(UdpPacket packet)
        {
            lock (m_logger.XmlWriter)
            {
                // <UdpHeader>
                m_logger.XmlWriter.WriteStartElement ("UdpHeader");

                    m_logger.XmlWriter.WriteElementString ("SourcePort",		packet.SourcePort.ToString());
                    m_logger.XmlWriter.WriteElementString ("DestinationPort",	packet.DestinationPort.ToString());
                    m_logger.XmlWriter.WriteElementString ("Checksum",			packet.Checksum.ToString());

                    // <LengthFields>
                    m_logger.XmlWriter.WriteStartElement ("UdpLengthFields");

                        int dataLength = (packet.Data != null ? packet.Data.Length : 0);

                        m_logger.XmlWriter.WriteElementString ("TotalLength",	packet.Length + " bytes");
                        m_logger.XmlWriter.WriteElementString ("HeaderLength",	(packet.Length - dataLength) + " bytes");
                        m_logger.XmlWriter.WriteElementString ("DataLength",	dataLength + " bytes");
                    m_logger.XmlWriter.WriteEndElement ();
                    // </LengthFields>

                m_logger.XmlWriter.WriteEndElement ();
                // </UdpHeader>

            }
        }
Example #2
0
		/// <summary>
		///		Whenever a new UDP packet arrives it should be passed to this method.
		///		If the packet is to be filtered out it will be ignored otherwise the
		///		UdpPacketArrived will be raised with the packet
		/// </summary>
		/// <param name="packet">
		///		The packet which has arrived.
		///	</param>
		public void HandleNewPacket(UdpPacket packet)
		{
			bool match = true;
		
			// check the source port filter
			foreach (string filter in m_sourcePortFilter)
			{
				if (!UdpFilter.IsMatch (packet.SourcePort, filter))
				{
					match = false;
					break;
				}
			}
			
			// if no match then exit
			if (!match)
			{
				return;
			}
			
			// check the destination port filter
			foreach (string filter in m_destPortFilter)
			{
				if (!UdpFilter.IsMatch (packet.DestinationPort, filter))
				{
					match = false;
					break;
				}
			}
			
			// if no match then exit
			if (!match)
			{
				return;
			}
			
			// if we get here then the packet has passed through the filter and we
			// raise the event
			if (UdpPacketArrived != null)
			{
				UdpPacketArrived (packet);
			}
			
		}