[Dibbler] dibbler-server an debian-armel
lists at milindur.de
Tue Aug 19 09:52:05 CEST 2008
sorry, parts of my last mail were nonsense, it has been a bit too late
> > Well, my proposal was quicker:
> > unsigned short code = buf[pos]*256 + buf[pos+1];
> > pos+=2;
> > unsigned short length = buf[pos]*256 + buf[pos+1];
> > pos+=2;
> > Didn't it work? As far as I understand, reading a byte is always
> > successful. Byte multipled by 256 is automatically cast to short.
This works for me and it would naturally work for little and big endian
> Yes, that worked, too. But this only works for little endian systems,
> for big endian. Better would be:
> unsigned short code = ntohs(buf[pos] + buf[pos+1]*256);
> unsigned short length = ntohs(buf[pos] + buf[pos+1]*256);
And this idea of mine was nonsense.
> But I think that also the code where data is written into byte-buffers
> to be modified, e.g.:
> Such code only works on ARM (and similar) if it is guaranteed that the
> DUID, DUID+2 and so on are properly aligned for the pointer-type they
> casted to. In this case (uint16_t) it has to be a multiple of 2, for
> uint32_t a multiple of 4.
This problem remains.
So I change my idea:
> Maybe are functions like these a solution (untested):
uint16_t getUShort(const char *buf)
return buf * 256 + buf;
void putUShort(char *buf, uint16_t val)
buf = (unsigned char)((val & 0xff00) >> 8);
buf = (unsigned char)(val & 0xff);
I hope that I am now well rested and this is right...
More information about the Dibbler