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); } }
public IpV4OptionTimestampAndAddress(IpV4OptionTimestampType timestampType, byte overflow, byte pointedIndex, IList <IpV4OptionTimedAddress> timedRoute) : base(timestampType, overflow, pointedIndex) { if (timestampType != IpV4OptionTimestampType.AddressAndTimestamp && timestampType != IpV4OptionTimestampType.AddressPrespecified) { throw new ArgumentException("Illegal timestamp type " + (object)timestampType, "timestampType"); } this._addressesAndTimestamps = IListExtensions.AsReadOnly <IpV4OptionTimedAddress>(timedRoute); }
/// <summary> /// Create the option by giving it all the data. /// </summary> /// <param name="timestampType">The timestamp option type.</param> /// <param name="overflow">The number of IP modules that cannot register timestamps due to lack of space. Maximum value is 15.</param> /// <param name="pointedIndex">The index in the timestamp that points to the for next timestamp.</param> /// <param name="timedRoute">The pairs of addresses and timestamps where each timestamp time passed since midnight UT.</param> public IpV4OptionTimestampAndAddress(IpV4OptionTimestampType timestampType, byte overflow, byte pointedIndex, IList<IpV4OptionTimedAddress> timedRoute) : base(timestampType, overflow, pointedIndex) { if (timestampType != IpV4OptionTimestampType.AddressAndTimestamp && timestampType != IpV4OptionTimestampType.AddressPrespecified) { throw new ArgumentException("Illegal timestamp type " + timestampType, "timestampType"); } _addressesAndTimestamps = timedRoute.AsReadOnly(); }
internal static IpV4OptionTimestampAndAddress Read(IpV4OptionTimestampType timestampType, byte overflow, byte pointedIndex, byte[] buffer, ref int offset, int numValues) { if (numValues % 2 != 0) { return((IpV4OptionTimestampAndAddress)null); } IpV4OptionTimedAddress[] optionTimedAddressArray = new IpV4OptionTimedAddress[numValues / 2]; for (int index = 0; index != numValues / 2; ++index) { optionTimedAddressArray[index] = new IpV4OptionTimedAddress(ByteArrayExtensions.ReadIpV4Address(buffer, ref offset, Endianity.Big), ByteArrayExtensions.ReadIpV4TimeOfDay(buffer, ref offset, Endianity.Big)); } return(new IpV4OptionTimestampAndAddress(timestampType, overflow, pointedIndex, optionTimedAddressArray)); }
internal static IpV4OptionTimestampAndAddress Read(IpV4OptionTimestampType timestampType, byte overflow, byte pointedIndex, byte[] buffer, ref int offset, int numValues) { if (numValues % 2 != 0) return null; IpV4OptionTimedAddress[] addressesAndTimestamps = new IpV4OptionTimedAddress[numValues / 2]; for (int i = 0; i != numValues / 2; ++i) { addressesAndTimestamps[i] = new IpV4OptionTimedAddress(buffer.ReadIpV4Address(ref offset, Endianity.Big), buffer.ReadIpV4TimeOfDay(ref offset, Endianity.Big)); } return new IpV4OptionTimestampAndAddress(timestampType, overflow, pointedIndex, addressesAndTimestamps); }
protected IpV4OptionTimestamp(IpV4OptionTimestampType timestampType, byte overflow, byte pointedIndex) : base(IpV4OptionType.InternetTimestamp) { if ((int)overflow > 15) { throw new ArgumentOutOfRangeException("overflow", (object)overflow, "Maximum value is " + (object)15); } if ((int)pointedIndex > 62) { throw new ArgumentOutOfRangeException("pointedIndex", (object)pointedIndex, "Maximum value is " + (object)62); } this._timestampType = timestampType; this._overflow = overflow; this._pointedIndex = pointedIndex; }
internal static IpV4OptionTimestampAndAddress Read(IpV4OptionTimestampType timestampType, byte overflow, byte pointedIndex, byte[] buffer, ref int offset, int numValues) { if (numValues % 2 != 0) { return(null); } IpV4OptionTimedAddress[] addressesAndTimestamps = new IpV4OptionTimedAddress[numValues / 2]; for (int i = 0; i != numValues / 2; ++i) { addressesAndTimestamps[i] = new IpV4OptionTimedAddress(buffer.ReadIpV4Address(ref offset, Endianity.Big), buffer.ReadIpV4TimeOfDay(ref offset, Endianity.Big)); } return(new IpV4OptionTimestampAndAddress(timestampType, overflow, pointedIndex, addressesAndTimestamps)); }
/// <summary> /// Create the option by giving it all the data. /// </summary> /// <param name="timestampType">The timestamp option type.</param> /// <param name="overflow">The number of IP modules that cannot register timestamps due to lack of space. Maximum value is 15.</param> /// <param name="pointedIndex">The index in the timestamp to points to the octet beginning the space for next timestamp. The timestamp area is considered full when the index points beyond the timestamps.</param> protected IpV4OptionTimestamp(IpV4OptionTimestampType timestampType, byte overflow, byte pointedIndex) : base(IpV4OptionType.InternetTimestamp) { if (overflow > OverflowMaxValue) { throw new ArgumentOutOfRangeException("overflow", overflow, "Maximum value is " + OverflowMaxValue); } if (pointedIndex > PointedIndexMaxValue) { throw new ArgumentOutOfRangeException("pointedIndex", pointedIndex, "Maximum value is " + PointedIndexMaxValue); } _timestampType = timestampType; _overflow = overflow; _pointedIndex = pointedIndex; }
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); } }
public static IpV4Option NextIpV4Option(this Random random, int maximumOptionLength) { if (maximumOptionLength == 0) { throw new ArgumentOutOfRangeException("maximumOptionLength", maximumOptionLength, "option length must be positive"); } if (maximumOptionLength >= IpV4OptionUnknown.OptionMinimumLength && random.Next(100) > 90) { return(random.NextIpV4OptionUnknown(maximumOptionLength)); } // TODO: Support MTU Probe, MTU Reply and CommercialSecurity. List <IpV4OptionType> impossibleOptionTypes = new List <IpV4OptionType> { IpV4OptionType.MaximumTransmissionUnitProbe, IpV4OptionType.MaximumTransmissionUnitReply, IpV4OptionType.CommercialSecurity, }; if (maximumOptionLength < IpV4OptionBasicSecurity.OptionMinimumLength) { impossibleOptionTypes.Add(IpV4OptionType.BasicSecurity); } if (maximumOptionLength < IpV4OptionRoute.OptionMinimumLength) { impossibleOptionTypes.Add(IpV4OptionType.LooseSourceRouting); impossibleOptionTypes.Add(IpV4OptionType.StrictSourceRouting); impossibleOptionTypes.Add(IpV4OptionType.RecordRoute); } if (maximumOptionLength < IpV4OptionStreamIdentifier.OptionLength) { impossibleOptionTypes.Add(IpV4OptionType.StreamIdentifier); } if (maximumOptionLength < IpV4OptionTimestamp.OptionMinimumLength) { impossibleOptionTypes.Add(IpV4OptionType.InternetTimestamp); } if (maximumOptionLength < IpV4OptionTraceRoute.OptionLength) { impossibleOptionTypes.Add(IpV4OptionType.TraceRoute); } if (maximumOptionLength < IpV4OptionQuickStart.OptionLength) { impossibleOptionTypes.Add(IpV4OptionType.QuickStart); } IpV4OptionType optionType = random.NextEnum <IpV4OptionType>(impossibleOptionTypes); switch (optionType) { case IpV4OptionType.EndOfOptionList: return(IpV4Option.End); case IpV4OptionType.NoOperation: return(IpV4Option.Nop); case IpV4OptionType.BasicSecurity: IpV4OptionSecurityProtectionAuthorities protectionAuthorities = IpV4OptionSecurityProtectionAuthorities.None; int protectionAuthorityLength = random.Next(maximumOptionLength - IpV4OptionBasicSecurity.OptionMinimumLength); if (protectionAuthorityLength > 0) { protectionAuthorities = random.NextEnum <IpV4OptionSecurityProtectionAuthorities>(); } return(new IpV4OptionBasicSecurity(random.NextEnum(IpV4OptionSecurityClassificationLevel.None), protectionAuthorities, (byte)(IpV4OptionBasicSecurity.OptionMinimumLength + protectionAuthorityLength))); case IpV4OptionType.LooseSourceRouting: case IpV4OptionType.StrictSourceRouting: case IpV4OptionType.RecordRoute: int numAddresses = random.Next((maximumOptionLength - IpV4OptionRoute.OptionMinimumLength) / 4 + 1); IpV4Address[] addresses = random.NextIpV4Addresses(numAddresses); byte pointedAddressIndex; if (random.NextBool()) { pointedAddressIndex = random.NextByte(IpV4OptionRoute.PointedAddressIndexMaxValue + 1); } else { pointedAddressIndex = random.NextByte(10); } switch (optionType) { case IpV4OptionType.LooseSourceRouting: return(new IpV4OptionLooseSourceRouting(addresses, pointedAddressIndex)); case IpV4OptionType.StrictSourceRouting: return(new IpV4OptionStrictSourceRouting(addresses, pointedAddressIndex)); case IpV4OptionType.RecordRoute: return(new IpV4OptionRecordRoute(pointedAddressIndex, addresses)); default: throw new InvalidOperationException("optionType = " + optionType); } case IpV4OptionType.StreamIdentifier: return(new IpV4OptionStreamIdentifier(random.NextUShort())); case IpV4OptionType.InternetTimestamp: IpV4OptionTimestampType timestampType = random.NextEnum <IpV4OptionTimestampType>(); byte overflow = random.NextByte(IpV4OptionTimestamp.OverflowMaxValue + 1); byte pointedIndex; if (random.NextBool()) { pointedIndex = random.NextByte(IpV4OptionTimestamp.PointedIndexMaxValue + 1); } else { pointedIndex = random.NextByte(10); } switch (timestampType) { case IpV4OptionTimestampType.TimestampOnly: int numTimestamps = random.Next((maximumOptionLength - IpV4OptionTimestamp.OptionMinimumLength) / 4 + 1); IpV4TimeOfDay[] timestamps = ((Func <IpV4TimeOfDay>)random.NextIpV4TimeOfDay).GenerateArray(numTimestamps); return(new IpV4OptionTimestampOnly(overflow, pointedIndex, timestamps)); case IpV4OptionTimestampType.AddressAndTimestamp: case IpV4OptionTimestampType.AddressPrespecified: int numPairs = random.Next((maximumOptionLength - IpV4OptionTimestamp.OptionMinimumLength) / 8 + 1); IpV4OptionTimedAddress[] pairs = new IpV4OptionTimedAddress[numPairs]; for (int i = 0; i != numPairs; ++i) { pairs[i] = new IpV4OptionTimedAddress(random.NextIpV4Address(), random.NextIpV4TimeOfDay()); } return(new IpV4OptionTimestampAndAddress(timestampType, overflow, pointedIndex, pairs)); default: throw new InvalidOperationException("timestampType = " + timestampType); } case IpV4OptionType.TraceRoute: return(new IpV4OptionTraceRoute(random.NextUShort(), random.NextUShort(), random.NextUShort(), random.NextIpV4Address())); case IpV4OptionType.RouterAlert: return(new IpV4OptionRouterAlert(random.NextUShort())); case IpV4OptionType.QuickStart: return(new IpV4OptionQuickStart(random.NextEnum <IpV4OptionQuickStartFunction>(), random.NextByte(IpV4OptionQuickStart.RateMaximumValue + 1), random.NextByte(), random.NextUInt() & 0x3FFFFFFF)); default: throw new InvalidOperationException("optionType = " + optionType); } }
/// <summary> /// Create the option by giving it all the data. /// </summary> /// <param name="timestampType">The timestamp option type.</param> /// <param name="overflow">The number of IP modules that cannot register timestamps due to lack of space. Maximum value is 15.</param> /// <param name="pointedIndex">The index in the timestamp that points to the for next timestamp.</param> /// <param name="timedRoute">The pairs of addresses and timestamps where each timestamp time passed since midnight UT.</param> public IpV4OptionTimestampAndAddress(IpV4OptionTimestampType timestampType, byte overflow, byte pointedIndex, params IpV4OptionTimedAddress[] timedRoute) : this(timestampType, overflow, pointedIndex, (IList<IpV4OptionTimedAddress>)timedRoute) { }
public IpV4OptionTimestampAndAddress(IpV4OptionTimestampType timestampType, byte overflow, byte pointedIndex, params IpV4OptionTimedAddress[] timedRoute) : this(timestampType, overflow, pointedIndex, (IList <IpV4OptionTimedAddress>)timedRoute) { }