/*return value 0 : TRUE (host boyte order is big-endian) 1 : FALSE */int isBigEndian(void){ union { int i; /* at least 16 bit */ char c; }un; un.i = 0x01; /* 0x01 is LSB */ return (un.c == 0x01);}
網路中位元組序轉換
#include <netinet/in.h>/* 將主機位元組序,轉換成網路位元組序,返回網路位元組序的值 */uint16_t htons(uint16_t host16bitvalue); /* convert short form host to net */uint32_t htonl(uint32_t host32bitvalue);/* 將網路位元組序,轉換成主機位元組序,返回主機位元組序的值 */unit16_t ntohs(uint16_t net16bitvalue);uint32_t ntohl(uint32_t net32bitvalue);