Esempio n. 1
0
 protected internal override void EncodeRecordData(byte[] messageData, int offset, ref int currentPosition, Dictionary <string, ushort> domainNames)
 {
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, (ushort)Type);
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, KeyTag);
     messageData[currentPosition++] = (byte)Algorithm;
     DnsMessageBase.EncodeByteArray(messageData, ref currentPosition, Certificate);
 }
Esempio n. 2
0
        protected internal override void EncodeRecordData(byte[] messageData, int offset, ref int currentPosition, Dictionary <string, ushort> domainNames)
        {
            foreach (AddressPrefix addressPrefix in Prefixes)
            {
                DnsMessageBase.EncodeUShort(messageData, ref currentPosition, (ushort)addressPrefix.AddressFamily);
                messageData[currentPosition++] = addressPrefix.Prefix;

                // no increment of position pointer, just set 1 bit
                if (addressPrefix.IsNegated)
                {
                    messageData[currentPosition] = 128;
                }

                byte[] addressData = addressPrefix.Address.GetNetworkAddress(addressPrefix.Prefix).GetAddressBytes();
                int    length      = addressData.Length;
                for (; length > 0; length--)
                {
                    if (addressData[length - 1] != 0)
                    {
                        break;
                    }
                }
                messageData[currentPosition++] |= (byte)length;
                DnsMessageBase.EncodeByteArray(messageData, ref currentPosition, addressData, length);
            }
        }
Esempio n. 3
0
 protected internal override void EncodeRecordData(byte[] messageData, int offset, ref int currentPosition, Dictionary <string, ushort> domainNames)
 {
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, Flags);
     messageData[currentPosition++] = Protocol;
     messageData[currentPosition++] = (byte)Algorithm;
     DnsMessageBase.EncodeByteArray(messageData, ref currentPosition, PublicKey);
 }
Esempio n. 4
0
 protected internal override void EncodeRecordData(byte[] messageData, int offset, ref int currentPosition, Dictionary <string, ushort> domainNames)
 {
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, Priority);
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, Weight);
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, Port);
     DnsMessageBase.EncodeDomainName(messageData, offset, ref currentPosition, Target, false, domainNames);
 }
Esempio n. 5
0
 protected internal override void EncodeRecordData(byte[] messageData, int offset, ref int currentPosition, Dictionary <string, ushort> domainNames)
 {
     messageData[currentPosition++] = (byte)HashAlgorithm;
     messageData[currentPosition++] = Flags;
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, Iterations);
     messageData[currentPosition++] = (byte)Salt.Length;
     DnsMessageBase.EncodeByteArray(messageData, ref currentPosition, Salt);
 }
Esempio n. 6
0
 internal override void EncodeData(byte[] messageData, ref int currentPosition)
 {
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, Version);
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, (ushort)OperationCode);
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, (ushort)ErrorCode);
     DnsMessageBase.EncodeULong(messageData, ref currentPosition, Id);
     DnsMessageBase.EncodeUInt(messageData, ref currentPosition, (uint)LeaseTime.TotalSeconds);
 }
Esempio n. 7
0
        internal override void EncodeData(byte[] messageData, ref int currentPosition)
        {
            DnsMessageBase.EncodeUShort(messageData, ref currentPosition, (ushort)(Family == AddressFamily.InterNetwork ? 1 : 2));
            messageData[currentPosition++] = SourceNetmask;
            messageData[currentPosition++] = ScopeNetmask;

            byte[] data = Address.GetAddressBytes();
            DnsMessageBase.EncodeByteArray(messageData, ref currentPosition, data, GetAddressLength());
        }
Esempio n. 8
0
        internal void EncodeRecordHeader(byte[] messageData, int offset, ref int currentPosition, Dictionary <string, ushort> domainNames, out int recordPosition)
        {
            DnsMessageBase.EncodeDomainName(messageData, offset, ref currentPosition, Name, true, domainNames);
            DnsMessageBase.EncodeUShort(messageData, ref currentPosition, (ushort)RecordType);
            DnsMessageBase.EncodeUShort(messageData, ref currentPosition, (ushort)RecordClass);
            DnsMessageBase.EncodeInt(messageData, ref currentPosition, TimeToLive);

            recordPosition = currentPosition + 2;
        }
 protected override void EncodePublicKey(byte[] messageData, int offset, ref int currentPosition, Dictionary <string, ushort> domainNames)
 {
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, (ushort)Prime.Length);
     DnsMessageBase.EncodeByteArray(messageData, ref currentPosition, Prime);
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, (ushort)Generator.Length);
     DnsMessageBase.EncodeByteArray(messageData, ref currentPosition, Generator);
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, (ushort)PublicValue.Length);
     DnsMessageBase.EncodeByteArray(messageData, ref currentPosition, PublicValue);
 }
Esempio n. 10
0
 protected internal override void EncodeRecordData(byte[] messageData, int offset, ref int currentPosition, Dictionary <string, ushort> domainNames)
 {
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, Order);
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, Preference);
     DnsMessageBase.EncodeTextBlock(messageData, ref currentPosition, Flags);
     DnsMessageBase.EncodeTextBlock(messageData, ref currentPosition, Services);
     DnsMessageBase.EncodeTextBlock(messageData, ref currentPosition, RegExp);
     DnsMessageBase.EncodeDomainName(messageData, offset, ref currentPosition, Replacement, false, domainNames);
 }
Esempio n. 11
0
        private byte[] QueryByTcp(IPAddress nameServer, byte[] messageData, int messageLength, ref TcpClient tcpClient, ref NetworkStream tcpStream, out IPAddress responderAddress)
        {
            responderAddress = nameServer;

            IPEndPoint endPoint = new IPEndPoint(nameServer, _port);

            try
            {
                if (tcpClient == null)
                {
                    tcpClient = new TcpClient(nameServer.AddressFamily)
                    {
                        ReceiveTimeout = QueryTimeout,
                        SendTimeout    = QueryTimeout
                    };

                    tcpClient.Connect(endPoint);
                    tcpStream = tcpClient.GetStream();
                }

                int    tmp          = 0;
                byte[] lengthBuffer = new byte[2];

                if (messageLength > 0)
                {
                    DnsMessageBase.EncodeUShort(lengthBuffer, ref tmp, (ushort)messageLength);

                    tcpStream.Write(lengthBuffer, 0, 2);
                    tcpStream.Write(messageData, 0, messageLength);
                }

                lengthBuffer[0] = (byte)tcpStream.ReadByte();
                lengthBuffer[1] = (byte)tcpStream.ReadByte();

                tmp = 0;
                int length = DnsMessageBase.ParseUShort(lengthBuffer, ref tmp);

                byte[] resultData = new byte[length];

                int readBytes = 0;

                while (readBytes < length)
                {
                    readBytes += tcpStream.Read(resultData, readBytes, length - readBytes);
                }

                return(resultData);
            }
            catch (Exception e)
            {
                Trace.TraceError("Error on dns query: " + e);
                return(null);
            }
        }
Esempio n. 12
0
 private void EncodeRecordData(byte[] messageData, int offset, ref int currentPosition, Dictionary <string, ushort> domainNames, byte[] mac)
 {
     DnsMessageBase.EncodeDomainName(messageData, offset, ref currentPosition, TSigAlgorithmHelper.GetDomainName(Algorithm), false, domainNames);
     EncodeDateTime(messageData, ref currentPosition, TimeSigned);
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, (ushort)Fudge.TotalSeconds);
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, (ushort)mac.Length);
     DnsMessageBase.EncodeByteArray(messageData, ref currentPosition, mac);
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, OriginalID);
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, (ushort)Error);
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, (ushort)OtherData.Length);
     DnsMessageBase.EncodeByteArray(messageData, ref currentPosition, OtherData);
 }
Esempio n. 13
0
 protected internal override void EncodeRecordData(byte[] messageData, int offset, ref int currentPosition, Dictionary <string, ushort> domainNames)
 {
     if ((Options != null) && (Options.Count != 0))
     {
         foreach (EDnsOptionBase option in Options)
         {
             DnsMessageBase.EncodeUShort(messageData, ref currentPosition, (ushort)option.Type);
             DnsMessageBase.EncodeUShort(messageData, ref currentPosition, option.DataLength);
             option.EncodeData(messageData, ref currentPosition);
         }
     }
 }
Esempio n. 14
0
 protected internal override void EncodeRecordData(byte[] messageData, int offset, ref int currentPosition, Dictionary <string, ushort> domainNames)
 {
     DnsMessageBase.EncodeDomainName(messageData, offset, ref currentPosition, TSigAlgorithmHelper.GetDomainName(Algorithm), false, domainNames);
     EncodeDateTime(messageData, ref currentPosition, Inception);
     EncodeDateTime(messageData, ref currentPosition, Expiration);
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, (ushort)Mode);
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, (ushort)Error);
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, (ushort)Key.Length);
     DnsMessageBase.EncodeByteArray(messageData, ref currentPosition, Key);
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, (ushort)OtherData.Length);
     DnsMessageBase.EncodeByteArray(messageData, ref currentPosition, OtherData);
 }
Esempio n. 15
0
 protected internal override void EncodeRecordData(byte[] messageData, int offset, ref int currentPosition, Dictionary <string, ushort> domainNames)
 {
     messageData[currentPosition++] = (byte)Hit.Length;
     messageData[currentPosition++] = (byte)Algorithm;
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, (ushort)PublicKey.Length);
     DnsMessageBase.EncodeByteArray(messageData, ref currentPosition, Hit);
     DnsMessageBase.EncodeByteArray(messageData, ref currentPosition, PublicKey);
     foreach (string server in RendezvousServers)
     {
         DnsMessageBase.EncodeDomainName(messageData, offset, ref currentPosition, server, false, domainNames);
     }
 }
Esempio n. 16
0
 protected internal override void EncodeRecordData(byte[] messageData, int offset, ref int currentPosition, Dictionary <string, ushort> domainNames)
 {
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, (ushort)TypeCovered);
     messageData[currentPosition++] = (byte)Algorithm;
     messageData[currentPosition++] = Labels;
     DnsMessageBase.EncodeInt(messageData, ref currentPosition, OriginalTimeToLive);
     EncodeDateTime(messageData, ref currentPosition, SignatureExpiration);
     EncodeDateTime(messageData, ref currentPosition, SignatureInception);
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, KeyTag);
     DnsMessageBase.EncodeDomainName(messageData, offset, ref currentPosition, SignersName, false, null);
     DnsMessageBase.EncodeByteArray(messageData, ref currentPosition, Signature);
 }
Esempio n. 17
0
        private void TcpConnectCompleted <TMessage>(IAsyncResult ar)
            where TMessage : DnsMessageBase, new()
        {
            DnsClientAsyncState <TMessage> state = (DnsClientAsyncState <TMessage>)ar.AsyncState;

            if (state.Timer != null)
            {
                state.Timer.Dispose();
            }

            if (state.TimedOut)
            {
                state.EndpointInfoIndex++;
                TcpBeginConnect(state);
            }
            else
            {
                try
                {
                    state.TcpClient.EndConnect(ar);

                    state.TcpStream = state.TcpClient.GetStream();

                    int tmp = 0;

                    state.Buffer = new byte[2];
                    DnsMessageBase.EncodeUShort(state.Buffer, ref tmp, (ushort)state.QueryLength);

                    IAsyncResult asyncResult = state.TcpStream.BeginWrite(state.Buffer, 0, 2, TcpSendLengthCompleted <TMessage>, state);
                    state.Timer = new Timer(TcpTimedOut <TMessage>, asyncResult, state.TimeRemaining, Timeout.Infinite);
                }
                catch (Exception e)
                {
                    Trace.TraceError("Error on dns query: " + e);

                    try
                    {
                        state.TcpClient.Close();
                        state.Timer.Dispose();
                    }
                    catch {}

                    state.EndpointInfoIndex++;
                    TcpBeginConnect(state);
                }
            }
        }
Esempio n. 18
0
 internal void Encode(byte[] messageData, int offset, ref int currentPosition, Dictionary <string, ushort> domainNames, bool useCompressionMutation)
 {
     DnsMessageBase.EncodeDomainName(messageData, offset, ref currentPosition, Name, true, useCompressionMutation, domainNames);
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, (ushort)RecordType);
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, (ushort)RecordClass);
 }
Esempio n. 19
0
 internal void EncodeRecordLength(byte[] messageData, int offset, ref int recordDataOffset, Dictionary <string, ushort> domainNames, int recordPosition)
 {
     DnsMessageBase.EncodeUShort(messageData, ref recordDataOffset, (ushort)(recordPosition - recordDataOffset - 2));
     recordDataOffset = recordPosition;
 }
Esempio n. 20
0
 protected internal override void EncodeRecordData(byte[] messageData, int offset, ref int currentPosition, Dictionary <string, ushort> domainNames)
 {
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, (ushort)SubType);
     DnsMessageBase.EncodeDomainName(messageData, offset, ref currentPosition, Hostname, false, domainNames);
 }
Esempio n. 21
0
 protected internal override void EncodeRecordData(byte[] messageData, int offset, ref int currentPosition, Dictionary <string, ushort> domainNames)
 {
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, Preference);
     DnsMessageBase.EncodeULong(messageData, ref currentPosition, Locator64);
 }
Esempio n. 22
0
 protected internal override void EncodeRecordData(byte[] messageData, int offset, ref int currentPosition, Dictionary <string, ushort> domainNames)
 {
     DnsMessageBase.EncodeUShort(messageData, ref currentPosition, Preference);
     DnsMessageBase.EncodeDomainName(messageData, offset, ref currentPosition, ExchangeDomainName, true, domainNames);
 }