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
00028
00029
00030
00031
00032
00033
00034 #ifndef ISCCC_UTIL_H
00035 #define ISCCC_UTIL_H 1
00036
00037 #include <isc/util.h>
00038
00039
00040
00041
00042
00043
00044
00045
00046 #define GET8(v, w) \
00047 do { \
00048 v = *w; \
00049 w++; \
00050 } while (0)
00051
00052 #define GET16(v, w) \
00053 do { \
00054 v = (unsigned int)w[0] << 8; \
00055 v |= (unsigned int)w[1]; \
00056 w += 2; \
00057 } while (0)
00058
00059 #define GET24(v, w) \
00060 do { \
00061 v = (unsigned int)w[0] << 16; \
00062 v |= (unsigned int)w[1] << 8; \
00063 v |= (unsigned int)w[2]; \
00064 w += 3; \
00065 } while (0)
00066
00067 #define GET32(v, w) \
00068 do { \
00069 v = (unsigned int)w[0] << 24; \
00070 v |= (unsigned int)w[1] << 16; \
00071 v |= (unsigned int)w[2] << 8; \
00072 v |= (unsigned int)w[3]; \
00073 w += 4; \
00074 } while (0)
00075
00076 #define GET64(v, w) \
00077 do { \
00078 v = (isc_uint64_t)w[0] << 56; \
00079 v |= (isc_uint64_t)w[1] << 48; \
00080 v |= (isc_uint64_t)w[2] << 40; \
00081 v |= (isc_uint64_t)w[3] << 32; \
00082 v |= (isc_uint64_t)w[4] << 24; \
00083 v |= (isc_uint64_t)w[5] << 16; \
00084 v |= (isc_uint64_t)w[6] << 8; \
00085 v |= (isc_uint64_t)w[7]; \
00086 w += 8; \
00087 } while (0)
00088
00089 #define GETC16(v, w, d) \
00090 do { \
00091 GET8(v, w); \
00092 if (v == 0) \
00093 d = ISCCC_TRUE; \
00094 else { \
00095 d = ISCCC_FALSE; \
00096 if (v == 255) \
00097 GET16(v, w); \
00098 } \
00099 } while (0)
00100
00101 #define GETC32(v, w) \
00102 do { \
00103 GET24(v, w); \
00104 if (v == 0xffffffu) \
00105 GET32(v, w); \
00106 } while (0)
00107
00108 #define GET_OFFSET(v, w) GET32(v, w)
00109
00110 #define GET_MEM(v, c, w) \
00111 do { \
00112 memmove(v, w, c); \
00113 w += c; \
00114 } while (0)
00115
00116 #define GET_TYPE(v, w) \
00117 do { \
00118 GET8(v, w); \
00119 if (v > 127) { \
00120 if (v < 255) \
00121 v = ((v & 0x7f) << 16) | ISCCC_RDATATYPE_SIG; \
00122 else \
00123 GET32(v, w); \
00124 } \
00125 } while (0)
00126
00127 #define PUT8(v, w) \
00128 do { \
00129 *w = (v & 0x000000ffU); \
00130 w++; \
00131 } while (0)
00132
00133 #define PUT16(v, w) \
00134 do { \
00135 w[0] = (v & 0x0000ff00U) >> 8; \
00136 w[1] = (v & 0x000000ffU); \
00137 w += 2; \
00138 } while (0)
00139
00140 #define PUT24(v, w) \
00141 do { \
00142 w[0] = (v & 0x00ff0000U) >> 16; \
00143 w[1] = (v & 0x0000ff00U) >> 8; \
00144 w[2] = (v & 0x000000ffU); \
00145 w += 3; \
00146 } while (0)
00147
00148 #define PUT32(v, w) \
00149 do { \
00150 w[0] = (v & 0xff000000U) >> 24; \
00151 w[1] = (v & 0x00ff0000U) >> 16; \
00152 w[2] = (v & 0x0000ff00U) >> 8; \
00153 w[3] = (v & 0x000000ffU); \
00154 w += 4; \
00155 } while (0)
00156
00157 #define PUT64(v, w) \
00158 do { \
00159 w[0] = (v & 0xff00000000000000ULL) >> 56; \
00160 w[1] = (v & 0x00ff000000000000ULL) >> 48; \
00161 w[2] = (v & 0x0000ff0000000000ULL) >> 40; \
00162 w[3] = (v & 0x000000ff00000000ULL) >> 32; \
00163 w[4] = (v & 0x00000000ff000000ULL) >> 24; \
00164 w[5] = (v & 0x0000000000ff0000ULL) >> 16; \
00165 w[6] = (v & 0x000000000000ff00ULL) >> 8; \
00166 w[7] = (v & 0x00000000000000ffULL); \
00167 w += 8; \
00168 } while (0)
00169
00170 #define PUTC16(v, w) \
00171 do { \
00172 if (v > 0 && v < 255) \
00173 PUT8(v, w); \
00174 else { \
00175 PUT8(255, w); \
00176 PUT16(v, w); \
00177 } \
00178 } while (0)
00179
00180 #define PUTC32(v, w) \
00181 do { \
00182 if (v < 0xffffffU) \
00183 PUT24(v, w); \
00184 else { \
00185 PUT24(0xffffffU, w); \
00186 PUT32(v, w); \
00187 } \
00188 } while (0)
00189
00190 #define PUT_OFFSET(v, w) PUT32(v, w)
00191
00192 #include <string.h>
00193
00194 #define PUT_MEM(s, c, w) \
00195 do { \
00196 memmove(w, s, c); \
00197 w += c; \
00198 } while (0)
00199
00200
00201
00202
00203 #define REGION_SIZE(r) ((unsigned int)((r).rend - (r).rstart))
00204 #define REGION_EMPTY(r) ((r).rstart == (r).rend)
00205 #define REGION_FROMSTRING(r, s) do { \
00206 (r).rstart = (unsigned char *)s; \
00207 (r).rend = (r).rstart + strlen(s); \
00208 } while (0)
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218 #define DE_CONST(konst, var) \
00219 do { \
00220 union { const void *k; void *v; } _u; \
00221 _u.k = konst; \
00222 var = _u.v; \
00223 } while (0)
00224
00225 #endif