[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: endianness guide

> > I don't know if by module you  mean kernel module, but you should look 
> > at the ntoh[l|s] && hton[l|s] macros. That should help... (the "host" 
> > is supposed to be big endian, so if you work on a big endian machine, 
> > ntohX does nothing).
> >
> So if I'm using a big endian machine like a mac, also when I use 
> hton[l|s] nothing happens (big endian -> network). hton and ntoh are 
> only used to make code portable is that right?

Those functions are a crummy API for userspace apps. They are not
used in kernel code, and might not even be available. For kernel
programming, you need these:


(some are identical, but you should distinguish them for documentation)

Other things to watch out for:

"char" is unsigned by default on PowerPC, but signed on every other
system. (this is stupid, unrelated to the hardware itself, related to
EBCDIC which Linux doesn't use anyway, and could be quickly changed
with only a bit of trouble involving C++ libraries)

Make sure that IO memory is properly mapped. See the Documentation
directory in the kernel source.

Try using the "sparse" tool to check the code for problems.

Reply to: