snetzuloo.blogg.se

Ip header checksum calculator
Ip header checksum calculator




ip header checksum calculator

u_int8_t, u_int16_t, u_int32_t are unsigned 8-digit, 16-digit, 32-digit, respectively I would like to thank this senior LiZhanglin, whose program has given me a lot of help. An example, the original code of the following example is copied from the program of 51 single-chip microcomputer. Here if the IP header of the data packet is correct, then the calculation result is 0 (this is the meaning of the checksum, the sender fills in the checksum, the receiver calculates the checksum in it, if the result is 0, The IP header of the packet is correct) They are all treated as 16-bit values, add them one by one, and expand the odd-numbered bits to 16-bit values, add them to the sum, and then add the high 16-bits and the low 16-bits repeatedly to get a The 16-bit sum, and invert this sum bitwise. The calculation rules are the same as the sender.

ip header checksum calculator

The receiving end calculates the checksum, and the packet received by the receiving end has already been filled in with the checksum filled in by the sending end, this does not need to be changed. Invert it bitwise in binary (for example, a 4-bit value, 1010 bitwise inversion is 0101), and the number after bitwise inversion is the checksum of the sender, Fill this checksum into the checksum position of the IP header. If the high 16 is still not equal to 0 in the result of the sum, then the high 16 bits and the low 16 bits are added together. Get such a sum, and then add the high 16 bits and low 16 bits of the sum (32-bit value). The result is stored in a 32-bit variable if the IP header is a special type packet, the number of bytes is not 20 (maybe 21, 23, 27 who knows, it is possible), it is left with an odd bit (it is an 8-bit The value of) is expanded into a 16-bit number (filled with 8-bit 0 at the back), and the new 16-bit number is added to the front sum. If it is not a special type of packet, the length of the IP header is 20 bytes, and the IP checksum is to calculate the checksum of these 20 bits TCP checksum, TCP checksum is not only To check the 20-bit TCP header and the data behind the TCP header, add two IPs (four bytes per IP), sixteen-bit TCP protocol (0x0006), TCP header and A pseudo header composed of the number of bytes in the data part (that is, the length of the TCP header and the data added together).īefore calculation, first set the checksum of the IP header to 0, and then treat the 20-byte IP header as 10 sixteen-bit values, and add each bit from the front (the bottom layer direction is front) to the back. The checksum of the IP header is relatively simple. First of all, on the concept of IP and TCP checksum






Ip header checksum calculator