예제 #1
0
 internal DnsResourceRecordIPAddress(DnsResourceRecord rr, int address_size)
 {
     CopyFrom(rr);
     ArraySegment<byte> segment = rr.Data;
     var bytes = new byte[address_size];
     Buffer.BlockCopy(segment.Array, segment.Offset, bytes, 0, address_size);
     address = new IPAddress(bytes);
 }
예제 #2
0
 internal void CopyFrom(DnsResourceRecord rr)
 {
     name = rr.name;
     type = rr.type;
     klass = rr.klass;
     ttl = rr.ttl;
     rdlength = rr.rdlength;
     m_rdata = rr.m_rdata;
 }
예제 #3
0
        internal static DnsResourceRecord CreateFromBuffer(DnsPacket packet, int size, ref int offset)
        {
            string pname = packet.ReadName(ref offset);
            var ptype = (DnsType) packet.ReadUInt16(ref offset);
            var pclass = (DnsClass) packet.ReadUInt16(ref offset);
            int pttl = packet.ReadInt32(ref offset);
            ushort prdlength = packet.ReadUInt16(ref offset);
            var 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;
        }
예제 #4
0
 internal DnsResourceRecordPTR(DnsResourceRecord rr)
 {
     CopyFrom(rr);
     int offset = rr.Data.Offset;
     dname = DnsPacket.ReadName(rr.Data.Array, ref offset);
 }
예제 #5
0
 internal DnsResourceRecordAAAA(DnsResourceRecord rr)
     : base(rr, 16)
 {
 }
예제 #6
0
 internal DnsResourceRecordA(DnsResourceRecord rr)
     : base(rr, 4)
 {
 }