Exemple #1
0
		private int lexCompare(Service that)
		{
			sbyte[] thisBytes = this.toByteArray();
			sbyte[] thatBytes = that.toByteArray();
			for (int i = 0, n = Math.Min(thisBytes.Length, thatBytes.Length); i < n; i++)
			{
				if (thisBytes[i] > thatBytes[i])
				{
					return 1;
				}
				else if (thisBytes[i] < thatBytes[i])
				{
					return - 1;
				}
			}
			return thisBytes.Length - thatBytes.Length;
		}
Exemple #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;
			}
		}