in reply to Re^2: unpack blob
in thread unpack blob

Combining all the responses:

#!perl use strict; use warnings; use Socket; use MIME::Base64; # in core, thanks choroba my $blob = "BAABAAXwAACGAAAAAAABLAAAAAAAAAAArBQEKA=="; $blob = decode_base64($blob); my ( $dataLength, # 2 bytes $type, # 2 bytes $version, # 1 byte $rank, # 1 byte $flags, # 2 bytes $serial, # 4 bytes $ttl, # 4 bytes $reserved, # 4 bytes $timestamp, # 4 bytes $data ) = unpack( 'S S C C S L N L L a*', $blob ); # http://www.perlmonks.org/?node_id=1152688 see Tux comment print $dataLength, "\n"; print "$type\n"; print "$version\n"; print "$rank\n"; print "$flags\n"; print "$serial\n"; print "$ttl\n"; print "$reserved\n"; print "$timestamp\n"; print inet_ntoa($data) . "\n";

Replies are listed 'Best First'.
Re^4: unpack blob
by Tux (Canon) on Jan 13, 2016 at 14:23 UTC

    Side note when using S and L, as you are also using N: The byte order in S and L is architecture dependent. You probably should add the required endianness, like S< or L>. See this overview to see what the difference is.


    Enjoy, Have FUN! H.Merijn