0

I've defined my own protocol with fields. Some of the fields are enumerated. When executing pkt[0].show(), I see the value in enum as expected.

Now, I'd like to have some logic based on the this enum filed. The elegant way to write my code is using the enum (if filed=='MY_ENUM_VALUE: ...), however when I executing the pkt[0][Layer].field_name I'm getting the numeric value.

How can I read the enum value?

user1977050
  • 496
  • 1
  • 6
  • 18

1 Answers1

0

The enums that are used in scapy are actually dictionaries.

This should work:

from scapy.layers.my_layer import Layer my_enum

if my_emun[pkt[0][Layer].field] == 'MY_ENUM_VALUE':
    ....
patVog
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 24 '22 at 09:46