Program printing all possible combinations of TCP flags

  • Thread starter Rainer Weikusat
  • Start date
R

Rainer Weikusat

Main function of this program is/was to generate a list of C string
literals used to populate an array which can be used to map the
numerical value of the flags field in a TCP header to a string
containing an uppercase letter (Fin, Syn, Rst, Psh, Ack, Urg) for each
set flag. Since it is kind-of cute an the algorithm is (IMHO) not
completely trivial/ obvious anymore, I thought I'd just post it here:

NB: This is fairly fast at the expense of possibly consuming huge
amounts of memory.

---------------
#!/usr/bin/perl

my @flags = qw(F S R P A U);

{
my @all;

push(@all, '');

for my $f (@flags) {
push(@all, map { $_.$f; } @all);
}

printf("\"%s\",\n", $_) for (@all);
}
---------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top