/// <summary>
        /// Determine if the transport layer checksum is valid
        /// </summary>
        /// <param name="option">
        /// A <see cref="TransportChecksumOption" />
        /// </param>
        /// <returns>
        /// A <see cref="bool" />
        /// </returns>
        public virtual bool IsValidChecksum(TransportChecksumOption option)
        {
            var dataToChecksum = ((IPPacket)ParentPacket).PayloadPacket.BytesSegment;

            if (dataToChecksum.Offset + dataToChecksum.Length > dataToChecksum.BytesLength)
            {
                return(false);
            }


            var bytes = option == TransportChecksumOption.IncludePseudoIPHeader
                ? ((IPPacket)ParentPacket).GetPseudoIPHeader(dataToChecksum.Length)
                : new byte[0];

            var onesSum = ChecksumUtils.OnesSum(dataToChecksum, bytes);

            Log.DebugFormat("option: {0}, byteArrayCombination.Length {1}",
                            option,
                            bytes.Length);

            const int expectedOnesSum = 0xFFFF;

            Log.DebugFormat("onesSum {0} expected {1}",
                            onesSum,
                            expectedOnesSum);

            return(onesSum == expectedOnesSum);
        }
Exemple #2
0
 public virtual bool IsValidChecksum(TransportChecksumOption option)
 {
     byte[] bytes = ((IpPacket)this.ParentPacket).PayloadPacket.Bytes;
     if (option == TransportChecksumOption.AttachPseudoIPHeader)
     {
         bytes = ((IpPacket)this.ParentPacket).AttachPseudoIPHeader(bytes);
     }
     return(ChecksumUtils.OnesSum(bytes) == 0xffff);
 }
        public virtual bool IsValidTransportLayerChecksum(bool pseudoIPHeader)
        {
            byte[] upperLayer = IPData;
            if (pseudoIPHeader)
            {
                upperLayer = AttachPseudoIPHeader(upperLayer);
            }
            int onesSum = ChecksumUtils.OnesSum(upperLayer);

            return(onesSum == 0xFFFF);
        }
        /// <summary>
        /// Determine if the transport layer checksum is valid
        /// </summary>
        /// <param name="option">
        /// A <see cref="TransportChecksumOption"/>
        /// </param>
        /// <returns>
        /// A <see cref="System.Boolean"/>
        /// </returns>
        public virtual bool IsValidChecksum(TransportChecksumOption option)
        {
            var upperLayer = ((IpPacket)ParentPacket).PayloadPacket.Bytes;

            if (option == TransportChecksumOption.AttachPseudoIPHeader)
            {
                upperLayer = ((IpPacket)ParentPacket).AttachPseudoIPHeader(upperLayer);
            }

            var       onesSum         = ChecksumUtils.OnesSum(upperLayer);
            const int expectedOnesSum = 0xffff;

            return(onesSum == expectedOnesSum);
        }
Exemple #5
0
        /// <summary>
        ///     Determine if the transport layer checksum is valid
        /// </summary>
        /// <param name="option">
        ///     A <see cref="TransportChecksumOption" />
        /// </param>
        /// <returns>
        ///     A <see cref="System.Boolean" />
        /// </returns>
        public virtual bool IsValidChecksum(TransportChecksumOption option)
        {
            var upperLayer = ((IpPacket)this.ParentPacket).PayloadPacket.Bytes;

            log.DebugFormat("option: {0}, upperLayer.Length {1}", option, upperLayer.Length);

            if (option == TransportChecksumOption.AttachPseudoIPHeader)
            {
                upperLayer = ((IpPacket)this.ParentPacket).AttachPseudoIPHeader(upperLayer);
            }

            var       onesSum         = ChecksumUtils.OnesSum(upperLayer);
            const int expectedOnesSum = 0xffff;

            log.DebugFormat("onesSum {0} expected {1}", onesSum, expectedOnesSum);

            return(onesSum == expectedOnesSum);
        }
        /// <summary>
        /// Determine if the transport layer checksum is valid
        /// </summary>
        /// <param name="option">
        /// A <see cref="TransportChecksumOption"/>
        /// </param>
        /// <returns>
        /// A <see cref="System.Boolean"/>
        /// </returns>
        public virtual Boolean IsValidChecksum(TransportChecksumOption option)
        {
            var dataToChecksum = ((IpPacket)ParentPacket).PayloadPacket.BytesHighPerformance;

            var bytes = option == TransportChecksumOption.IncludePseudoIPHeader
                    ? ((IpPacket)ParentPacket).GetPseudoIPHeader(dataToChecksum.Length)
                    : new byte[0];

            var onesSum = ChecksumUtils.OnesSum(dataToChecksum, bytes);

            log.DebugFormat("option: {0}, byteArrayCombination.Length {1}",
                            option, bytes.Length);

            const Int32 expectedOnesSum = 0xffff;

            log.DebugFormat("onesSum {0} expected {1}",
                            onesSum,
                            expectedOnesSum);

            return(onesSum == expectedOnesSum);
        }