[Israel.pm] pack & unpack and system architecture

Natty aloha2004 at gmail.com
Mon Sep 5 05:10:58 PDT 2011


You mean if the struct has the attributed packed? such as:

struct
{...} __attribute__((__packed__));

???

if so,I will need to take a look at the device that sends the data. I get
the binary data over the network from an embedded device which runs gcc
compiler, and I have no idea (yet) if it uses the __packed__ flag.

thanks,

On Mon, Sep 5, 2011 at 2:45 PM, Scott Weisman <sweisman at pobox.com> wrote:

> You would have to provide more details, like the C compiler, flags, etc.
>
> IIRC unless you specify otherwise, C aligns structure members on 4 or 8
> byte boundaries. You can force it to pack structs, which you want in your
> case.
>
> On Sun, Sep 4, 2011 at 6:34 PM, Natty <aloha2004 at gmail.com> wrote:
>
>> Hi,
>>
>> I've packed a C structure which looks similar to:
>>
>> struct  {
>>   unsigned char _vMapping1[3]; //  on the system perl is running, it sums
>> up to 3 bytes.
>>   unsigned char _vMapping2[3];   // on the system perl is running, it sums
>> up to 3 bytes.
>>   short _uPnP;  //  on the system perl is running, it sums up to 2 bytes.
>> }
>>
>> I think there are some fill bytes, which there shouldn't be I believe,
>> since I am not getting what I'm expecting when using:
>>
>> my $bin = unpack('c[3]c[3]s',...);
>>
>> is there a module which will make my life easier to pack / unpack C
>> structures / binary data?
>>
>> thanks,
>>
>>
>>
>> _______________________________________________
>> Perl mailing list
>> Perl at perl.org.il
>> http://mail.perl.org.il/mailman/listinfo/perl
>>
>
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://mail.perl.org.il/mailman/listinfo/perl
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.perl.org.il/pipermail/perl/attachments/20110905/db76ca80/attachment.htm 


More information about the Perl mailing list