CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: sysread and Little Endian: Edit Log



ric79
New User

Oct 4, 2013, 1:34 AM


Views: 2481
sysread and Little Endian

Hi all,
my file, in HEX, is like this:


Code
hexdump -C mytest.pcap -n 16 
00000018 63 1e 0f 4f b5 a2 0e 00 2a 05 00 00 2a 05 00 00 |c..O....*...*...|
00000028


I need to sysread the last 4 bytes (2a 05 00 00) which indicates the total file length. Beware that the number is written in Little Endian and must be read as 0x0000052a --> 1322 Bytes


Code
sysread($global_fh, $buffer, 12) > 0 || die "couldn't read byte from $filename: $!"; 
sysread($global_fh, $buffer, 4) > 0 || die "couldn't read byte from $filename: $!";
$buf = unpack('H*',$buffer);
print "-". $buf ."-\n";


-2a050000-


How to convert now in decimal?
Help is appreciated!

Riccardo


(This post was edited by ric79 on Oct 6, 2013, 11:37 PM)
Attachments: mytest.pcap (1.33 KB)


Edit Log:
Post edited by ric79 (New User) on Oct 4, 2013, 1:36 AM
Post edited by ric79 (New User) on Oct 6, 2013, 11:37 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives