[patch 5/6] IP support for PPP

Kristen Carlson Accardi kristen at linux.intel.com
Fri Mar 19 10:58:42 PDT 2010


On Thu, 18 Mar 2010 12:26:15 +0100
Marcel Holtmann <marcel at holtmann.org> wrote:

> Hi Kristen,
> 
> > > > +static guint32 bytes_to_32(guint8 *bytes)
> > > > +{
> > > > +	union addr {
> > > > +		guint8 bytes[4];
> > > > +		guint32 word;
> > > > +	} a;
> > > > +
> > > > +	memcpy(a.bytes, bytes, 4);
> > > > +	return(ntohl(a.word));
> > > > +}
> > > 
> > > This works, but is pretty ugly.
> > > 
> > > Doesn't GLib has functions to ensure retrieve unaligned data? BlueZ has
> > > the GCC magic that is required to do this right.
> > >
> > 
> > I have looked everywhere for something nice from glib, but I'm not
> > seeing it.  As far as I can tell, most people just do the bit shifting
> > manually -- but that's what I had originally and you didn't like it.
> > So I'm only seeing 2 options here, this way or the original way.  If
> > you know of the glib function to use, please let me know what it is.
> 
> I don't see how bit shifting is gonna help you against the unaligned
> access of your buffer.
> 
> Regards
> 
> Marcel
> 
> 

I wound up implementing both the packed data structures to represent
PPP packets (etc) as well as get_unaligned() to handle cases like this.
It does still seem hard to believe that glib doesn't already have a
way to access unaligned data, but I got tired of looking for it.


More information about the ofono mailing list