2 * Portions Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Portions Copyright (C) 2001 Internet Software Consortium.
4 * Portions Copyright (C) 2001 Nominum, Inc.
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NOMINUM DISCLAIMS ALL
11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
12 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY
13 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 /* $Id: util.h,v 1.3.206.1 2004/03/06 08:15:23 marka Exp $ */
22 #define ISCCC_UTIL_H 1
27 * Macros for dealing with unaligned numbers.
29 * Note: no side effects are allowed when invoking these macros!
40 v = (unsigned int)w[0] << 8; \
41 v |= (unsigned int)w[1]; \
47 v = (unsigned int)w[0] << 16; \
48 v |= (unsigned int)w[1] << 8; \
49 v |= (unsigned int)w[2]; \
55 v = (unsigned int)w[0] << 24; \
56 v |= (unsigned int)w[1] << 16; \
57 v |= (unsigned int)w[2] << 8; \
58 v |= (unsigned int)w[3]; \
64 v = (isc_uint64_t)w[0] << 56; \
65 v |= (isc_uint64_t)w[1] << 48; \
66 v |= (isc_uint64_t)w[2] << 40; \
67 v |= (isc_uint64_t)w[3] << 32; \
68 v |= (isc_uint64_t)w[4] << 24; \
69 v |= (isc_uint64_t)w[5] << 16; \
70 v |= (isc_uint64_t)w[6] << 8; \
71 v |= (isc_uint64_t)w[7]; \
75 #define GETC16(v, w, d) \
87 #define GETC32(v, w) \
94 #define GET_OFFSET(v, w) GET32(v, w)
96 #define GET_MEM(v, c, w) \
102 #define GET_TYPE(v, w) \
107 v = ((v & 0x7f) << 16) | ISCCC_RDATATYPE_SIG; \
115 *w = (v & 0x000000ffU); \
119 #define PUT16(v, w) \
121 w[0] = (v & 0x0000ff00U) >> 8; \
122 w[1] = (v & 0x000000ffU); \
126 #define PUT24(v, w) \
128 w[0] = (v & 0x00ff0000U) >> 16; \
129 w[1] = (v & 0x0000ff00U) >> 8; \
130 w[2] = (v & 0x000000ffU); \
134 #define PUT32(v, w) \
136 w[0] = (v & 0xff000000U) >> 24; \
137 w[1] = (v & 0x00ff0000U) >> 16; \
138 w[2] = (v & 0x0000ff00U) >> 8; \
139 w[3] = (v & 0x000000ffU); \
143 #define PUT64(v, w) \
145 w[0] = (v & 0xff00000000000000ULL) >> 56; \
146 w[1] = (v & 0x00ff000000000000ULL) >> 48; \
147 w[2] = (v & 0x0000ff0000000000ULL) >> 40; \
148 w[3] = (v & 0x000000ff00000000ULL) >> 32; \
149 w[4] = (v & 0x00000000ff000000ULL) >> 24; \
150 w[5] = (v & 0x0000000000ff0000ULL) >> 16; \
151 w[6] = (v & 0x000000000000ff00ULL) >> 8; \
152 w[7] = (v & 0x00000000000000ffULL); \
156 #define PUTC16(v, w) \
158 if (v > 0 && v < 255) \
166 #define PUTC32(v, w) \
171 PUT24(0xffffffU, w); \
176 #define PUT_OFFSET(v, w) PUT32(v, w)
180 #define PUT_MEM(s, c, w) \
189 #define REGION_SIZE(r) ((unsigned int)((r).rend - (r).rstart))
190 #define REGION_EMPTY(r) ((r).rstart == (r).rend)
191 #define REGION_FROMSTRING(r, s) do { \
192 (r).rstart = (unsigned char *)s; \
193 (r).rend = (r).rstart + strlen(s); \
197 * Use this to remove the const qualifier of a variable to assign it to
198 * a non-const variable or pass it as a non-const function argument ...
199 * but only when you are sure it won't then be changed!
200 * This is necessary to sometimes shut up some compilers
201 * (as with gcc -Wcast-qual) when there is just no other good way to avoid the
204 #define DE_CONST(konst, var) \
206 union { const void *k; void *v; } _u; \
211 #endif /* ISCCC_UTIL_H */