Size of empty UDP and TCP packet?

2019-01-06 13:37发布

问题:

What is the size of an empty UDP datagram? And that of an empty TCP packet?

I can only find info about the MTU, but I want to know what is the "base" size of these, in order to estimate bandwidth consumption for protocols on top of them.

回答1:

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



回答2:

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:

  • Ethernet_frame
  • Ethernet


回答3:

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



回答4:

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



回答5:

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.



标签: tcp udp size