Exemple #1
0
        /// <summary>
        /// Parse answers into a typed array
        /// </summary>
        /// <param name="paylod"></param>
        /// <returns></returns>
        private static DnsAnswer[] ParseAnswers(byte[] payload, int start, uint count)
        {
            if (Adapter.VerboseDebugging)
            {
                Debug.WriteLine("DNS Answers");
            }

            var    result      = new DnsAnswer[count];
            ushort currentSize = 0;
            var    position    = start;

            try
            {
                for (ushort i = 0; i < count; i++)
                {
                    currentSize = Utility.ExtractRangeFromArray(payload, position + 10, 2).ToShort();

                    result[i] = new DnsAnswer()
                    {
                        Type       = Utility.ExtractRangeFromArray(payload, position + 2, 2).ToShort(),
                        Expiration = Microsoft.SPOT.Hardware.PowerState.Uptime.Add(new TimeSpan(TimeSpan.TicksPerSecond * Utility.ExtractRangeFromArray(payload, position + 6, 4).ToInt())),
                        Value      = Utility.ExtractRangeFromArray(payload, position + 12, currentSize)
                    };

                    position += currentSize + 12;  // move pointer to start of next answer
                }
            }
            catch
            {
                Debug.WriteLine("Warning: Failed to parse DNS answers");
                return(new DnsAnswer[0]);  // return an empty array...
            }

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Parse answers into a typed array
        /// </summary>
        /// <param name="paylod"></param>
        /// <returns></returns>
        private static DnsAnswer[] ParseAnswers(byte[] payload, int start, uint count)
        {
            if (Adapter.VerboseDebugging) Debug.WriteLine("DNS Answers");

            var result = new DnsAnswer[count];
            ushort currentSize = 0;
            var position = start;

            try
            {
                for (ushort i = 0; i < count; i++)
                {
                    currentSize = Utility.ExtractRangeFromArray(payload, position + 10, 2).ToShort();

                    result[i] = new DnsAnswer()
                    {
                        Type = Utility.ExtractRangeFromArray(payload, position + 2, 2).ToShort(),
                        Expiration = Microsoft.SPOT.Hardware.PowerState.Uptime.Add(new TimeSpan(TimeSpan.TicksPerSecond * Utility.ExtractRangeFromArray(payload, position + 6, 4).ToInt())),
                        Value = Utility.ExtractRangeFromArray(payload, position + 12, currentSize)
                    };

                    position += currentSize + 12;  // move pointer to start of next answer
                }

            }
            catch
            {
                Debug.WriteLine("Warning: Failed to parse DNS answers");
                return new DnsAnswer[0];  // return an empty array...
            }

            return result;
        }