Option IOptionComplexFactory.CreateInstance(byte[] buffer, ref int offset, byte valueLength)
            {
                if ((int)valueLength < 2 || (int)valueLength % 4 != 2)
                {
                    return((Option)null);
                }
                byte num1 = buffer[offset++];

                if ((int)num1 % 4 != 1 || (int)num1 < 5)
                {
                    return((Option)null);
                }
                byte pointedIndex = (byte)((int)num1 / 4 - 1);
                byte num2         = buffer[offset++];
                IpV4OptionTimestampType timestampType = (IpV4OptionTimestampType)((uint)num2 & 15U);
                byte overflow  = (byte)((uint)num2 >> 4);
                int  numValues = (int)valueLength / 4;

                switch (timestampType)
                {
                case IpV4OptionTimestampType.TimestampOnly:
                    return((Option)IpV4OptionTimestampOnly.Read(overflow, pointedIndex, buffer, ref offset, numValues));

                case IpV4OptionTimestampType.AddressAndTimestamp:
                case IpV4OptionTimestampType.AddressPrespecified:
                    return((Option)IpV4OptionTimestampAndAddress.Read(timestampType, overflow, pointedIndex, buffer, ref offset, numValues));

                default:
                    return((Option)null);
                }
            }
            Option IOptionComplexFactory.CreateInstance(byte[] buffer, ref int offset, byte valueLength)
            {
                if (valueLength < OptionValueMinimumLength || valueLength % 4 != 2)
                {
                    return(null);
                }

                byte pointer = buffer[offset++];

                if (pointer % 4 != 1 || pointer < 5)
                {
                    return(null);
                }

                byte pointedIndex = (byte)(pointer / 4 - 1);

                byte overflow = buffer[offset++];
                IpV4OptionTimestampType timestampType = (IpV4OptionTimestampType)(overflow & 0x0F);

                overflow >>= 4;

                int numValues = valueLength / 4;

                switch (timestampType)
                {
                case IpV4OptionTimestampType.TimestampOnly:
                    return(IpV4OptionTimestampOnly.Read(overflow, pointedIndex, buffer, ref offset, numValues));

                case IpV4OptionTimestampType.AddressAndTimestamp:
                case IpV4OptionTimestampType.AddressPrespecified:
                    return(IpV4OptionTimestampAndAddress.Read(timestampType, overflow, pointedIndex, buffer, ref offset, numValues));

                default:
                    return(null);
                }
            }
Ejemplo n.º 3
0
 public void IpV4OptionTimestampPointedIndexErrorTest()
 {
     Random random = new Random();
     IpV4Option option = new IpV4OptionTimestampOnly(0, random.NextByte(IpV4OptionTimestamp.PointedIndexMaxValue + 1, byte.MaxValue + 1));
     Assert.IsNotNull(option);
     Assert.Fail();
 }
Ejemplo n.º 4
0
 public void IpV4OptionTimestampOverflowErrorTest()
 {
     Random random = new Random();
     IpV4Option option = new IpV4OptionTimestampOnly(random.NextByte(IpV4OptionTimestamp.OverflowMaxValue + 1, byte.MaxValue + 1), 0);
     Assert.IsNotNull(option);
     Assert.Fail();
 }