00001
00002
00003
00004 #ifndef __BYTEORDER_H
00005 #define __BYTEORDER_H
00006
00007
00008 #include <machine/endian.h>
00009
00010
00011 #include <byteswap.h>
00012 #define swap16(x) bswap_16(x)
00013 #define swap32(x) bswap_32(x)
00014 #define swap64(x) bswap_64(x)
00015
00016
00017 #include <_stdint.h>
00018
00019
00020
00021
00022
00023
00024
00025
00026 #define be16atoh(x) ((uint16_t)(((x)[0]<<8)|(x)[1]))
00027 #define be32atoh(x) ((uint32_t)(((x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3]))
00028 #define be64atoh_x(x,off,shift) (((uint64_t)((x)[off]))<<shift)
00029 #define be64atoh(x) ((uint64_t)(be64atoh_x(x,0,56)|be64atoh_x(x,1,48)|be64atoh_x(x,2,40)| \
00030 be64atoh_x(x,3,32)|be64atoh_x(x,4,24)|be64atoh_x(x,5,16)|be64atoh_x(x,6,8)|((x)[7])))
00031 #define le16atoh(x) ((uint16_t)(((x)[1]<<8)|(x)[0]))
00032 #define le32atoh(x) ((uint32_t)(((x)[3]<<24)|((x)[2]<<16)|((x)[1]<<8)|(x)[0]))
00033 #define le64atoh_x(x,off,shift) (((uint64_t)(x)[off])<<shift)
00034 #define le64atoh(x) ((uint64_t)(le64atoh_x(x,7,56)|le64atoh_x(x,6,48)|le64atoh_x(x,5,40)| \
00035 le64atoh_x(x,4,32)|le64atoh_x(x,3,24)|le64atoh_x(x,2,16)|le64atoh_x(x,1,8)|((x)[0])))
00036
00037 #define htobe16a(a,x) (a)[0]=(uint8_t)((x)>>8), (a)[1]=(uint8_t)(x)
00038 #define htobe32a(a,x) (a)[0]=(uint8_t)((x)>>24), (a)[1]=(uint8_t)((x)>>16), \
00039 (a)[2]=(uint8_t)((x)>>8), (a)[3]=(uint8_t)(x)
00040 #define htobe64a(a,x) (a)[0]=(uint8_t)((x)>>56), (a)[1]=(uint8_t)((x)>>48), \
00041 (a)[2]=(uint8_t)((x)>>40), (a)[3]=(uint8_t)((x)>>32), \
00042 (a)[4]=(uint8_t)((x)>>24), (a)[5]=(uint8_t)((x)>>16), \
00043 (a)[6]=(uint8_t)((x)>>8), (a)[7]=(uint8_t)(x)
00044 #define htole16a(a,x) (a)[1]=(uint8_t)((x)>>8), (a)[0]=(uint8_t)(x)
00045 #define htole32a(a,x) (a)[3]=(uint8_t)((x)>>24), (a)[2]=(uint8_t)((x)>>16), \
00046 (a)[1]=(uint8_t)((x)>>8), (a)[0]=(uint8_t)(x)
00047 #define htole64a(a,x) (a)[7]=(uint8_t)((x)>>56), (a)[6]=(uint8_t)((x)>>48), \
00048 (a)[5]=(uint8_t)((x)>>40), (a)[4]=(uint8_t)((x)>>32), \
00049 (a)[3]=(uint8_t)((x)>>24), (a)[2]=(uint8_t)((x)>>16), \
00050 (a)[1]=(uint8_t)((x)>>8), (a)[0]=(uint8_t)(x)
00051
00052 #endif