1.6 TCPFlags Objects

A TCPFlags object represents the eight bits of flags from a TCP session.

class TCPFlags( value)
The constructor takes either a TCPFlags value, a string, or an integer. If a TCPFlags value, it returns a copy of that value. If an integer, the integer should represent the 8-bit representation of the flags. If a string, the string should consist of a concatenation of zero or more of the characters "F", "S", "R", "P", "A", "U", "E", and "C"--upper or lower-case--representing the FIN, SYN, RST, PSH, ACK, URG, ECE, and CWR flags. Spaces in the string are ignored.

Examples:

>>> a = TCPFlags('SA')
>>> b = TCPFlags(5)

Instance attributes (read-only):

Attribute Value
FIN True if the FIN flag is set, False otherwise
SYN True if the SYN flag is set, False otherwise
RST True if the RST flag is set, False otherwise
PSH True if the PSH flag is set, False otherwise
ACK True if the ACK flag is set, False otherwise
URG True if the URG flag is set, False otherwise
ECE True if the ECE flag is set, False otherwise
CWR True if the CWR flag is set, False otherwise

Supported operations:

Operation Result
 f The bitwise inversion (not) of f
f1 & f2 The bitwise intersection (and) of the flags from f1 and f2
f1 | f2 The bitwise union (or) of the flags from f1 and f2
f1 ^ f2 The bitwise exclusive disjunction (xor) of the flags from f1 and f2
int(f) The integer value of the flags f
f Can be used as a truth value with any flag set == True, False otherwise

Constants:

The following constants are defined:

Constant Meaning
FIN A TCPFlags value with only the FIN flags set
SYN A TCPFlags value with only the SYN flags set
RST A TCPFlags value with only the RST flags set
PSH A TCPFlags value with only the PSH flags set
ACK A TCPFlags value with only the ACK flags set
URG A TCPFlags value with only the URG flags set
ECE A TCPFlags value with only the ECE flags set
CWR A TCPFlags value with only the CWR flags set

Supported methods:

matches( flagmask)
Given a flagmask of the form "flags/mask", returns True if if the flags of self match flags after being masked with mask, False otherwise.

Given a flagmask without the "/", checks for literal equality, as if the mask contained all flags.

__str__( )
For an TCPFlags object f, str(f) returns the a string representation of the flags set in f.