use constant FIN => 0x01; use constant SYN => 0x02; use constant RST => 0x04; use constant PSH => 0x08; use constant ACK => 0x10; use constant URG => 0x20; use constant ECE => 0x40; use constant CWR => 0x80; #### #!/usr/bin/perl use strict; use warnings; use constant FIN => 0x01; use constant SYN => 0x02; use constant RST => 0x04; use constant PSH => 0x08; use constant ACK => 0x10; use constant URG => 0x20; use constant ECE => 0x40; use constant CWR => 0x80; my $helpDec = sprintf("%d", 19); # an arbitrary number that will have the SYN bit set my $helpBin = unpack("B*", pack('C',$helpDec)); print "TCPFLAG: $helpBin\n"; print "Or: $helpDec\n"; print "TCPACK: " . substr( $helpBin, 6, 1 ) . "\n"; #TCP flag ACK print "TCPPSH: " . substr( $helpBin, 5, 1 ) . "\n"; #TCP flag PUSH (PSH) print "TCPRST: " . substr( $helpBin, 4, 1 ) . "\n"; #TCP flag RESET (RST) print "TCPSYN: " . substr( $helpBin, 3, 1 ) . "\n"; #TCP flag SYN print "TCPFIN: " . substr( $helpBin, 2, 1 ) . "\n"; #TCP flag FIN print "\n"; print "TCPACK: " . ( $helpDec & ACK ? 1 : 0 ) . "\n"; #TCP flag ACK print "TCPPSH: " . ( $helpDec & PSH ? 1 : 0 ) . "\n"; #TCP flag PUSH (PSH) print "TCPRST: " . ( $helpDec & RST ? 1 : 0 ) . "\n"; #TCP flag RESET (RST) print "TCPSYN: " . ( $helpDec & SYN ? 1 : 0 ) . "\n"; #TCP flag SYN print "TCPFIN: " . ( $helpDec & FIN ? 1 : 0 ) . "\n"; #TCP flag FIN __END__ TCPFLAG: 00010011 Or: 19 TCPACK: 1 TCPPSH: 0 TCPRST: 0 TCPSYN: 1 TCPFIN: 0 TCPACK: 1 TCPPSH: 0 TCPRST: 0 TCPSYN: 1 TCPFIN: 1