internal static DnsOptions Read(DataSegment data)
        {
            List <DnsOption> options = new List <DnsOption>();

            while (data.Length != 0)
            {
                if (data.Length < DnsOption.MinimumLength)
                {
                    return(null);
                }
                DnsOptionCode code             = (DnsOptionCode)data.ReadUShort(0, Endianity.Big);
                ushort        optionDataLength = data.ReadUShort(sizeof(ushort), Endianity.Big);

                int optionLength = DnsOption.MinimumLength + optionDataLength;
                if (data.Length < optionLength)
                {
                    return(null);
                }
                DnsOption option = DnsOption.CreateInstance(code, data.Subsegment(DnsOption.MinimumLength, optionDataLength));
                if (option == null)
                {
                    return(null);
                }
                options.Add(option);

                data = data.Subsegment(optionLength, data.Length - optionLength);
            }

            return(new DnsOptions(options));
        }
Esempio n. 2
0
        internal static DnsOptions Read(DataSegment data)
        {
            List <DnsOption> list = new List <DnsOption>();
            int offset;

            for (; data.Length != 0; data = data.Subsegment(offset, data.Length - offset))
            {
                if (data.Length < 4)
                {
                    return((DnsOptions)null);
                }
                DnsOptionCode code = (DnsOptionCode)data.ReadUShort(0, Endianity.Big);
                ushort        num  = data.ReadUShort(2, Endianity.Big);
                offset = 4 + (int)num;
                if (data.Length < offset)
                {
                    return((DnsOptions)null);
                }
                DnsOption instance = DnsOption.CreateInstance(code, data.Subsegment(4, (int)num));
                if (instance == null)
                {
                    return((DnsOptions)null);
                }
                list.Add(instance);
            }
            return(new DnsOptions((IList <DnsOption>)list));
        }