Beispiel #1
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(_algorithmName);
            sb.Append(" ");
            sb.Append(_timeSigned);
            sb.Append(" ");
            sb.Append(_fudge);
            sb.Append(" ");
            sb.Append(_mac.Length);
            sb.Append(" ");
            sb.Append(Convert.ToBase64String(Mac));
            sb.Append(" ");
            sb.Append(_error);
            sb.Append(" ");

            if (_otherData == null)
            {
                sb.Append(0);
            }
            else
            {
                sb.Append(_otherData.Length);
                sb.Append(" ");

                if (_error == RCode.BADTIME)
                {
                    if (_otherData.Length != 6)
                    {
                        sb.Append("<invalid BADTIME other data>");
                    }
                    else
                    {
                        long time = ((long)(_otherData[0] & 0xFF) << 40) +
                                    ((long)(_otherData[1] & 0xFF) << 32) +
                                    ((_otherData[2] & 0xFF) << 24) +
                                    ((_otherData[3] & 0xFF) << 16) +
                                    ((_otherData[4] & 0xFF) << 8) +
                                    ((_otherData[5] & 0xFF));

                        sb.Append("<server time: ");
                        sb.Append(DnsHelpers.ConvertFromDnsTime(time));
                        sb.Append(">");
                    }
                }
                else
                {
                    sb.Append("<");
                    sb.Append(Convert.ToBase64String(_otherData));
                    sb.Append(">");
                }
            }

            return(sb.ToString());
        }
Beispiel #2
0
        public override void ParseRecord(ref MemoryStream memoryStream)
        {
            Byte[] dataUInt16 = new byte[2];
            Byte[] dataUInt32 = new byte[4];

            _algorithmName = ParseName(ref memoryStream);

            memoryStream.Read(dataUInt16, 0, dataUInt16.Length);
            long timeHigh = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(dataUInt16, 0));

            memoryStream.Read(dataUInt32, 0, dataUInt32.Length);
            long timeLow = (uint)IPAddress.NetworkToHostOrder((int)BitConverter.ToUInt32(dataUInt32, 0));

            _timeSigned = DnsHelpers.ConvertFromDnsTime(timeLow, timeHigh);

            memoryStream.Read(dataUInt16, 0, dataUInt16.Length);
            _fudge = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(dataUInt16, 0));

            memoryStream.Read(dataUInt16, 0, dataUInt16.Length);
            Int32 macLen = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(dataUInt16, 0));

            _mac = new byte[macLen];
            memoryStream.Read(_mac, 0, macLen);

            memoryStream.Read(dataUInt16, 0, dataUInt16.Length);
            _originalId = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(dataUInt16, 0));

            memoryStream.Read(dataUInt16, 0, dataUInt16.Length);
            _error = (RCode)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(dataUInt16, 0));

            memoryStream.Read(dataUInt16, 0, dataUInt16.Length);
            Int32 otherLen = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(dataUInt16, 0));

            if (otherLen > 0)
            {
                _otherData = new byte[otherLen];
                memoryStream.Read(_otherData, 0, otherLen);
            }
            else
            {
                _otherData = null;
            }

            _answer = ToString();
        }