parsing - How can I parse space separated STDIN hex strings unpacked in Perl? -


I have a Java program that exits from space in hexadecimal format, 16 bytes of raw packets received on the network. Since I do not want to change that code, I'm piping the results on Perl script, which can theoretically, unpack from STDIN in the recognizable variable . The following is a sample of line input in the Perl file:

 FF FF 09 7D 10 01 07 01 00 02 00 1 00 00 00 00 00 00 06 00 07 00 | -Jerbage ----- | C-- | C-- | Integer --- | Integer --- | Integer --- | Integer --- | Integer --- | Integer --- | Integer --- | 

(int is for four / byte, 16bit integer variables for C)

I initially wanted to use unpack so that each input line I wanted to be separated into the variable I wanted. However, due to the location limit in the string, I'm not sure how to handle it (I can use 'A' as a template, but then I can also use split!)

Is there a great way to use unpack () ? I'm not a Pearl Master, but on the other side, as I had suggested earlier, use split and then manually convert each hex to one byte, and then bit manipulals and masks What do I need by using Any other suggestions (if unpack does not save the day)?

Consider those Ints in the big endian command, use

  #! Use / usr / bin / perl warnings; Strict use; # Only * ARGV = * data for demo; While ( 

It starts by packing in bytes ( C * ) The following sections contain unpack templates according to their values:

  • x5 excludes five bytes
  • c2 decode two unsigned char value
  • n7 decodes seven 16-bit Big-Endian unsigned integer

Output:

 $ ./dump-packets [1] [7] [256] [512] [7424] [0] [0] [1536] [17 9 2] 

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -