Program printing all possible combinations of TCP flags

Discussion in 'Perl Misc' started by Rainer Weikusat, Aug 9, 2011.

  1. 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);
    }
    ---------------
    Rainer Weikusat, Aug 9, 2011
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rbt

    all possible combinations

    rbt, Jul 13, 2005, in forum: Python
    Replies:
    36
    Views:
    21,411
    Steve Holden
    Jul 28, 2005
  2. Replies:
    16
    Views:
    763
    Scott David Daniels
    May 31, 2006
  3. Steve Holden
    Replies:
    0
    Views:
    756
    Steve Holden
    Feb 8, 2009
  4. Erik Terpstra
    Replies:
    9
    Views:
    136
    Robert Klemme
    May 17, 2004
  5. Teme Rosi

    All possible letter combinations?

    Teme Rosi, Dec 11, 2008, in forum: Ruby
    Replies:
    3
    Views:
    203
    Martin Carpenter
    Dec 16, 2008
Loading...

Share This Page