请输入您要查询的百科知识:

 

词条 IPv4 header checksum
释义

  1. Calculation

  2. Example: calculating an IPv4 header checksum

  3. Example: verifying an IPv4 header checksum

  4. See also

  5. External links

  6. References

{{cleanup HTML|date=February 2019}}

The IPv4 header checksum is a simple checksum used in version 4 of the Internet Protocol (IPv4) to protect the header of IPv4 data packets against data corruption. This checksum is calculated only for the header bytes, is 16 bits long and is a part of the IP packet header.

Calculation

RFC 791 defines the checksum calculation:[1]

The checksum field is the 16-bit one's complement of the one's complement sum of all 16-bit words in the header. For purposes of computing the checksum, the value of the checksum field is zero.

The result of summing the entire IP header, including checksum, should be zero if there is no corruption. At each hop, the checksum is recalculated and the packet will be discarded upon checksum mismatch. The router must adjust the checksum if it changes part of the IP header (such as when decrementing the TTL.)[2]

The IPv6 protocol lacks a header checksum: its designers considered that the whole-packet link-layer checksumming provided in layer 2 transports such as PPP and Ethernet, combined with the use of checksums in upper-layer protocols such as TCP and UDP, were sufficient to make a separate header checksum unnecessary.[3]

Example: calculating an IPv4 header checksum

Take the following truncated excerpt of an IPv4 packet. The header is shown in bold and the checksum is underlined.


4500 0073 0000 4000 4011 b861 c0a8 0001

c0a8 00c7 0035 e97c 005f 279f 1e4b 8180

For one's complement addition, each time a carry occurs, we must add a 1 to the sum.[4] A carry check and correction can be performed with each addition or as a post-process after all additions. If another carry is generated by the correction, another 1 is added to the sum.

To calculate the checksum, we can first calculate the sum of each 16 bit value within the header, skipping only the checksum field itself. Note that these values are in hexadecimal notation.

4500 + 0073 + 0000 + 4000 + 4011 + c0a8 + 0001 + c0a8 + 00c7 = 2479C

The first digit is the carry count and is added to the sum:

2 + 479C = 479E (if another carry is generated by this addition, another 1 must be added to the sum)

To obtain the checksum we take the one's complement of this result: B861 (as shown underlined in the original IP packet header).

Example: verifying an IPv4 header checksum

When verifying a checksum, the same procedure is used as above, except that the original header checksum is not omitted.

4500 + 0073 + 0000 + 4000 + 4011 + b861 + c0a8 + 0001 + c0a8 + 00c7 = 2fffd

Add the carry bits:

fffd + 2 = ffff

Taking the ones' complement (flipping every bit) yields 0000, which indicates that no error is detected.

IP header checksum does not check for the correct order of 16 bit values within the header.

See also

  • Header check sequence
  • Internet Protocol, version 4
  • Checksum

External links

  • IP Datagram General Format
  • Header Checksum

References

1. ^{{cite IETF| title = Internet Protocol DARPA Internet program protocol specification| rfc = 791| std = 5| sectionname = Internet Header Format| page = 14|date=September 1981| publisher = IETF| accessdate = 2009-10-27}}
2. ^{{cite IETF| title = Requirements for IP Version 4 Routers| rfc = 1812| sectionname = Header Checksum| section = 4.2.2.5| page = 44| editor-last = Baker| editor-first = Fred| editor-link = Fred Baker (IETF chair)|date=June 1995| publisher = IETF| accessdate = 2009-10-27}}
3. ^{{cite web|url=http://www.cisco.com/web/about/ac123/ac147/archived_issues/ipj_9-3/ipv6_internals.html|title=IPv6 Internals|author= Iljitsch van Beijnum|date=September 2006|publisher=Cisco}}
4. ^{{cite web |url=http://mathforum.org/library/drmath/view/54379.html |title=Compute 16-bit One's Complement Sum |access-date=2019-02-07}}

2 : Error detection and correction|IPv4

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/9/24 10:29:16