Question

I am trying to figure out how to read IP flags (not TCP) using scapy library. I know it is stored in "flags" and it is FlagsField type. According to IP protocol specification there are 3 flags R, MF, and DF. I've search, and searched and could not find any info on how to read these flags. Any ideas?

Thank you all for your input.

Was it helpful?

Solution

For example, creating an IP packet with the DF (Don't Fragment) flag set:

>>> packet = IP(flags=2)  # alternatively, IP(flags='DF')
>>> packet
<IP  flags=DF |>

Reading a packet's flags:

>>> packet.flags
2

As for the flag bits, Wikipedia outlines this succinctly. It's a three-bit value with the following meaning:

  • bit 0: Reserved; must be zero.
  • bit 1: Don't Fragment (DF)
  • bit 2: More Fragments (MF)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top