00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifdef LBL_ALIGN
00028
00029
00030
00031 #ifdef HAVE___ATTRIBUTE__
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 typedef struct {
00047 u_int16_t val;
00048 } __attribute__((packed)) unaligned_u_int16_t;
00049
00050 typedef struct {
00051 u_int32_t val;
00052 } __attribute__((packed)) unaligned_u_int32_t;
00053
00054 #define EXTRACT_16BITS(p) \
00055 ((u_int16_t)ntohs(((const unaligned_u_int16_t *)(p))->val))
00056 #define EXTRACT_32BITS(p) \
00057 ((u_int32_t)ntohl(((const unaligned_u_int32_t *)(p))->val))
00058 #define EXTRACT_64BITS(p) \
00059 ((u_int64_t)(((u_int64_t)ntohl(((const unaligned_u_int32_t *)(p) + 0)->val)) << 32 | \
00060 ((u_int64_t)ntohl(((const unaligned_u_int32_t *)(p) + 1)->val)) << 0))
00061
00062 #else
00063
00064
00065
00066
00067
00068 #define EXTRACT_16BITS(p) \
00069 ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 0) << 8 | \
00070 (u_int16_t)*((const u_int8_t *)(p) + 1)))
00071 #define EXTRACT_32BITS(p) \
00072 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 24 | \
00073 (u_int32_t)*((const u_int8_t *)(p) + 1) << 16 | \
00074 (u_int32_t)*((const u_int8_t *)(p) + 2) << 8 | \
00075 (u_int32_t)*((const u_int8_t *)(p) + 3)))
00076 #define EXTRACT_64BITS(p) \
00077 ((u_int64_t)((u_int64_t)*((const u_int8_t *)(p) + 0) << 56 | \
00078 (u_int64_t)*((const u_int8_t *)(p) + 1) << 48 | \
00079 (u_int64_t)*((const u_int8_t *)(p) + 2) << 40 | \
00080 (u_int64_t)*((const u_int8_t *)(p) + 3) << 32 | \
00081 (u_int64_t)*((const u_int8_t *)(p) + 4) << 24 | \
00082 (u_int64_t)*((const u_int8_t *)(p) + 5) << 16 | \
00083 (u_int64_t)*((const u_int8_t *)(p) + 6) << 8 | \
00084 (u_int64_t)*((const u_int8_t *)(p) + 7)))
00085 #endif
00086 #else
00087
00088
00089
00090
00091 #define EXTRACT_16BITS(p) \
00092 ((u_int16_t)ntohs(*(const u_int16_t *)(p)))
00093 #define EXTRACT_32BITS(p) \
00094 ((u_int32_t)ntohl(*(const u_int32_t *)(p)))
00095 #define EXTRACT_64BITS(p) \
00096 ((u_int64_t)(((u_int64_t)ntohl(*((const u_int32_t *)(p) + 0))) << 32 | \
00097 ((u_int64_t)ntohl(*((const u_int32_t *)(p) + 1))) << 0))
00098 #endif
00099
00100 #define EXTRACT_24BITS(p) \
00101 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 16 | \
00102 (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \
00103 (u_int32_t)*((const u_int8_t *)(p) + 2)))
00104
00105
00106
00107
00108
00109 #define EXTRACT_LE_8BITS(p) (*(p))
00110 #define EXTRACT_LE_16BITS(p) \
00111 ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 1) << 8 | \
00112 (u_int16_t)*((const u_int8_t *)(p) + 0)))
00113 #define EXTRACT_LE_32BITS(p) \
00114 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 3) << 24 | \
00115 (u_int32_t)*((const u_int8_t *)(p) + 2) << 16 | \
00116 (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \
00117 (u_int32_t)*((const u_int8_t *)(p) + 0)))
00118 #define EXTRACT_LE_64BITS(p) \
00119 ((u_int64_t)((u_int64_t)*((const u_int8_t *)(p) + 7) << 56 | \
00120 (u_int64_t)*((const u_int8_t *)(p) + 6) << 48 | \
00121 (u_int64_t)*((const u_int8_t *)(p) + 5) << 40 | \
00122 (u_int64_t)*((const u_int8_t *)(p) + 4) << 32 | \
00123 (u_int64_t)*((const u_int8_t *)(p) + 3) << 24 | \
00124 (u_int64_t)*((const u_int8_t *)(p) + 2) << 16 | \
00125 (u_int64_t)*((const u_int8_t *)(p) + 1) << 8 | \
00126 (u_int64_t)*((const u_int8_t *)(p) + 0)))