Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

pack() and non-64bit systems

by BlueLines (Hermit)
on Mar 19, 2003 at 03:38 UTC ( [id://244228]=perlquestion: print w/replies, xml ) Need Help??

BlueLines has asked for the wisdom of the Perl Monks concerning the following question:

i'm writing some client code at work to talk to a udp server we use for debugging. the server sends out the following c structure:
typedef struct Net_LogMsgHdr { int32 magic; Net_LogMsgType type; int32 nextLogChar; int32 logBufferSize; int32 length; int32 override; uint64 bootTS; uint64 pad; } Net_LogMsgHdr;
i've got something like this set up on the client side:
my $sock = IO::Socket::INET->new( LocalAddr => '127.0.0.1:6300', LocalPort => 6300, Proto => 'udp', ); my $incoming; while ($sock->recv($incoming, 65536)) { my ($magic, $type, $nextLogChar, $logBufferSize, $length, $override +, $bootTS, $pad) = unpack "llllllQQ" , $incoming;
which in theory should work, except my perl doesn't grok 64 bit integers. i know i can compile a version that does, but that's not a solution, since this has to be portable amongst our development machines here. i thought about bitshifting, but the camel book has the following warning:
"Results on large (or negative) numbers may vary depending on the numb +er of bits your machine uses to represent integers".
My machine (of course) uses 32 bit integers. So there's no way that i know of to go from a 128bit chunk of network data to two 64bit uints (excluding unpack). any ideas? cpan modules? *shudder* regexes?

BlueLines

Disclaimer: This post may contain inaccurate information, be habit forming, cause atomic warfare between peaceful countries, speed up male pattern baldness, interfere with your cable reception, exile you from certain third world countries, ruin your marriage, and generally spoil your day. No batteries included, no strings attached, your mileage may vary.

Replies are listed 'Best First'.
Re: pack() and non-64bit systems (old node)
by tye (Sage) on Mar 19, 2003 at 08:43 UTC

    See (tye)Re: 64 bit Integer anyone? for how I got 32-bit Perl to deal with 64-bit fields a few years back.

    Thanks to jmcnamara for giving me the node IDs in the CB so I didn't have to do the search. (:

                    - tye
Re: pack() and non-64bit systems
by pg (Canon) on Mar 19, 2003 at 04:46 UTC
    To make your program really portable and platform independent, there is no way you should send out c structure directly.

    Not only 32-bit, 64-bit, 128-bit is a problem, there are many other problems, for example, little endian, big endian etc.

    You have to define your own encoding schema, and encode (on sending side) and decode (on receiving side) by yourself. There is no easy way to gain full portability.

    A better way is to use SOAP, so you can focus on your data, and let SOAP take care of the rest for you.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://244228]
Approved by Paladin
Front-paged by Courage
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-03-29 01:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found