Byte order fix for BSD and OSX

Hi, as described in the commit messages, this patch fixes a byte order related issue i ran into while running on NetBSD and OSX.