00001
00002
00003
00004 #ifndef __BYTEORDER_H
00005 #define __BYTEORDER_H
00006
00007
00008 #include <arpa/inet.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
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef htobe16
00033 # define htobe16(x) htons(x)
00034 #endif
00035 #ifndef htobe32
00036 # define htobe32(x) htonl(x)
00037 #endif
00038 #ifndef be16toh
00039 # define be16toh(x) ntohs(x)
00040 #endif
00041 #ifndef be32toh
00042 # define be32toh(x) ntohl(x)
00043 #endif
00044
00045 #define HTOBE16(x) (x) = htobe16(x)
00046 #define HTOBE32(x) (x) = htobe32(x)
00047 #define BE32TOH(x) (x) = be32toh(x)
00048 #define BE16TOH(x) (x) = be16toh(x)
00049
00050
00051 #ifndef htole16
00052 # define htole16(x) (x)
00053 #endif
00054 #ifndef htole32
00055 # define htole32(x) (x)
00056 #endif
00057 #ifndef htole64
00058 # define htole64(x) (x)
00059 #endif
00060 #ifndef le16toh
00061 # define le16toh(x) (x)
00062 #endif
00063 #ifndef le32toh
00064 # define le32toh(x) (x)
00065 #endif
00066 #ifndef le64toh
00067 # define le64toh(x) (x)
00068 #endif
00069
00070 #define HTOLE16(x) (void) (x)
00071 #define HTOLE32(x) (void) (x)
00072 #define HTOLE64(x) (void) (x)
00073 #define LE16TOH(x) (void) (x)
00074 #define LE32TOH(x) (void) (x)
00075 #define LE64TOH(x) (void) (x)
00076
00077
00078 #ifndef htobe64
00079 # define htobe64(x) swap64(x)
00080 #endif
00081 #ifndef be64toh
00082 # define be64toh(x) swap64(x)
00083 #endif
00084
00085 #define HTOBE64(x) (x) = htobe64(x)
00086 #define BE64TOH(x) (x) = be64toh(x)
00087
00088
00089 #include <_stdint.h>
00090
00091
00092
00093
00094
00095
00096
00097
00098 #define be16atoh(x) ((uint16_t)(((x)[0]<<8)|(x)[1]))
00099 #define be32atoh(x) ((uint32_t)(((x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3]))
00100 #define be64atoh_x(x,off,shift) (((uint64_t)((x)[off]))<<shift)
00101 #define be64atoh(x) ((uint64_t)(be64atoh_x(x,0,56)|be64atoh_x(x,1,48)|be64atoh_x(x,2,40)| \
00102 be64atoh_x(x,3,32)|be64atoh_x(x,4,24)|be64atoh_x(x,5,16)|be64atoh_x(x,6,8)|((x)[7])))
00103 #define le16atoh(x) ((uint16_t)(((x)[1]<<8)|(x)[0]))
00104 #define le32atoh(x) ((uint32_t)(((x)[3]<<24)|((x)[2]<<16)|((x)[1]<<8)|(x)[0]))
00105 #define le64atoh_x(x,off,shift) (((uint64_t)(x)[off])<<shift)
00106 #define le64atoh(x) ((uint64_t)(le64atoh_x(x,7,56)|le64atoh_x(x,6,48)|le64atoh_x(x,5,40)| \
00107 le64atoh_x(x,4,32)|le64atoh_x(x,3,24)|le64atoh_x(x,2,16)|le64atoh_x(x,1,8)|((x)[0])))
00108
00109 #define htobe16a(a,x) (a)[0]=(uint8_t)((x)>>8), (a)[1]=(uint8_t)(x)
00110 #define htobe32a(a,x) (a)[0]=(uint8_t)((x)>>24), (a)[1]=(uint8_t)((x)>>16), \
00111 (a)[2]=(uint8_t)((x)>>8), (a)[3]=(uint8_t)(x)
00112 #define htobe64a(a,x) (a)[0]=(uint8_t)((x)>>56), (a)[1]=(uint8_t)((x)>>48), \
00113 (a)[2]=(uint8_t)((x)>>40), (a)[3]=(uint8_t)((x)>>32), \
00114 (a)[4]=(uint8_t)((x)>>24), (a)[5]=(uint8_t)((x)>>16), \
00115 (a)[6]=(uint8_t)((x)>>8), (a)[7]=(uint8_t)(x)
00116 #define htole16a(a,x) (a)[1]=(uint8_t)((x)>>8), (a)[0]=(uint8_t)(x)
00117 #define htole32a(a,x) (a)[3]=(uint8_t)((x)>>24), (a)[2]=(uint8_t)((x)>>16), \
00118 (a)[1]=(uint8_t)((x)>>8), (a)[0]=(uint8_t)(x)
00119 #define htole64a(a,x) (a)[7]=(uint8_t)((x)>>56), (a)[6]=(uint8_t)((x)>>48), \
00120 (a)[5]=(uint8_t)((x)>>40), (a)[4]=(uint8_t)((x)>>32), \
00121 (a)[3]=(uint8_t)((x)>>24), (a)[2]=(uint8_t)((x)>>16), \
00122 (a)[1]=(uint8_t)((x)>>8), (a)[0]=(uint8_t)(x)
00123
00124 #endif