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. Advertisements

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:
    22,091
    Steve Holden
    Jul 28, 2005
  2. Replies:
    16
    Views:
    934
    Scott David Daniels
    May 31, 2006
  3. Tiger
    Replies:
    5
    Views:
    1,213
    Dave Thompson
    May 1, 2006
  4. Baba
    Replies:
    71
    Views:
    3,101
  5. Erik Terpstra
    Replies:
    9
    Views:
    255
    Robert Klemme
    May 17, 2004
  6. Teme Rosi

    All possible letter combinations?

    Teme Rosi, Dec 11, 2008, in forum: Ruby
    Replies:
    3
    Views:
    324
    Martin Carpenter
    Dec 16, 2008
  7. Ed W.
    Replies:
    1
    Views:
    214
    J├╝rgen Exner
    Oct 22, 2003
  8. rajsena
    Replies:
    3
    Views:
    313
    Arndt Jonasson
    Nov 10, 2004
Loading...