# IP/IGMP/UDP checksum Algorithm

Source: Internet
Author: User

IP/IGMP/UDP checksum algorithm and algorithm: the IP, IGMP, UDP, and TCP packet headers both have validation fields, and their algorithms are the same. The range of IP, IGMP, UDP, and TCP checksum: only the length of the packet header. When sending data, in order to calculate the packet inspection. Perform the following steps: 1. Set the checksum field to 0; 2. Regard the data to be verified as a number in the unit of 16 bits, sum the binary anticode in sequence (the overflow bit must be added to the low position); 3. Save the obtained result to the checksum field. When receiving data, the test and calculation of data packets are relatively simple. follow the steps below: 1. Regard the header as a 16-bit number, and perform the binary anticode summation in turn, including the checksum field; 2. Check whether the calculated checksum is 0. 3. If the value is 0, the checksum is correct. Otherwise, the checksum is incorrect. The protocol stack must discard this packet. Note: Both of the above schemes can correctly implement the checksum field. The result of first obtaining the inverse sum is the same as that of first seeking and then obtaining the inverse result. Note: The overflow bits must be added to the low level for the above two implementation schemes, such as while (cksum> 16) {cksum = (cksum> 16) + (cksum & 0 xffff );}. When the packet header size is transferred, the actual packet header size is enough. The advantage of using back-code Summation for checksum is that it does not depend on the system as a large-end or small-end. That is, no matter whether you are a sender's computer or receiver, do not call htons or ntohs. You can directly obtain the correct result through the above algorithm. To solve this problem, you can give an example by yourself. When we use the reverse code to sum up, we exchange the 16-digit byte order and get the same result, but the byte order is also exchanged accordingly; however, if you use the source code or the supplementary code to sum up, the result may be different.

Related Keywords:

### 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.