Add the control flags constants and a helper function to test which flags are on.
Signed-off-by: Jason Kölker <[email protected]> --- ryu/lib/packet/tcp.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/ryu/lib/packet/tcp.py b/ryu/lib/packet/tcp.py index 7b5a7c7..80c4992 100644 --- a/ryu/lib/packet/tcp.py +++ b/ryu/lib/packet/tcp.py @@ -35,6 +35,16 @@ TCP_OPTION_KIND_TIMESTAMPS = 8 # Timestamps TCP_OPTION_KIND_USER_TIMEOUT = 28 # User Timeout Option TCP_OPTION_KIND_AUTHENTICATION = 29 # TCP Authentication Option (TCP-AO) +TCP_FIN = 0x001 +TCP_SYN = 0x002 +TCP_RST = 0x004 +TCP_PSH = 0x008 +TCP_ACK = 0x010 +TCP_URG = 0x020 +TCP_ECE = 0x040 +TCP_CWR = 0x080 +TCP_NS = 0x100 + class tcp(packet_base.PacketBase): """TCP (RFC 793) header encoder/decoder class. @@ -83,6 +93,21 @@ class tcp(packet_base.PacketBase): def __len__(self): return self.offset * 4 + def has_flags(self, *flags): + """Check if flags are set on this packet. + + returns boolean if all passed flags is set + + eg. + + # Check if this is a syn+ack + if pkt.has_flags(tcp.TCP_SYN, tcp.TCP_ACK): + ... + """ + + mask = sum(flags) + return (self.bits & mask) == mask + @classmethod def parser(cls, buf): (src_port, dst_port, seq, ack, offset, bits, window_size, -- 2.7.3 ------------------------------------------------------------------------------ Transform Data into Opportunity. Accelerate data analysis in your applications with Intel Data Analytics Acceleration Library. Click to learn more. http://pubads.g.doubleclick.net/gampad/clk?id=278785351&iu=/4140 _______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
