Size of empty UDP and TCP packet?

落花浮王杯 提交于 2019-11-27 00:38:53
Himanshu

TCP:

Size of Ethernet frame - 24 Bytes
Size of IPv4 Header (without any options) - 20 bytes
Size of TCP Header (without any options) - 20 Bytes

Total size of an Ethernet Frame carrying an IP Packet with an empty TCP Segment - 24 + 20 + 20 = 64 bytes

UDP:

Size of Ethernet frame - 24 Bytes
Size of IPv4 Header (without any options) - 20 bytes
Size of UDP header - 8 bytes

Total size of an Ethernet Frame carrying an IP Packet with an empty UDP Datagram - 24 + 20 + 8 = 52 bytes

Himanshus answer is perfectly correct.

What might be misleading when looking at the structure of an Ethernet frame [see further reading], is that without payload the minimum size of an Ethernet frame would be 18 bytes: Dst Mac(6) + Src Mac(6) + Length (2) + Fcs(4), adding minimum size of IPv4 (20) and TCP (20) gives us a total of 58 bytes.

What has not been mentioned yet is that the minimum payload of an ethernet frame is 46 byte, so the 20+20 byte from the IPv4 an TCP are not enough payload! This means that 6 bytes have to be padded, thats where the total of 64 bytes is coming from.

18(min. Ethernet "header" fields) + 6(padding) + 20(IPv4) + 20(TCP) = 64 bytes

Hope this clears things up a little.

Further Reading:

See User Datagram Protocol. The UDP Header is 8 Bytes (64 bits) long.

The mimimum size of the bare TCP header is 5 words (32bit word), while the maximum size of a TCP header is 15 words.

Best wishes, Fabian

Artelius and halfdan are correct, but you're missing something: UDP and TCP both run on top of some physical transport. For example, if you're using UDP over ethernet, you should also include the size of the ethernet frame

If you intend to calculate the bandwidth consumption and relate them to the maximum rate of your network (like 1Gb/s or 10Gb/s), it is necessary, as pointed out by Useless, to add the Ethernet framing overhead at layer 1 to the numbers calculated by Felix and others, namely

  • 7 bytes preamble
  • 1 byte start-of-frame delimiter
  • 12 bytes interpacket gap

i.e. a total of 20 more bytes consumed per packet.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!