コード例 #1
0
ファイル: DnsQuestion.cs プロジェクト: netngn/Mono.Dns
 internal int Init(DnsPacket packet, int offset)
 {
     name = packet.ReadName(ref offset);
     type = (DnsQType) packet.ReadUInt16(ref offset);
     _class = (DnsQClass) packet.ReadUInt16(ref offset);
     return offset;
 }
コード例 #2
0
ファイル: DnsResourceRecord.cs プロジェクト: netngn/Mono.Dns
        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;
        }