Esempio n. 1
0
 public void MergeCopyFrom(DNSPacket aSource)
 {
     this.Questions.AddRange(aSource.Questions);
     this.Answers.AddRange(aSource.Answers);
     this.AuthorityRecords.AddRange(aSource.AuthorityRecords);
     this.AdditionalRecords.AddRange(aSource.AdditionalRecords);
 }
Esempio n. 2
0
            private void GotData(IAsyncResult ar)
            {
                lock (this)
                {
                    if (timer == null)
                    {
                        return;
                    }
                    try
                    {
                        DNSPacket  pack = new DNSPacket();
                        IPEndPoint ipd  = null;

                        pack.ReadFrom(cl.EndReceive(ar, ref ipd));
                        if (pack.SequenceID != this.Input.SequenceID)
                        {
                            return;                                           // bad wolf
                        }
                        var tm = timer;
                        timer = null;
                        tm.Dispose();
                        cl.Close();
                        Callback(pack);
                    }
                    catch
                    {
                    }
                }
            }
Esempio n. 3
0
        public override void BodyReadFrom(byte[] aData, Stream aMainStream)
        {
            BinaryReader aSrc = new BinaryReader(new MemoryStream(aData));

            this.fTargetName = DNSPacket.ParseName(aSrc, aMainStream);
            aSrc.Close();
        }
Esempio n. 4
0
        public static DNSResource ReadFrom(BinaryReader aSrc)
        {
            DNSResource resource;
            string      str    = DNSPacket.ParseName(aSrc, aSrc.BaseStream);
            DNSType     aType  = (DNSType)DNSPacket.N2H(aSrc.ReadUInt16());
            DNSClass    class2 = (DNSClass)DNSPacket.N2H(aSrc.ReadUInt16());
            bool        flag   = false;

            if (0 != (((ushort)class2) & 0x8000))
            {
                flag = true;
            }
            class2 &= (DNSClass)(-32769);
            uint   num  = DNSPacket.N2H(aSrc.ReadUInt32());
            ushort num2 = DNSPacket.N2H(aSrc.ReadUInt16());

            byte[]  aData = aSrc.ReadBytes((int)num2);
            DNSType type2 = aType;

            if (type2 == DNSType.A)
            {
                resource = new DNSARecord();
            }
            else if (type2 == DNSType.AAAA)
            {
                resource = new DNSAAAARecord();
            }
            else if (type2 == DNSType.PTR)
            {
                resource = new DNSPTRRecord();
            }
            else if (type2 == DNSType.NS)
            {
                resource = new DNSNSRecord();
            }
            else if (type2 == DNSType.TXT)
            {
                resource = new DNSTXTRecord();
            }
            else if (type2 == DNSType.CNAME)
            {
                resource = new DNSCNameRecord();
            }
            else if (type2 == DNSType.SRV)
            {
                resource = new DNSSRVRecord();
            }
            else
            {
                resource = new DNSUnknownRecord(aType);
            }
            resource.fName       = str;
            resource.fParseTime  = DateTime.UtcNow;
            resource.fClass      = class2;
            resource.fClearCache = flag;
            resource.fTTL        = (ushort)num;
            resource.BodyReadFrom(aData, aSrc.BaseStream);
            return(resource);
        }
Esempio n. 5
0
        public override void BodyReadFrom(byte[] aData, Stream aMainStream)
        {
            BinaryReader aSrc = new BinaryReader(new MemoryStream(aData));

            this.fPriority   = DNSPacket.N2H(aSrc.ReadUInt16());
            this.fWeight     = DNSPacket.N2H(aSrc.ReadUInt16());
            this.fPort       = DNSPacket.N2H(aSrc.ReadUInt16());
            this.fTargetName = DNSPacket.ParseName(aSrc, aMainStream);
            aSrc.Close();
        }
Esempio n. 6
0
        public override byte[] BodyWriteTo()
        {
            BinaryWriter aDest = new BinaryWriter(new MemoryStream());

            DNSPacket.GenerateName(aDest, this.fTargetName);
            aDest.Flush();
            byte[] buffer = (aDest.BaseStream as MemoryStream).ToArray();
            aDest.Close();
            return(buffer);
        }
Esempio n. 7
0
        public void ReadFrom(BinaryReader aSrc)
        {
            this.fName = DNSPacket.ParseName(aSrc, aSrc.BaseStream);
            this.fType = (DNSType)DNSPacket.N2H(aSrc.ReadUInt16());
            ushort num = DNSPacket.N2H(aSrc.ReadUInt16());

            if (0 != (num & 0x8000))
            {
                this.fClearCache = true;
            }
            this.fClass = ((DNSClass)num) & ((DNSClass)(-32769));
        }
Esempio n. 8
0
 public void WriteTo(BinaryWriter aDest)
 {
     DNSPacket.GenerateName(aDest, this.fName);
     aDest.Write(DNSPacket.H2N((ushort)this.fType));
     if (this.fClearCache)
     {
         aDest.Write(DNSPacket.H2N((ushort)(this.fClass | ((DNSClass)0x8000))));
     }
     else
     {
         aDest.Write(DNSPacket.H2N((ushort)this.fClass));
     }
 }
Esempio n. 9
0
 public void BeginRequest(DNSQuestion question, Action<DNSResource> action)
 {
     DNSPacket req = new DNSPacket();
     req.QueryType = DNSQueryType.Standard;
     req.RecursionDesired = true;
     req.Questions.Add(question);
     BeginRequest(req, a =>
     {
         if (a == null || a.Answers.Count != 1)
             action(null);
         else
             action(a.Answers[0]);
     });
 }
Esempio n. 10
0
        public void BeginRequest(DNSPacket input, Action<DNSPacket> action)
        {
            if (fAddresses.Count == 0)
            {
                LoadSystemAddresses();
                if (fAddresses == null) throw new DNSException("No addresses available");
            }
            RequestInfo info = new RequestInfo();
            info.Input = input;
            info.Index = 0;
            info.Owner = this;
            info.Callback = action;
            input.SequenceID = (ushort)rnd.Next(ushort.MaxValue);

            info.Start();
        }
Esempio n. 11
0
 public void WriteTo(BinaryWriter aDest)
 {
     DNSPacket.GenerateName(aDest, this.fName);
     aDest.Write(DNSPacket.H2N((ushort)this.Type));
     if (this.fClearCache)
     {
         aDest.Write(DNSPacket.H2N((ushort)(this.fClass | ((DNSClass)0x8000))));
     }
     else
     {
         aDest.Write(DNSPacket.H2N((ushort)this.fClass));
     }
     byte[] buffer = this.BodyWriteTo();
     aDest.Write(DNSPacket.H2N((uint)this.fTTL));
     aDest.Write(DNSPacket.H2N((ushort)buffer.Length));
     aDest.Write(buffer, 0, buffer.Length);
 }
Esempio n. 12
0
        public void BeginRequest(DNSQuestion question, Action <DNSResource> action)
        {
            DNSPacket req = new DNSPacket();

            req.QueryType        = DNSQueryType.Standard;
            req.RecursionDesired = true;
            req.Questions.Add(question);
            BeginRequest(req, a =>
            {
                if (a == null || a.Answers.Count != 1)
                {
                    action(null);
                }
                else
                {
                    action(a.Answers[0]);
                }
            });
        }
Esempio n. 13
0
        public void BeginRequest(DNSPacket input, Action <DNSPacket> action)
        {
            if (fAddresses.Count == 0)
            {
                LoadSystemAddresses();
                if (fAddresses == null)
                {
                    throw new DNSException("No addresses available");
                }
            }
            RequestInfo info = new RequestInfo();

            info.Input       = input;
            info.Index       = 0;
            info.Owner       = this;
            info.Callback    = action;
            input.SequenceID = (ushort)rnd.Next(ushort.MaxValue);

            info.Start();
        }
Esempio n. 14
0
            private void GotData(IAsyncResult ar)
            {
                lock (this)
                {
                    if (timer == null)
                    {
                        return;
                    }
                    try
                    {
                        DNSPacket pack = new DNSPacket();
                        IPEndPoint ipd = null;

                        pack.ReadFrom(cl.EndReceive(ar, ref ipd));
                        if (pack.SequenceID != this.Input.SequenceID) return; // bad wolf
                        var tm = timer;
                        timer = null;
                        tm.Dispose();
                        cl.Close();
                        Callback(pack);
                    }
                    catch
                    {
                    }
                }
            }
Esempio n. 15
0
 public void MergeCopyFrom(DNSPacket aSource)
 {
     this.Questions.AddRange(aSource.Questions);
     this.Answers.AddRange(aSource.Answers);
     this.AuthorityRecords.AddRange(aSource.AuthorityRecords);
     this.AdditionalRecords.AddRange(aSource.AdditionalRecords);
 }