/// <summary> /// Create a new time stamp option. /// </summary> /// <param name="option"> /// The option to parse. /// </param> /// <exception cref="ArgumentNullException"> /// The option argument is null. /// </exception> /// <exception cref="ArgumentException"> /// The option argument is not a timestamp option. /// </exception> public IpV4TimeStampOption(IpV4Option option) { if (option == null) { throw new ArgumentNullException("option"); } if (option.OptionType != IpV4OptionNumber.InternetTimestamp) { throw new ArgumentException("The option passed was not compatible with this class. This class accepts timestamp options only", "option"); } // extract the pointer m_pointer = (byte)option.Data[0]; // extract the overflow field m_overflow = (byte)((option.Data[1] & 0xf0) >> 4); // extract the type m_type = (IpV4TimestampType)(option.Data[1] & 0xf); // calculate how many fields there are and allocate space int numberStamps = (option.Data.Length - 2) / 4; if (m_type == IpV4TimestampType.TimestampAndAddress) { numberStamps /= 2; m_addressstamps = new IPAddress[numberStamps]; } m_timestamps = new uint[numberStamps]; // extract the time stamps and addresses for (int i = 0; i < numberStamps; i++) { if (m_type == IpV4TimestampType.TimestampAndAddress) { uint address = BitConverter.ToUInt32(option.Data, (i * 8) + 2); m_addressstamps[i] = new IPAddress((long)address); m_timestamps[i] = BitConverter.ToUInt32(option.Data, (i * 8) + 6); } else { m_timestamps[i] = BitConverter.ToUInt32(option.Data, (i * 4) + 2); } } }
/// <summary> /// Create a new time stamp option. /// </summary> /// <param name="option"> /// The option to parse. /// </param> /// <exception cref="ArgumentNullException"> /// The option argument is null. /// </exception> /// <exception cref="ArgumentException"> /// The option argument is not a timestamp option. /// </exception> public IpV4TimeStampOption (IpV4Option option) { if (option == null) { throw new ArgumentNullException ("option"); } if (option.OptionType != IpV4OptionNumber.InternetTimestamp) { throw new ArgumentException ("The option passed was not compatible with this class. This class accepts timestamp options only", "option"); } // extract the pointer m_pointer = (byte)option.Data[0]; // extract the overflow field m_overflow = (byte)((option.Data[1] & 0xf0) >> 4); // extract the type m_type = (IpV4TimestampType)(option.Data[1] & 0xf); // calculate how many fields there are and allocate space int numberStamps = (option.Data.Length - 2) / 4; if (m_type == IpV4TimestampType.TimestampAndAddress) { numberStamps /= 2; m_addressstamps = new IPAddress[numberStamps]; } m_timestamps = new uint[numberStamps]; // extract the time stamps and addresses for (int i = 0; i < numberStamps; i++) { if (m_type == IpV4TimestampType.TimestampAndAddress) { uint address = BitConverter.ToUInt32 (option.Data, (i * 8) + 2); m_addressstamps[i] = new IPAddress ((long)address); m_timestamps[i] = BitConverter.ToUInt32 (option.Data, (i * 8) + 6); } else { m_timestamps[i] = BitConverter.ToUInt32 (option.Data, (i * 4) + 2); } } }