Exemplo n.º 1
0
 public override string ToString()
 {
     // TODO this is a mess
     return(toString((text.Length > 10)?new String(SupportClass.ToCharArray(text), 0, 7) + "...":new String(SupportClass.ToCharArray(text))));
 }
Exemplo n.º 2
0
		/// <summary> Parse a message from a datagram packet.</summary>
		internal DNSIncoming(SupportClass.PacketSupport packet)
		{
			this.packet = packet;
			this.data = SupportClass.ToSByteArray(packet.Data);
			this.len = packet.Length;
			// TODO: will this always be 0 in .NET??
			this.off = 0;
			this.questions = ArrayList.ReadOnly(new ArrayList());
			this.answers = ArrayList.ReadOnly(new ArrayList());
			this.receivedTime = (DateTime.Now.Ticks - 621355968000000000) / 10000;
			
			try
			{
				id = ReadUnsignedShort();
				flags = ReadUnsignedShort();
				numQuestions = ReadUnsignedShort();
				numAnswers = ReadUnsignedShort();
				numAuthorities = ReadUnsignedShort();
				numAdditionals = ReadUnsignedShort();
				
				// parse questions
				if (numQuestions > 0)
				{
					questions = ArrayList.Synchronized(new ArrayList(numQuestions));
					for (int i = 0; i < numQuestions; i++)
					{
						DNSQuestion question = new DNSQuestion(ReadName(), ReadUnsignedShort(), ReadUnsignedShort());
						questions.Add(question);
					}
				}
				
				// parse answers
				int n = numAnswers + numAuthorities + numAdditionals;
				if (n > 0)
				{
					answers = ArrayList.Synchronized(new ArrayList(n));
					for (int i = 0; i < n; i++)
					{
						string domain = ReadName();
						int type = ReadUnsignedShort();
						int clazz = ReadUnsignedShort();
						int ttl = ReadInt();
						int len = ReadUnsignedShort();
						int end = off + len;
						DNSRecord rec = null;
						
						switch (type)
						{
							
							case DNSConstants.TYPE_A: 
							// IPv4
							case DNSConstants.TYPE_AAAA:  // IPv6 FIXME [PJYF Oct 14 2004] This has not been tested
								rec = new Address(domain, type, clazz, ttl, ReadBytes(off, len));
								break;
							
							case DNSConstants.TYPE_CNAME: 
							case DNSConstants.TYPE_PTR: 
								rec = new Pointer(domain, type, clazz, ttl, ReadName());
								break;
							
							case DNSConstants.TYPE_TXT: 
								rec = new Text(domain, type, clazz, ttl, ReadBytes(off, len));
								break;
							
							case DNSConstants.TYPE_SRV: 
								rec = new Service(domain, type, clazz, ttl, ReadUnsignedShort(), ReadUnsignedShort(), ReadUnsignedShort(), ReadName());
								break;
							
							case DNSConstants.TYPE_HINFO: 
								// Maybe we should do something with those
								break;
							
							default: 
								logger.Debug("DNSIncoming() unknown type:" + type);
								break;
							
						}
						
						if (rec != null)
						{
							// Add a record, if we were able to create one.
							answers.Add(rec);
						}
						else
						{
							// Addjust the numbers for the skipped record
							if (answers.Count < numAnswers)
							{
								numAnswers--;
							}
							else if (answers.Count < numAnswers + numAuthorities)
							{
								numAuthorities--;
							}
							else if (answers.Count < numAnswers + numAuthorities + numAdditionals)
							{
								numAdditionals--;
							}
						}
						off = end;
					}
				}
			}
			catch (IOException e)
			{
				logger.Warn("DNSIncoming() dump " + Print(true) + "\n exception ", e);
				throw e;
			}
		}
Exemplo n.º 3
0
		internal virtual bool ShouldIgnorePacket(SupportClass.PacketSupport packet)
		{
			bool result = false;
			if (Address != null)
			{
				IPAddress from = packet.Address;
				if (from != null)
				{
					// TODO: how to replace this?
//					if (from.isLinkLocalAddress() && (!Address.isLinkLocalAddress()))
//					{
//						// Ignore linklocal packets on regular interfaces, unless this is
//						// also a linklocal interface. This is to avoid duplicates. This is
//						// a terrible hack caused by the lack of an API to get the address
//						// of the interface on which the packet was received.
//						result = true;
//					}
					if (IPAddress.IsLoopback(from) && (!IPAddress.IsLoopback(Address)))
					{
						// Ignore loopback packets on a regular interface unless this is
						// also a loopback interface.
						result = true;
					}
				}
			}
			return result;
		}
Exemplo n.º 4
0
        /// <summary> Parse a message from a datagram packet.</summary>
        internal DNSIncoming(SupportClass.PacketSupport packet)
        {
            this.packet = packet;
            this.data   = SupportClass.ToSByteArray(packet.Data);
            this.len    = packet.Length;
            // TODO: will this always be 0 in .NET??
            this.off          = 0;
            this.questions    = ArrayList.ReadOnly(new ArrayList());
            this.answers      = ArrayList.ReadOnly(new ArrayList());
            this.receivedTime = (DateTime.Now.Ticks - 621355968000000000) / 10000;

            try
            {
                id             = ReadUnsignedShort();
                flags          = ReadUnsignedShort();
                numQuestions   = ReadUnsignedShort();
                numAnswers     = ReadUnsignedShort();
                numAuthorities = ReadUnsignedShort();
                numAdditionals = ReadUnsignedShort();

                // parse questions
                if (numQuestions > 0)
                {
                    questions = ArrayList.Synchronized(new ArrayList(numQuestions));
                    for (int i = 0; i < numQuestions; i++)
                    {
                        DNSQuestion question = new DNSQuestion(ReadName(), ReadUnsignedShort(), ReadUnsignedShort());
                        questions.Add(question);
                    }
                }

                // parse answers
                int n = numAnswers + numAuthorities + numAdditionals;
                if (n > 0)
                {
                    answers = ArrayList.Synchronized(new ArrayList(n));
                    for (int i = 0; i < n; i++)
                    {
                        string    domain = ReadName();
                        int       type   = ReadUnsignedShort();
                        int       clazz  = ReadUnsignedShort();
                        int       ttl    = ReadInt();
                        int       len    = ReadUnsignedShort();
                        int       end    = off + len;
                        DNSRecord rec    = null;

                        switch (type)
                        {
                        case DNSConstants.TYPE_A:
                        // IPv4
                        case DNSConstants.TYPE_AAAA:                                  // IPv6 FIXME [PJYF Oct 14 2004] This has not been tested
                            rec = new Address(domain, type, clazz, ttl, ReadBytes(off, len));
                            break;

                        case DNSConstants.TYPE_CNAME:
                        case DNSConstants.TYPE_PTR:
                            rec = new Pointer(domain, type, clazz, ttl, ReadName());
                            break;

                        case DNSConstants.TYPE_TXT:
                            rec = new Text(domain, type, clazz, ttl, ReadBytes(off, len));
                            break;

                        case DNSConstants.TYPE_SRV:
                            rec = new Service(domain, type, clazz, ttl, ReadUnsignedShort(), ReadUnsignedShort(), ReadUnsignedShort(), ReadName());
                            break;

                        case DNSConstants.TYPE_HINFO:
                            // Maybe we should do something with those
                            break;

                        default:
                            logger.Debug("DNSIncoming() unknown type:" + type);
                            break;
                        }

                        if (rec != null)
                        {
                            // Add a record, if we were able to create one.
                            answers.Add(rec);
                        }
                        else
                        {
                            // Addjust the numbers for the skipped record
                            if (answers.Count < numAnswers)
                            {
                                numAnswers--;
                            }
                            else if (answers.Count < numAnswers + numAuthorities)
                            {
                                numAuthorities--;
                            }
                            else if (answers.Count < numAnswers + numAuthorities + numAdditionals)
                            {
                                numAdditionals--;
                            }
                        }
                        off = end;
                    }
                }
            }
            catch (IOException e)
            {
                logger.Warn("DNSIncoming() dump " + Print(true) + "\n exception ", e);
                throw e;
            }
        }