TCPIP:UDP / TCPチェックサム

UDP / TCPチェックサム

1Content表

インターネットチェックサム

1の補数和

UDP / TCPチェックサム

 

2Internetチェックサム

(1)チェックサムさに隣接オクテットは、16ビットを形成するために対にされます

整数、およびこれらの16ビット整数の1の補数和が形成されています。

(2)チェックサムを生成するために、チェックサムフィールド自体はクリアされ、

16ビットの1の補数和は当該オクテットにわたって計算され、この合計の1の補数は、チェックサムフィールドに置かれます。

(3)チェックサムを確認するには、1の補数の合計は、チェックサムフィールドを含め、オクテットの同じセットにわたって計算されます。結果は、すべて1ビット(1の補数演算で-0)である場合、チェックが成功しました。



31の補数和

データのブロックのチェックサムはブロックの16ビットの合計の1の補数の補数です。チェックサムは、データのブロックに含まれている場合は、データの新しいブロックは、そのチェックサムはゼロになります。これは、チェックサムは、データグラムの送信中にエラー検出のために使用される方法です。

例として、データのブロックを考慮してください。

0x23fb

+ 0x34c0

+ 0xa090

+ 0xbcaf

+ 0xfc05

-----------

0x2b1ff

16ビットの1の補数和を計算するために、過剰の桁2つのニーズが最下位の16ビットに戻って追加されます。

0xb1ff

+ 0x2の

-----------

0xb201

これの補数は0x4dfeです。これは、データのブロックのチェックサムです。

なお:サム(サム+データ)= 0

私たちは、チェックサムフィールドを含むデータのブロックを送信した場合に何ビットのエラーがないのであれば、受信機は0のチェックサムが表示されるはずです。



4UDP / TCPチェックサム

 

Although the basics for calculating the UDP checksum are similar to the general Internet checksum (the one’s complement of the one’s complement sum of 16-bit words), there are two small special details.

First, the length of the UDP datagram can be an odd number of bytes, whereas the checksum algorithm adds 16-bit words (always an even number of bytes). The procedure for UDP is to append a (virtual) pad byte of 0 to the end of odd-length datagrams, just for the checksum computation and verification.

The second detail is that UDP (as well as TCP) computes its checksum over a 12-byte pseudo-header derived from fields in the IPv4 header or a 40-byte pseudo-header derived from fields in the IPv6 header. This pseudo-header is also virtual and is used only for purposes of the checksum computation (at both the sender and the receiver). Its purpose is to let the UDP layer verify that the data has arrived at the correct destination (i.e., that IP has not accepted a misaddressed datagram, and that IP has not given UDP a datagram that is for another transport protocol).


The TCP Checksum field covers the TCP header and data and some fields in the IP header, using a pseudo-header computation similar to the one used with UDP. It is mandatory for this field to be calculated and stored by the sender, and then verified by the receiver.



5Reference

  1. https://tools.ietf.org/html/rfc1071

  2. http://www.cs.newpaltz.edu/~easwaran/CCN/Week5/Checksum.pdf

  3. Vol 1. TCP/IP Illustrated

 

おすすめ

転載: www.cnblogs.com/wordchao/p/11127637.html