Fix wrong headers on MacOSX.

When using MacOSX, the endian header was not found. It is located in
machine/endian.h. This patch checks when the case arise and use this
header instead.
Fix compilation errors on MacOS X.

The endianness macro (htole32, ...) do not exist on MacOS X. We use
their OSX equivalent instead when we know that we are on this platform.