Add htole32 replacement and proper header detection of endian.h.

Done, 03bde26c777f07532c05fcabb38516be15dbbc8c.