示例#1
0
 /// <summary>
 /// Constructs a NS record by reading bytes from a return message
 /// </summary>
 /// <param name="pointer">A logical pointer to the bytes holding the record</param>
 internal SRVRecord(Pointer pointer)
 {
     _Priority = pointer.ReadShort();
        _Weight = pointer.ReadShort();
        _Port = pointer.ReadShort();
        _Target = pointer.ReadDomain();
 }
示例#2
0
文件: SRVRecord.cs 项目: bwail/xmpp
 /// <summary>
 /// Constructs a NS record by reading bytes from a return message
 /// </summary>
 /// <param name="pointer">A logical pointer to the bytes holding the record</param>
 internal SRVRecord(Pointer pointer)
 {
     _priority = pointer.ReadShort();
     _weight = pointer.ReadShort();
     _port = pointer.ReadShort();
     _target = pointer.ReadDomain();
 }
示例#3
0
文件: ANameRecord.cs 项目: bwail/xmpp
        /// <summary>
        /// Constructs an ANAME record by reading bytes from a return message
        /// </summary>
        /// <param name="pointer">A logical pointer to the bytes holding the record</param>
        internal ANameRecord(Pointer pointer)
        {
            byte b1 = pointer.ReadByte();
            byte b2 = pointer.ReadByte();
            byte b3 = pointer.ReadByte();
            byte b4 = pointer.ReadByte();

            // this next line's not brilliant - couldn't find a better way though
            _ipAddress = IPAddress.Parse(string.Format("{0}.{1}.{2}.{3}", b1, b2, b3, b4));
        }
示例#4
0
文件: Response.cs 项目: bwail/xmpp
        /// <summary>
        /// Construct a Response object from the supplied byte array
        /// </summary>
        /// <param name="message">a byte array returned from a DNS server query</param>
        internal Response(byte[] message)
        {
            // the bit flags are in bytes 2 and 3
            var flags1 = message[2];
            var flags2 = message[3];

            // get return code from lowest 4 bits of byte 3
            var returnCode = flags2 & 15;

            // if its in the reserved section, set to other
            if (returnCode > 6) returnCode = 6;
            _returnCode = (ReturnCode)returnCode;

            // other bit flags
            _authoritativeAnswer = ((flags1 & 4) != 0);
            _recursionAvailable = ((flags2 & 128) != 0);
            _truncated = ((flags1 & 2) != 0);

            // create the arrays of response objects
            _questions = new Question[GetShort(message, 4)];
            _answers = new Answer[GetShort(message, 6)];
            _nameServers = new NameServer[GetShort(message, 8)];
            _additionalRecords = new AdditionalRecord[GetShort(message, 10)];

            // need a pointer to do this, position just after the header
            var pointer = new Pointer(message, 12);

            // and now populate them, they always follow this order
            for (var index = 0; index < _questions.Length; index++)
            {
                try
                {
                    // try to build a quesion from the response
                    _questions[index] = new Question(pointer);
                }
                catch (Exception ex)
                {
                    // something grim has happened, we can't continue
                    throw new InvalidResponseException(ex);
                }
            }
            for (var index = 0; index < _answers.Length; index++)
            {
                _answers[index] = new Answer(pointer);
            }
            for (var index = 0; index < _nameServers.Length; index++)
            {
                _nameServers[index] = new NameServer(pointer);
            }
            for (var index = 0; index < _additionalRecords.Length; index++)
            {
                _additionalRecords[index] = new AdditionalRecord(pointer);
            }
        }
示例#5
0
文件: AAAARecord.cs 项目: bwail/xmpp
        /// <summary>
        /// Constructs an ANAME record by reading bytes from a return message
        /// </summary>
        /// <param name="pointer">A logical pointer to the bytes holding the record</param>
        internal AAAARecord(Pointer pointer)
        {
            byte b1 = pointer.ReadByte();
            byte b2 = pointer.ReadByte();
            byte b3 = pointer.ReadByte();
            byte b4 = pointer.ReadByte();
            byte b5 = pointer.ReadByte();
            byte b6 = pointer.ReadByte();
            byte b7 = pointer.ReadByte();
            byte b8 = pointer.ReadByte();

            // this next line's not brilliant - couldn't find a better way though
            _ipAddress = IPAddress.Parse(string.Format("{0}:{1}:{2}:{3}:{4}:{5}:{6}:{7}", b1, b2, b3, b4, b5, b6, b7, b8));
        }
示例#6
0
文件: Question.cs 项目: bwail/xmpp
 /// <summary>
 /// Construct the question reading from a DNS Server response. Consult RFC1035 4.1.2
 /// for byte-wise details of this structure in byte array form
 /// </summary>
 /// <param name="pointer">a logical pointer to the Question in byte array form</param>
 internal Question(Pointer pointer)
 {
     // extract from the message
     _domain = pointer.ReadDomain();
     _dnsType = (DnsType)pointer.ReadShort();
     _dnsClass = (DnsClass)pointer.ReadShort();
 }