コード例 #1
0
        private DnsQueryRequest ParseQuery(ref MemoryStream ms)
        {
            DnsQueryRequest queryRequest = new DnsQueryRequest();

            // Read name
            queryRequest.Name = DnsRecordBase.ParseName(ref ms);

            return(queryRequest);
        }
コード例 #2
0
        internal void ParseResponse(byte[] recvBytes, ProtocolType protocol)
        {
            MemoryStream memoryStream = new MemoryStream(recvBytes);

            byte[] flagBytes              = new byte[2];
            byte[] transactionId          = new byte[2];
            byte[] questions              = new byte[2];
            byte[] answerRRs              = new byte[2];
            byte[] authorityRRs           = new byte[2];
            byte[] additionalRRCountBytes = new byte[2];
            byte[] nsType  = new byte[2];
            byte[] nsClass = new byte[2];

            this._bytesReceived = recvBytes.Length;

            // Parse DNS Response
            memoryStream.Read(transactionId, 0, 2);
            memoryStream.Read(flagBytes, 0, 2);
            memoryStream.Read(questions, 0, 2);
            memoryStream.Read(answerRRs, 0, 2);
            memoryStream.Read(authorityRRs, 0, 2);
            memoryStream.Read(additionalRRCountBytes, 0, 2);

            // Parse Header
            _transactionId = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(transactionId, 0));
            _flags         = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(flagBytes, 0));
            _queryResponse = (QueryResponse)(_flags & (ushort)FlagMasks.QueryResponseMask);
            _opCode        = (OpCode)(_flags & (ushort)FlagMasks.OpCodeMask);
            _nsFlags       = (NsFlags)(_flags & (ushort)FlagMasks.NsFlagMask);
            _rCode         = (RCode)(_flags & (ushort)FlagMasks.RCodeMask);

            // Parse Questions Section
            _questions    = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(questions, 0));
            _answerRRs    = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(answerRRs, 0));
            _authorityRRs = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(authorityRRs, 0));
            ushort additionalRRCount = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(additionalRRCountBytes, 0));

            _additionalRecords      = new List <IDnsRecord>();
            _answers                = new DnsRecordBase[_answerRRs];
            _authoritiveNameServers = new DnsRecordBase[_authorityRRs];

            // Parse Queries
            _queryRequest = this.ParseQuery(ref memoryStream);

            // Read dnsType
            memoryStream.Read(nsType, 0, 2);

            // Read dnsClass
            memoryStream.Read(nsClass, 0, 2);

            _nsType  = (NsType)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(nsType, 0));
            _nsClass = (NsClass)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(nsClass, 0));

            // Read in Answer Blocks
            for (int i = 0; i < _answerRRs; i++)
            {
                _answers[i] = RecordFactory.Create(ref memoryStream);
            }

            // Parse Authority Records
            for (int i = 0; i < _authorityRRs; i++)
            {
                _authoritiveNameServers[i] = RecordFactory.Create(ref memoryStream);
            }

            // Parse Additional Records
            for (int i = 0; i < additionalRRCount; i++)
            {
                _additionalRecords.Add(RecordFactory.Create(ref memoryStream));
            }
        }