OSPF endianess fix
Ondrej Feela Filip
feela at network.cz
Sun Sep 7 00:15:51 CEST 2003
On Sat, 6 Sep 2003, Martin Mares wrote:
> Hello!
>
> > I think that preffered way would be to use correct ntoh(3) library
> > call while receiving LSA packet. Still doesn't matter, because BIRD
> > doesn't support multiple OSPF areas :-( (as far as i know).
>
> | +#ifdef CPU_LITTLE_ENDIAN
> | chsum= x + (y << 8);
> | +#else
> | + chsum= y + (x << 8);
> | +#endif
> | h->checksum = chsum;
>
> Yes, htons should be here.
This was fixed some other way. Krzysztof Szuster had a good idea. The
checksum is calculated in network's endianity.
> | +#ifdef CPU_LITTLE_ENDIAN
> | u8 ms:1;
> | u8 m:1;
> | u8 i:1;
> | u8 padding:5;
> | +#else
> | + u8 padding:5;
> | + u8 i:1;
> | + u8 m:1;
> | + u8 ms:1;
> | +#endif
> | };
>
> I don't really understand this piece -- either it's a piece of packet as seen
> on the wire and then it must not depend on CPU endianity or it's already
> converted to host order somewhere else and then the conversion is wrong.
> I'd understand such a construction if it were in a union with a longer integer
> field, but it doesn't seem to be the case here.
I cannot agree. The bit ordering in structures _depends_ on the endianity.
Please look into /usr/include/netinet/ip.h for examples. This structure is
in the network's endianity. (The same problem is also with "struct
immsb".)
Feela
>
> Have a nice fortnight
>
More information about the Bird-users
mailing list