Re: packing a C structure
- From: Josef Moellers <josef.moellers@xxxxxxxxxxxxxxxxxxx>
- Date: Fri, 26 Oct 2007 09:06:07 +0200
haairam@xxxxxxxxx wrote:
hi ,,,
iam trying to pack a C structure to send via socket..i would like to
know how to frame the template for the C structure..
this is my 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;
kindly suggest me the format for the pack function call..this will
help me to solve my issue...
Transferring binary structures is inherently non-portable, so there is not a single way to deduce the actual binary layout of this structure, as the alignment and even the format of the binary numbers (e.g. endianness) will vary from machine type to machine type and even between compilers. It might even be impossible to transfer the data if the receiving machine is unable to handle 32 bit data, but I guess that's less of a problem.
That's why techniques like ASN.1 were developed.
If the amount of data is relatively small and you can live with some time spent in conversion, a simple (and more portable (*)) means to transfer this data is to transform it into ascii, with suitable separators, e.g. commas or colons, terminated by a line feed.
(*) Sheesh, I sure hope Scott Nudds doesn't read this ;-) It's "more" portable because you have removed alignment and endianness problems, there's still a portability issue in that the receiving machine might speak EBCDIC while the sending machine speaks ASCII.
--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html
.
- Follow-Ups:
- Re: packing a C structure
- From: rams
- Re: packing a C structure
- References:
- packing a C structure
- From: haairam
- packing a C structure
- Prev by Date: FAQ 7.19 What's the difference between deep and shallow binding?
- Next by Date: Re: daemon in perl
- Previous by thread: packing a C structure
- Next by thread: Re: packing a C structure
- Index(es):
Relevant Pages
|