Beispiel #1
0
 /// <summary>
 /// ICMP layers are equal if they have the same message type, code, checksum, variable and payload.
 /// </summary>
 public bool Equals(IcmpLayer other)
 {
     return(other != null &&
            MessageType == other.MessageType && CodeValue == other.CodeValue &&
            Checksum == other.Checksum &&
            Variable == other.Variable &&
            EqualPayload(other));
 }
Beispiel #2
0
 public bool Equals(IcmpLayer other)
 {
     if (other != null && this.MessageType == other.MessageType && (int)this.CodeValue == (int)other.CodeValue)
     {
         ushort?checksum1 = this.Checksum;
         ushort?checksum2 = other.Checksum;
         if (((int)checksum1.GetValueOrDefault() != (int)checksum2.GetValueOrDefault() ? 0 : (checksum1.HasValue == checksum2.HasValue ? 1 : 0)) != 0 && (int)this.Variable == (int)other.Variable)
         {
             return(this.EqualPayload(other));
         }
     }
     return(false);
 }
 /// <summary>
 /// True iff the OriginateTimestamp, ReceiveTimestamp and the TransmitTimestamp fields are equal.
 /// </summary>
 protected override sealed bool EqualPayload(IcmpLayer other)
 {
     return EqualPayload(other as IcmpTimestampLayer);
 }
Beispiel #4
0
 /// <summary>
 /// True iff the ICMP payload is equal to the other ICMP payload.
 /// </summary>
 protected virtual bool EqualPayload(IcmpLayer other)
 {
     return(true);
 }
 /// <summary>
 /// True iff the Entries are equal to the other ICMP entries.
 /// </summary>
 protected override bool EqualPayload(IcmpLayer other)
 {
     return EqualPayload(other as IcmpRouterAdvertisementLayer);
 }
 protected override sealed bool EqualPayload(IcmpLayer other)
 {
     return(this.EqualPayload(other as IcmpTimestampLayer));
 }
Beispiel #7
0
 /// <summary>
 /// True iff the ICMP payload is equal to the other ICMP payload.
 /// </summary>
 protected virtual bool EqualPayload(IcmpLayer other)
 {
     return true;
 }
Beispiel #8
0
 /// <summary>
 /// ICMP layers are equal if they have the same message type, code, checksum, variable and payload.
 /// </summary>
 public bool Equals(IcmpLayer other)
 {
     return other != null &&
            MessageType == other.MessageType && CodeValue == other.CodeValue &&
            Checksum == other.Checksum &&
            Variable == other.Variable &&
            EqualPayload(other);
 }
        public static IEnumerable<ILayer> NextIcmpPayloadLayers(this Random random, IcmpLayer icmpLayer)
        {
            IEnumerable<ILayer> icmpPayloadLayers = new List<ILayer>();
            switch (icmpLayer.MessageType)
            {
                case IcmpMessageType.DestinationUnreachable:
                case IcmpMessageType.TimeExceeded:
                case IcmpMessageType.ParameterProblem:
                case IcmpMessageType.SourceQuench:
                case IcmpMessageType.Redirect:
                case IcmpMessageType.SecurityFailures:
                    icmpPayloadLayers = IEnumerableExtensions.Concat(icmpPayloadLayers, random.NextIpV4Layer(), random.NextPayloadLayer(IcmpIpV4HeaderPlus64BitsPayloadDatagram.OriginalDatagramPayloadLength));
                    break;
                case IcmpMessageType.ConversionFailed:
                    IpV4Layer icmpIpV4Layer = random.NextIpV4Layer();
                    icmpPayloadLayers = IEnumerableExtensions.Concat(icmpPayloadLayers, icmpIpV4Layer);
                    if (icmpLayer.MessageTypeAndCode == IcmpMessageTypeAndCode.ConversionFailedUnsupportedTransportProtocol)
                    {
                        icmpPayloadLayers =
                            IEnumerableExtensions.Concat(icmpPayloadLayers, random.NextPayloadLayer(
                                IcmpConversionFailedDatagram.OriginalDatagramLengthForUnsupportedTransportProtocol -
                                icmpIpV4Layer.Length));
                    }
                    else
                    {
                        switch (icmpIpV4Layer.Protocol)
                        {
                            case IpV4Protocol.Udp:
                                icmpPayloadLayers = IEnumerableExtensions.Concat(icmpPayloadLayers, random.NextUdpLayer(),
                                                                             random.NextPayloadLayer(random.Next(100)));
                                break;

                            case IpV4Protocol.Tcp:
                                icmpPayloadLayers = IEnumerableExtensions.Concat(icmpPayloadLayers, random.NextTcpLayer(),
                                                                             random.NextPayloadLayer(random.Next(100)));
                                break;

                            default:
                                icmpPayloadLayers = IEnumerableExtensions.Concat(icmpPayloadLayers, random.NextPayloadLayer(random.Next(200)));

                                break;
                        }
                    }
                    break;

                case IcmpMessageType.Echo:
                case IcmpMessageType.EchoReply:
                case IcmpMessageType.Timestamp:
                case IcmpMessageType.TimestampReply:
                case IcmpMessageType.InformationRequest:
                case IcmpMessageType.InformationReply:
                case IcmpMessageType.RouterAdvertisement:
                case IcmpMessageType.RouterSolicitation:
                case IcmpMessageType.AddressMaskRequest:
                case IcmpMessageType.AddressMaskReply:
                case IcmpMessageType.TraceRoute:
                case IcmpMessageType.DomainNameRequest:
                    break;

                case IcmpMessageType.DomainNameReply:
                default:
                    throw new InvalidOperationException("Invalid icmpMessageType " + icmpLayer.MessageType);
            }
            return icmpPayloadLayers;
        }
 /// <summary>
 /// True iff the address mask is equal to the other address mask.
 /// </summary>
 protected sealed override bool EqualPayload(IcmpLayer other)
 {
     return(EqualPayload(other as IcmpAddressMaskRequestLayer));
 }
 /// <summary>
 /// True iff the Entries are equal to the other ICMP entries.
 /// </summary>
 protected override bool EqualPayload(IcmpLayer other)
 {
     return(EqualPayload(other as IcmpRouterAdvertisementLayer));
 }
 /// <summary>
 /// True iff the address mask is equal to the other address mask.
 /// </summary>
 protected override sealed bool EqualPayload(IcmpLayer other)
 {
     return EqualPayload(other as IcmpAddressMaskRequestLayer);
 }