Example #1
0
        /// <summary>
        /// Parses Bytes from DNS to IDnsPacket Object
        /// </summary>
        /// <param name="data"></param>
        /// <param name="sendDnsPacket"></param>
        /// <returns></returns>
        public static IDnsPacket Parse(byte[] data, SendDnsPacket sendDnsPacket)
        {
            IDnsHeader header = DnsHeader.Parse(data.Take(12).ToArray()); //Take First 12x Bytes which should always equal to DNS header

            if (header.Parameters.Response != ResponseCode.Ok)            //If other response to OK, then return.
            {
                return(new ReceiveDnsPacket(header, sendDnsPacket.Questions, null));
            }

            int byteCount = 12;                                                             //Amount of bytes before answer (Start with header)

            sendDnsPacket.Questions.ToList().ForEach(n => byteCount += n.ToBytes().Length); //Question Byte Count
            byte[] answerArr = data.TakeLast(data.Length - byteCount).ToArray();            //Extracts answers from data

            IEnumerable <IResource> answers = Resource.Parse(data, new ReceiveDnsPacket(header, sendDnsPacket.Questions, null));

            return(new ReceiveDnsPacket(header, sendDnsPacket.Questions, answers));
        }
Example #2
0
 /// <summary>
 /// Construction of a Receive DNS Packet
 /// </summary>
 /// <param name="header"></param>
 /// <param name="questions"></param>
 /// <param name="resource"></param>
 protected DnsPacket(IDnsHeader header, IEnumerable <IQuestion> questions, IEnumerable <IResource> resource)
 {
     Header    = header;
     Questions = questions;
     Resources = resource;
 }
Example #3
0
 /// <inheritdoc />
 /// <summary>
 /// Construction of a Send DNS Packet
 /// </summary>
 /// <param name="header"></param>
 /// <param name="question"></param>
 public SendDnsPacket(IDnsHeader header, IQuestion question) : base(header, new [] { question })
 {
 }
Example #4
0
 /// <summary>
 /// Construction of a Send DNS Packet
 /// </summary>
 /// <param name="header"></param>
 /// <param name="questions"></param>
 protected DnsPacket(IDnsHeader header, IEnumerable <IQuestion> questions) : this(header, questions, null)
 {
 }
Example #5
0
 public ReceiveDnsPacket(IDnsHeader header, IEnumerable <IQuestion> questions, IEnumerable <IResource> resource) : base(header, questions, resource)
 {
 }