in reply to Re: TCP States ( NetPacket::TCP module )
in thread TCP States ( NetPacket::TCP module )

Thanks for the reply. I have tried to print the value of $tcp_obj->{falgs}. Its giving me 0. Do you know any procedure to parse the flags?
  • Comment on Re^2: TCP States ( NetPacket::TCP module )

Replies are listed 'Best First'.
Re^3: TCP States ( NetPacket::TCP module )
by tirwhan (Abbot) on Dec 19, 2005 at 09:15 UTC

    You can binary AND them with the constants provided by the module to test for a single flag. The following will give you a comma-separated list of flags for a single packet.

    my %tcp_flags=(FIN => FIN, SYN => SYN, RST => RST, PSH => PSH, ACK => ACK, URG => URG, ECE => ECE, CWR => CWR); my $cur_flags=$tcp_obj->{flags}; my @set_flags = grep { $cur_flags & $tcp_flags{$_} } keys %tcp_flags; print join(",",@set_flags)."\n";

    Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan
      Thanks, its working fine.
Re^3: TCP States ( NetPacket::TCP module )
by gu (Beadle) on Dec 19, 2005 at 07:56 UTC
    If you really wrote $tcp_obj->{falgs}, an error is normal, because you should write $tcp_obj->{flags}.
    The value you intend to print is as in the packet, in binary form, so you must use binary operators to scan each flag. The example given in the documentation reads :
    # set the syn flag $tcp_obj->{flags} |= SYN;
    NetPacket::TCP exports the different flags, so you can use them as above.
    You should consider reading about binary operators.

    Hope this helps.

    Gu