Check UDP protocol and TCP protocol

1, UDP header of 8 bytes, a source port, a destination port, a length (in bytes) and the checksum

UDP checksum to add 12B pseudo-header, the dummy header 5 field, a source IP (4B), the target IP (4B), all-0 field (. IB), the value of the IP header protocol field (. IB), UDP user data packet length (2B).

Then 16 as a group, as a group 2B i.e., if the dummy UDP user datagram header + a odd number of bytes (i.e. the data portion of the UDP datagram is the odd number of bytes) so that a full complement 0 byte (this byte is not sent, the pseudo-header is not transmitted).

 

Using a binary code anti sum, this sum is not determined once and for all, is seeking two lines two lines.

Anti-sum binary code and general summation are no different, mainly high if overflow, add 1 to it at the lowest position.

When calculating the checksum, will be written with all zeros in the first checksum field, the final result is the sum of the binary one inversion code into the checksum field. On the receiving side, also coupled with the pseudo-header and a stuffing byte, the checksum is calculated, if no mistakes, it should be 1. Otherwise, it means all go wrong.

Dummy header sender and recipient are the same.

TCP and UDP checksum is the same way, the checksum field is 2B, the first to write full-0, and then add the pseudo-header,

IP addresses are 32-bit 4B, IPv6 addresses are 128

Pseudo-header is 12 bytes, five fields, a source IP (4B) + target IP (4B) + all-0 (1B) + protocol (TCP is 6) (1B) + the length of the TCP data (the header section + data section)

Guess you like

Origin blog.csdn.net/shen19960603/article/details/94750223