/// <summary>
 /// True iff the options values is equal.
 /// </summary>
 protected override bool EqualValues(IpV4OptionTimestamp other)
 {
     return TimedRoute.SequenceEqual(((IpV4OptionTimestampAndAddress)other).TimedRoute);
 }
 /// <summary>
 /// Compares the values of the options.
 /// </summary>
 protected override bool EqualValues(IpV4OptionTimestamp other)
 {
     return Timestamps.SequenceEqual(((IpV4OptionTimestampOnly)other).Timestamps);
 }
示例#3
0
        public static IEnumerable <string> GetWiresharkSubfieldStrings(this IpV4Option option)
        {
            switch (option.OptionType)
            {
            case IpV4OptionType.EndOfOptionList:
            case IpV4OptionType.NoOperation:
            case IpV4OptionType.StreamIdentifier:
            case IpV4OptionType.RouterAlert:
            case IpV4OptionType.QuickStart:
                break;

            case IpV4OptionType.LooseSourceRouting:
            case IpV4OptionType.StrictSourceRouting:
            case IpV4OptionType.RecordRoute:
                IpV4OptionRoute routeOption = (IpV4OptionRoute)option;
                yield return("Pointer: " + (routeOption.PointedAddressIndex * 4 + 4));

                for (int i = 0; i != routeOption.Route.Count; ++i)
                {
                    yield return(routeOption.Route[i] + (routeOption.PointedAddressIndex == i ? " <- (current)" : string.Empty));
                }
                break;

            case IpV4OptionType.InternetTimestamp:
                IpV4OptionTimestamp timestampOption = (IpV4OptionTimestamp)option;
                if (timestampOption.CountTimestamps == 0)
                {
                    break;
                }

                yield return("Pointer: " + (timestampOption.PointedIndex * 4 + 5));

                yield return("Overflow: " + timestampOption.Overflow);

                switch (timestampOption.TimestampType)
                {
                case IpV4OptionTimestampType.TimestampOnly:
                    yield return("Flag: Time stamps only");

                    IpV4OptionTimestampOnly timestampOnlyOption = (IpV4OptionTimestampOnly)option;
                    foreach (IpV4TimeOfDay timeOfDay in timestampOnlyOption.Timestamps)
                    {
                        yield return("Time stamp = " + timeOfDay.MillisecondsSinceMidnightUniversalTime);
                    }
                    break;

                case IpV4OptionTimestampType.AddressAndTimestamp:
                    yield return("Flag: Time stamp and address");

                    IpV4OptionTimestampAndAddress timestampAndAddressOption = (IpV4OptionTimestampAndAddress)option;
                    foreach (IpV4OptionTimedAddress timedAddress in timestampAndAddressOption.TimedRoute)
                    {
                        yield return("Address = " + timedAddress.Address + ", " +
                                     "time stamp = " + timedAddress.TimeOfDay.MillisecondsSinceMidnightUniversalTime);
                    }
                    break;

                case IpV4OptionTimestampType.AddressPrespecified:
                    yield return("Flag: Time stamps for prespecified addresses");

                    IpV4OptionTimestampAndAddress timestampPrespecifiedOption = (IpV4OptionTimestampAndAddress)option;
                    foreach (IpV4OptionTimedAddress timedAddress in timestampPrespecifiedOption.TimedRoute)
                    {
                        yield return(string.Format("Address = {0}, time stamp = {1}",
                                                   timedAddress.Address,
                                                   timedAddress.TimeOfDay.MillisecondsSinceMidnightUniversalTime));
                    }
                    break;

                default:
                    throw new InvalidOperationException("Illegal timestamp type " + timestampOption.TimestampType);
                }
                break;

// ReSharper disable RedundantCaseLabel
            case IpV4OptionType.BasicSecurity:
// ReSharper restore RedundantCaseLabel
            default:
                if (typeof(IpV4OptionType).GetEnumValues <IpV4OptionType>().Contains(option.OptionType))
                {
                    throw new InvalidOperationException("Invalid option type " + option.OptionType);
                }
                break;
            }
        }