예제 #1
0
        public int LoadFrom(byte[] bytes, int offset, ushort count)
        {
            int currentOffset = offset;

            for (int index = 0; index < count; index++)
            {
                // TODO: move this code into the Question object

                Question question = new Question();

                question.Name = DnsProtocol.ReadString(bytes, ref currentOffset);

                question.Type  = (ResourceType)(BitConverter.ToUInt16(bytes, currentOffset).SwapEndian());
                currentOffset += 2;

                question.Class = (ResourceClass)(BitConverter.ToUInt16(bytes, currentOffset).SwapEndian());
                currentOffset += 2;

                this.Add(question);
            }

            int bytesRead = currentOffset - offset;

            return(bytesRead);
        }
예제 #2
0
        public static DomainNamePointRData Parse(byte[] bytes, int offset, int size)
        {
            DomainNamePointRData domainName = new DomainNamePointRData();

            domainName.Name = DnsProtocol.ReadString(bytes, ref offset);
            return(domainName);
        }
예제 #3
0
        public static CNameRData Parse(byte[] bytes, int offset, int size)
        {
            CNameRData cname = new CNameRData();

            cname.Name = DnsProtocol.ReadString(bytes, ref offset);
            return(cname);
        }
예제 #4
0
        public static NameServerRData Parse(byte[] bytes, int offset, int size)
        {
            NameServerRData nsRdata = new NameServerRData();

            nsRdata.Name = DnsProtocol.ReadString(bytes, ref offset);
            return(nsRdata);
        }
예제 #5
0
        public static StatementOfAuthorityRData Parse(byte[] bytes, int offset, int size)
        {
            StatementOfAuthorityRData soaRdata = new StatementOfAuthorityRData();

            soaRdata.PrimaryNameServer = DnsProtocol.ReadString(bytes, ref offset);
            soaRdata.ResponsibleAuthoritativeMailbox = DnsProtocol.ReadString(bytes, ref offset);
            soaRdata.Serial          = DnsProtocol.ReadUint(bytes, ref offset).SwapEndian();
            soaRdata.RefreshInterval = DnsProtocol.ReadUint(bytes, ref offset).SwapEndian();
            soaRdata.RetryInterval   = DnsProtocol.ReadUint(bytes, ref offset).SwapEndian();
            soaRdata.ExpirationLimit = DnsProtocol.ReadUint(bytes, ref offset).SwapEndian();
            soaRdata.MinimumTTL      = DnsProtocol.ReadUint(bytes, ref offset).SwapEndian();
            return(soaRdata);
        }
예제 #6
0
        public int LoadFrom(byte[] bytes, int offset, ushort count)
        {
            int currentOffset = offset;

            for (int index = 0; index < count; index++)
            {
                // TODO: move this code into the Resource object

                Resource resource = new Resource();
                //// extract the domain, question type, question class and Ttl

                resource.Name = DnsProtocol.ReadString(bytes, ref currentOffset);

                resource.Type  = (ResourceType)(BitConverter.ToUInt16(bytes, currentOffset).SwapEndian());
                currentOffset += sizeof(ushort);

                resource.Class = (ResourceClass)(BitConverter.ToUInt16(bytes, currentOffset).SwapEndian());
                currentOffset += sizeof(ushort);

                resource.TTL   = BitConverter.ToUInt32(bytes, currentOffset).SwapEndian();
                currentOffset += sizeof(uint);

                resource.DataLength = BitConverter.ToUInt16(bytes, currentOffset).SwapEndian();
                currentOffset      += sizeof(ushort);

                if (resource.Class == ResourceClass.IN && resource.Type == ResourceType.A)
                {
                    resource.RData = ANameRData.Parse(bytes, currentOffset, resource.DataLength);
                }
                else if (resource.Type == ResourceType.CNAME)
                {
                    resource.RData = CNameRData.Parse(bytes, currentOffset, resource.DataLength);
                }

                // move past resource data record
                currentOffset = currentOffset + resource.DataLength;

                this.Add(resource);
            }

            int bytesRead = currentOffset - offset;

            return(bytesRead);
        }