コード例 #1
0
        public static DnsMessage ParseMessage(ReadOnlySpan <byte> span, out int bytesConsumed)
        {
            var context = new DnsParseContext(span);

            var message = new DnsMessage
            {
                QueryId = context.ReadUInt16(),
            };
            ushort flags           = context.ReadUInt16();
            int    queryCount      = context.ReadUInt16();
            int    answerCount     = context.ReadUInt16();
            int    serverCount     = context.ReadUInt16();
            int    additionalCount = context.ReadUInt16();

            message.IsResponse            = (flags & ResponseFlag) != 0;
            message.Operation             = (DnsOperation)((flags & OpCodeMask) >> OpCodeShift);
            message.IsAuthoritativeAnswer = (flags & AuthoritativeMask) != 0;
            message.IsTruncated           = (flags & TruncationMask) != 0;
            message.IsRecursionDesired    = (flags & RecursionDesiredMask) != 0;
            message.IsRecursionAvailable  = (flags & RecursionAvailableMask) != 0;
            message.ResponseCode          = (DnsResponseCode)(flags & ResponseCodeMask);