network-programmingipipv4ip-fragmentation

Determine if IPv4 packet is fragmented


What is the right way to test if IP packet is a fragment?
Currently I only look at MF (More Fragments) bit in the IPv4 header. Is it sufficient?


Solution

  • That is insufficient because the last packet fragment will not have the MF flag set. You must also look at the Fragment offset field, but that by itself is not sufficient because the first packet fragment will have that field set to 0.

    If the Fragment Offset field > 0 then it is a packet fragment, or if the Fragment Offset field = 0 and the MF flag is set then it is a fragment packet.