public int ComputeTransportLayerChecksum(int checksumOffset, bool update, bool pseudoIPHeader) { // copy the tcp section with data byte[] dataToChecksum = IPData; // reset the checksum field (checksum is calculated when this field is // zeroed) ArrayHelper.insertLong(dataToChecksum, 0, checksumOffset, 2); if (pseudoIPHeader) { dataToChecksum = AttachPseudoIPHeader(dataToChecksum); } // compute the one's complement sum of the tcp header int cs = ChecksumUtils.OnesComplementSum(dataToChecksum); if (update) { SetTransportLayerChecksum(cs, checksumOffset); } return(cs); }
/// <summary> Computes the UDP checksum, optionally updating the UDP checksum header. /// /// </summary> /// <param name="update">Specifies whether or not to update the UDP checksum header /// after computing the checksum. A value of true indicates the /// header should be updated, a value of false indicates it should /// not be updated. /// </param> /// <returns> The computed UDP checksum. /// </returns> public int ComputeUDPChecksum(bool update) { if (IPVersion != IPVersions.IPv4) { throw new System.NotImplementedException("IPVersion of " + IPVersion + " is unrecognized"); } // copy the udp section with data byte[] udp = IPData; // reset the checksum field (checksum is calculated when this field is // zeroed) ArrayHelper.insertLong(udp, 0, UDPFields_Fields.UDP_CSUM_POS, UDPFields_Fields.UDP_CSUM_LEN); //pseudo ip header should be attached to the udp+data udp = AttachPseudoIPHeader(udp); // compute the one's complement sum of the udp header int cs = ChecksumUtils.OnesComplementSum(udp); if (update) { UDPChecksum = cs; } return(cs); }
/// <summary> Sets the urgent pointer. /// /// </summary> /// <param name="pointer">The urgent pointer value. /// </param> public void setUrgentPointer(int pointer) { ArrayHelper.insertLong(Bytes, pointer, _ipOffset + TCPFields_Fields.TCP_URG_POS, TCPFields_Fields.TCP_URG_LEN); _urgentPointerSet = false; }
/// <summary> Sets the IP header checksum.</summary> protected internal virtual void SetChecksum(int cs, int checkSumOffset) { ArrayHelper.insertLong(Bytes, cs, checkSumOffset, 2); }