publicENEMY publicENEMY - 1 month ago 22
C# Question

What is the size of udp packets if i send 0 payload data in c#?

I have figured out the maximum data before fragmentation between 2 endpoints using udp is 1472(other endpoints may vary). this states that mtu is 1500bytes and header overhead per packet is 28bytes.is it safe to assume that if i send 0 bytes data(payload), the actual data being transferred is 28bytes? im doing some bencchmark, so its crucial for me to know what happens in the channel. thanks.

dtb dtb
Answer
  • The MTU is the maximum size of an IP packet that can be transmitted without fragmentation.

    IPv4 mandates a path MTU of at least 576 bytes, IPv6 of at least 1280 bytes.

    Ethernet has an MTU of 1500 bytes.

  • An IP packet is composed of two parts: the packet header and the payload.

    The size of an IPv4 header is at least 20 bytes, the size of an IPv6 header at least 40 bytes.

    The payload of an IP packet is typically a TCP segment or a UDP datagram.

  • A UDP datagram consists of a UDP header and the transported data.

    The size of a UDP header is 8 bytes.

This means an IP packet with an empty UDP datagram as payload takes at least 28 (IPv4) or 48 (IPv6) bytes, but may take more bytes.

Also note that in the case of Ethernet, the IP packet will additionally be wrapped in a MAC packet (14 byte header + 4 byte CRC) which will be embedded in an Ethernet frame (8 byte preamble sequence). This adds 26 bytes of data to the IP packet, but doesn't count against the MTU.

So you cannot assume that a UDP datagram will cause a specific number of bytes to be transmitted.