[PATCH] initial commit for libosmo-gtp

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Jacob Erlbeck jerlbeck at sysmocom.de
Mon Oct 19 12:42:50 UTC 2015


On 17.10.2015 22:52, Neels Hofmeyr wrote:
> On Sat, Oct 17, 2015 at 10:53:53AM +0200, Harald Welte wrote:
>> Hi Neels and Pablo,
>>
>> first of all, it is great to see this code appear, I never liked libgtp
>> much either...
>>
>> On Thu, Oct 15, 2015 at 03:32:02PM +0200, Neels Hofmeyr wrote:
>>>> +struct gtp0_header {
>>>> +#if BYTE_ORDER == BIG_ENDIAN
>>>> +	uint8_t version:3,
>>>> +		pt:1,
>>>> +		spare:3,
>>>> +		snn:1;
>>>> +#elif BYTE_ORDER == LITTLE_ENDIAN
>>>> +	uint8_t snn:1,
>>>> +		spare:3,
>>>> +		pt:1,
>>>> +		version:3;
>>
>> /usr/include/netinet/ip.h or /usr/include/netinet/tcp.h
> 
> Learning never ends indeed. Thanks!
> 
> And then, I take it, the bits within each bitfield element are also
> reversed, but since it matches the host, they are correct and ready...
> 
> I'm confused by the fact that the bitfields' order is "reversed" on BE.
> Is that consistent with shift left and right operators?? Don't tell me
> that you have to reverse those as well on a BE system.

The ordering of bitfields is not necessarily tied to the byte ordering.

> 
> Either way, would be great if C had a way that doesn't need everything
> written twice...

In fact you have to write it two times only, because we know we are
using gcc. The C99 spec leaves it open to the compiler implementer
whether the bit fields within a unit are "high-order to
low-order or low-order to high-order" [C99: 6.7.2.1 (10)]. Have a look
at the definition of the 'ms_struct' and 'gcc_struct' variable
attributes in the gcc documentation for further details. Supporting both
ABIs would lead to four variants.

So this approach to do serialisation/deserialisation is not really
portable with respect to the specification.

Jacob

-- 
- Jacob Erlbeck <jerlbeck at sysmocom.de>       http://www.sysmocom.de/
=======================================================================
* sysmocom - systems for mobile communications GmbH
* Alt-Moabit 93
* 10559 Berlin, Germany
* Sitz / Registered office: Berlin, HRB 134158 B
* Geschaeftsfuehrer / Managing Directors: Holger Freyther, Harald Welte



More information about the OpenBSC mailing list