preload
Dec 01

If you do any amount of work with F5 Nework’s iRules scripting language, eventually you run into the need to print out the contents of a packet you are working with to make sure you are processing the packet correctly, getting the fields lined up, getting sent the values you think you are being sent, etc.  Personally, I’m used to using a very common hexdump format that I’ve created Ruby methods for in the past…but I could not find anything similar for iRules, so I wrote my own.

The following code implements the hexdump:

if { $static::DEBUG eq 1 } {
        #  The hexbinary code we want to decode is stored in $payload
        ##
        ## format string for hexdump output
        ##
        set p 0     ;## buf ptr
        set sl [string length $payload]
        set inPkt "\n\n"
        while { $p < $sl } {
            set s [string range $payload $p [expr {$p+16}] ]
            binary scan $s H*@0a* hex ascii
            regsub -all -- {[^[:graph:] ]} $ascii {.} ascii
            set hex1   [string range $hex   0 15]
            set hex2   [string range $hex  16 31]
            set ascii1 [string range $ascii 0  7]
            set ascii2 [string range $ascii 8 15]
            # Convert the hex to pairs of hex digits
            regsub -all -- {..} $hex1 {& } hex1
            regsub -all -- {..} $hex2 {& } hex2
            append inPkt "[format {%08x  %-24s %-24s %-8s %-8s} $p $hex1 $hex2 $ascii1 $ascii2]\n"
            set p [expr {$p + 16}]
        }
        ###
        puts "Input PKT: $inPkt"            ;## print the output to /var/log/tmm
}

Continue reading »

SociBook del.icio.us Digg Facebook Google Yahoo Buzz StumbleUpon
Tagged with: