On 10/26/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > hi,, > > iam new to perl..i would like to pack a C structure to send it via > socket.... > > this is my C structure > > typedef struct buffer_t { > uint32_t a; > char b[16]; > uint32_t c; > uint32_t d; > char e[6]; > char f[8]; > } buffer_t; > > > can u provide a guideline for the format in the Pack command that i > need to use... snip
Short answer: You cant do this, find a better way to send the data (I would suggest XML, YAML, or JSON). Long answer: You may be able to do this, but only for a given C compiler and OS combination. ANSI C does not specify how structures are laid out in memory, only how the language access it. Some architectures use all sorts of padding to make accessing elements faster (this is why you have to say sizeof(struct foo) to get the size of the structure instead of just calculating it from the elements). You are also not guaranteed what order the elements will be in. The elements themselves may not even be of a given size since char, int, and long only have minimum size definitions. Yet another hurdle is big endian vs little endian memory layout. So, the upshot is you need to find out exactly how the structure is laid out in memory. After you know that, you can choose the proper pack string, but be prepared for it to change. It is better to send the data in a platform neutral manner and reconstitute it on the other end. XML is popular for some reason, but there are many different data transport formats. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/