Example #1
0
        static internal DnsResourceRecord CreateFromBuffer(DnsPacket packet, int size, ref int offset)
        {
            string            pname     = packet.ReadName(ref offset);
            DnsType           ptype     = (DnsType)packet.ReadUInt16(ref offset);
            DnsClass          pclass    = (DnsClass)packet.ReadUInt16(ref offset);
            int               pttl      = packet.ReadInt32(ref offset);
            ushort            prdlength = packet.ReadUInt16(ref offset);
            DnsResourceRecord rr        = new DnsResourceRecord();

            rr.name     = pname;
            rr.type     = ptype;
            rr.klass    = pclass;
            rr.ttl      = pttl;
            rr.rdlength = prdlength;
            rr.m_rdata  = new ArraySegment <byte>(packet.Packet, offset, prdlength);
            offset     += prdlength;

            switch (pclass)
            {
            case DnsClass.IN:
                switch (ptype)
                {
                case DnsType.A:
                    rr = new DnsResourceRecordA(rr);
                    break;

                case DnsType.AAAA:
                    rr = new DnsResourceRecordAAAA(rr);
                    break;

                case DnsType.CNAME:
                    rr = new DnsResourceRecordCName(rr);
                    break;

                case DnsType.PTR:
                    rr = new DnsResourceRecordPTR(rr);
                    break;

                default:
                    break;
                }
                break;

            default:
                break;
            }
            return(rr);
        }
Example #2
0
		static internal DnsResourceRecord CreateFromBuffer(DnsPacket packet, int size, ref int offset) {
			string pname = packet.ReadName(ref offset);
			DnsType ptype = (DnsType)packet.ReadUInt16(ref offset);
			DnsClass pclass = (DnsClass)packet.ReadUInt16(ref offset);
			int pttl = packet.ReadInt32(ref offset);
			ushort prdlength = packet.ReadUInt16(ref offset);
			DnsResourceRecord rr = new DnsResourceRecord();
			rr.name = pname;
			rr.type = ptype;
			rr.klass = pclass;
			rr.ttl = pttl;
			rr.rdlength = prdlength;
			rr.m_rdata = new ArraySegment<byte>(packet.Packet, offset, prdlength);
			offset += prdlength;

			switch(pclass) {
			case DnsClass.IN:
				switch(ptype) {
				case DnsType.A:
					rr = new DnsResourceRecordA(rr);
					break;
				case DnsType.AAAA:
					rr = new DnsResourceRecordAAAA(rr);
					break;
				case DnsType.CNAME:
					rr = new DnsResourceRecordCName(rr);
					break;
				case DnsType.PTR:
					rr = new DnsResourceRecordPTR(rr);
					break;
				default:
					break;
					}
				break;
			default:
				break;
			}
			return rr;
		}