Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Transmission Control Protocol
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===TCP checksum for IPv4=== When TCP runs over [[IPv4]], the method used to compute the checksum is defined as follows:{{sfn|RFC 9293}} <blockquote> ''The checksum field is the 16-bit ones' complement of the ones' complement sum of all 16-bit words in the header and text. The checksum computation needs to ensure the 16-bit alignment of the data being summed. If a segment contains an odd number of header and text octets, alignment can be achieved by padding the last octet with zeros on its right to form a 16-bit word for checksum purposes. The pad is not transmitted as part of the segment. While computing the checksum, the checksum field itself is replaced with zeros.''</blockquote> In other words, after appropriate padding, all 16-bit words are added using [[end-around carry|ones' complement arithmetic]]. The sum is then bitwise complemented and inserted as the checksum field. A pseudo-header that mimics the IPv4 packet header used in the checksum computation is as follows: {{APHD|start|title=TCP pseudo-header for checksum computation (IPv4)}} {{APHD|0|bits1=32|background1=mistyrose|field1=Source address}} {{APHD|4|bits1=32|background1=mistyrose|field1=Destination address}} {{APHD|8|bits1=8|bits2=8|bits3=16|background1=mistyrose|background2=mistyrose|background3=mistyrose|field1=Zeroes|field2=Protocol|value2=6|field3=TCP length}} {{APHD|12|bits1=16|bits2=16|field1=Source port|field2=Destination port}} {{APHD|16|bits1=32|field1=Sequence number}} {{APHD|20|bits1=32|field1=Acknowledgement number}} {{APHD|24|bits1=4|bits2=4|bits3=8|bits4=16|field1=Data offset|field2=Reserved|field3=Flags|field4=Window}} {{APHD|28|bits1=16|background1=lightpink|field1=Checksum|bits2=16|field2=Urgent pointer}} {{APHD|32|bits1=32|background1=linen|field1=(Options)}} {{APHD|36|bits1=0|field1=Data}} {{APHD|end}} The checksum is computed over the following fields: ;{{APHD|def|name=Source address|length=32 bits|text=The source address in the IPv4 header}} ;{{APHD|def|name=Destination address|length=32 bits|text=The destination address in the IPv4 header}} ;{{APHD|def|name=Zeroes|length=8 bits|text=All zeroes}} ;{{APHD|def|name=Protocol|length=8 bits|text=The protocol value for TCP: {{val|6}}}} ;{{APHD|def|name=TCP length|length=16 bits|text=The length of the TCP header and data (measured in octets). For example, let's say we have IPv4 packet with Total Length of {{val|200|u=bytes}} and IHL value of 5, which indicates a length of {{val|5|x|32|u=bits}} = {{val|160|u=bits}} = {{val|20|u=bytes}}. We can compute the TCP length as {{nowrap|(Total Length) − (IPv4 Header Length)}} i.e. {{nowrap|200 − 20}}, which results in {{val|180|u=bytes}}.}}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)