Understanding of internet verification algorithms

Source: Internet
Author: User

It takes almost two weeks to verify the InternetAlgorithmI still don't quite understand. The Reference URL is as follows:

Introduction to http://blog.csdn.net/namelcx/article/details/6866720 TCP/IP checksum algorithm.
Checksum algorithm of http://www.cnblogs.com/tuyile006/archive/2006/12/06/583647.html IP packet)
Http://blog.csdn.net/max2008/article/details/1720706 IP packet checksum algorithm.
Http://phinecos.blog.51cto.com/1941821/368159 C ++ exercises (17th) --- Internet checksum Algorithm
Calculation Method of checksum in http://blog.csdn.net/jiangnanyouzi/article/details/3333486 TCP/IP.

Few people can understand the truth. For thisCodeI don't know. I don't understand it. I'm stupid!

 
Unsigned short checksum (unsigned short * Buf, int nword) {unsigned long sum; For (sum = 0; nword> 0; nword --) sum + = * Buf ++; sum = (sum> 16) + (sum & 0 xFFFF); sum + = (sum> 16); Return ~ SUM ;}

Especially in the last three or two rows, do you understand? Please leave a message. Thank you for sharing it!

1) sum = (sum> 16) // calculate the 16-bit height of sum.
 
2) (sum & 0 xFFFF); // The sum is 16 bits.
 
(1) 2) the possible carry produced by the formula addition is composed of the lower formula. If there is no carry, the result of> 16 is zero, which has no effect on the result.
 
Sum + = (sum> 16 );

Every 16-bit binary anticode is added to this end, but I still do not understand the http://blog.csdn.net/jiangnanyouzi/article/details/3333486 in this great god mentioned.

Unsigned short a [10] = {0x4500, 0x059a, 0x82b9, 0X4000, 0x3206, 0x4f79, 0xa66f, 0x08ee, 0xc0a8, 0x0126 };

Question 1: The first 16-bit ox4500 is understandable. 4 is IPv4 and 5 is the header length. Taking the 32-bit binary number as a counting unit, it indicates five 32-bit characters. The rest will not be expressed. What is the basis for this expression?

Question 2: It seems that the final result is 0 xFFFF. If not, isn't it?

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.