Re: avoid structure padding



pmm wrote:
i am trying out a UDP packet
transfer between a windows machine and a linux I created a structure on
both sides (ie on linux and on windows) and I sent using UDP
but on the receiving side when I am trying to reform the packet back
into structure tis giving me different outputs I assume it is the
problem of structure padding ...

Internet packets should always, first, have a clear layout spec
and second, be constructed and interpreted by functions that map
between that layout and whatever data format the program finds
most convenient. (This is often called "marshalling" and
"unmarshalling" the data.) For your code that does this to be
portable, i.e. function the same regardless of platform, it
cannot make any assumptions about C data formats other than
what is guaranteed by the standard. In that context, the safest
way to code such marshalling/unmarshalling functions is to copy
*8 bits at a time* of each integer value between the structure
members and the packet data buffer (treated as a byte array,
byte-sequentially transmitted on the network). There are quite
a few pitfalls involved in doing that, so if at all possible
you should use an existing, tested data marshalling library.
Sun's XDR spec was among the earliest such approaches. These
days, sometimes, XML format is used, although it requires a lot
more bandwidth than the information content being conveyed.
--
comp.lang.c.moderated - moderation address: clcm@xxxxxxxxxxxx -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
.



Relevant Pages

  • Re: [SLE] Need help mounting a USB disk drive
    ... > be able to move that device between my Windows machine and my Linux machine. ... > The idea would be to convert one of those partitions into either an EXT2 ... > to create a high-level directory entry for use as a mount point and issue ...
    (SuSE)
  • Re: [opensuse] Iomega Rev drive
    ... it as a backup device. ... There is a device driver for Linux. ... another Linux machine or a Windows machine. ... than a REV disk, but we reuse them as they are only for data transport. ...
    (SuSE)
  • Re: HHeeellllllppp!!
    ... Data in your disk directory structure appears to has been corrupted. ... and connected it to a linux machine. ... it to do what we wanted, so we connected it to a windows machine. ... when I tried to go back to a connecting it to a windows machine, ...
    (microsoft.public.windowsxp.help_and_support)
  • RE: Remote Connections and port identification
    ... Remote Connections and port identification ... and it was sharing information on remote logins to windows machines from linux machines and it says at one point a linux machine 1 was forwarding information back over a public network through a secure remote network to another windows machine. ... If this was true, I'm thinking about performing an experiment where from my own windows machine, I will direct connect to a relativly unsecure LAN network down the street from my house, and connect to a windows 2k pro OS box I own, bypassing his server computer. ...
    (Security-Basics)
  • Re: Linux Server
    ... I think, rather, that the goal needs to be ... Linux is trying too hard to go in that direction. ... apps and stop trying to be as monolithic as Windows. ... effort should be going into defining data format standards so that I ...
    (alt.os.linux.suse)