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 able to do the same for a UDP datagram
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 able to do the same for a UDP datagram
On
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 :)
On
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", [...]
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:
The information is not needed at the TCP level since TCP is a stream based protocol.