Hi.
I certainly join Scott with the recommendation to look on the binary
data itself, and see that you actually get the data that you expect.
A simple unpack "H*" will tell you a lot.
Apart from that, shameless plug to my module: Data::ParseBinary.
you can do something like:
$s = Struct( "foo",
Array(3, Byte("_vMapping1")),
Array(3, Byte("_vMapping2")),
UBInt16("uPnP"),
);
or something like that.
Shmuel.
On 2011/09/05 21:12, Scott Weisman wrote:
> I don't know enough about the details. But I have read about struct
> alignment issues causing problems like you're having.
>
> On Mon, Sep 5, 2011 at 3:10 PM, Natty <[email protected]
> <mailto:[email protected]>> wrote:
>
> 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 <[email protected]
> <mailto:[email protected]>> 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 <[email protected]
> <mailto:[email protected]>> 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
> [email protected] <mailto:[email protected]>
> http://mail.perl.org.il/mailman/listinfo/perl
>
>
>
> _______________________________________________
> Perl mailing list
> [email protected] <mailto:[email protected]>
> http://mail.perl.org.il/mailman/listinfo/perl
>
>
>
> _______________________________________________
> Perl mailing list
> [email protected] <mailto:[email protected]>
> http://mail.perl.org.il/mailman/listinfo/perl
>
>
>
>
> _______________________________________________
> Perl mailing list
> [email protected]
> http://mail.perl.org.il/mailman/listinfo/perl
_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl