protected override void ChannelRead0(IChannelHandlerContext ctx, DatagramDnsQuery query) { DatagramDnsResponse response = new DatagramDnsResponse(query.Recipient, query.Sender, query.Id); DefaultDnsQuestion dnsQuestion = query.GetRecord <DefaultDnsQuestion>(DnsSection.QUESTION); response.AddRecord(DnsSection.QUESTION, dnsQuestion); _readAction(ctx, new TransportMessage(new DnsTransportMessage { DnsResponse = response, DnsQuestion = dnsQuestion })); }
private static IDnsResponse NewResponse(DatagramPacket packet, IByteBuffer buffer) { int id = buffer.ReadUnsignedShort(); int flags = buffer.ReadUnsignedShort(); if (flags >> 15 == 0) { throw new CorruptedFrameException("not a response"); } IDnsResponse response = new DatagramDnsResponse( packet.Sender, packet.Recipient, id, DnsOpCode.From((byte)(flags >> 1 & 0xf)), DnsResponseCode.From((byte)(flags & 0xf))); return(response); }