Why does UDP have a length field in the header and TCP does not?

前端 未结 4 1154
清酒与你
清酒与你 2021-02-01 04:21

Why does UDP have a length field in the header and TCP does not?

I am guessing that the length of the segment in TCP is inferred from the IP header but one should be abl

相关标签:
4条回答
  • 2021-02-01 04:23

    I thought: As TCP is a stream based protocol, it's ok if its segment be fragmented at . UDP is transaction oriented, if its messages be fragmented at IP layer we need its length to recover it.

    Sorry for my poor English.

    0 讨论(0)
  • 2021-02-01 04:25

    According to TCP/IP Illustrated Volume 1, the length field is redundant. That's all Stevens says on the matter.

    I personally believe it was to make the UDP header length (in bits) divisible by 32 :)

    0 讨论(0)
  • 2021-02-01 04:26

    It's just the way UDP was originally specified. UDP could work without a length field in the header in the same way TCP does.

    How is the length of each segment obtained in TCP? It is really up to the specific implementation (OS). The RFC for TCP just states:

    Any lower level protocol will have to provide the source address, destination address, and protocol fields, and some way to determine the "TCP length", [...]

    0 讨论(0)
  • 2021-02-01 04:40

    There is a 96 bit pseudo header conceptually prefixed to the TCP header that contains the information already.

    The checksum field description from this source gives the answer:

    Checksum: 16 bits

    The checksum field is the 16 bit one's complement of the one's complement sum of all 16 bit words in the header and text. If a segment contains an odd number of header and text octets to be checksummed, the last octet is padded on the right with zeros 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.

    The checksum also covers a 96 bit pseudo header conceptually prefixed to the TCP header. This pseudo header contains the Source Address, the Destination Address, the Protocol, and TCP length. This gives the TCP protection against misrouted segments. This information is carried in the Internet Protocol and is transferred across the TCP/Network interface in the arguments or results of calls by the TCP on the IP.

          +--------+--------+--------+--------+
          |           Source Address          |
          +--------+--------+--------+--------+
          |         Destination Address       |
          +--------+--------+--------+--------+
          |  zero  |  PTCL  |    TCP Length   |
          +--------+--------+--------+--------+
    

    The information is not needed at the TCP level since TCP is a stream based protocol.

    0 讨论(0)
提交回复
热议问题