]>
The Tcpdump Group git mirrors - tcpdump/blob - extract.h
2 * Copyright (c) 1992, 1993, 1994, 1995, 1996
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
25 * For 8-bit values; needed to fetch a one-byte value. Byte order
26 * isn't relevant, and alignment isn't an issue.
28 #define EXTRACT_U_1(p) (*(p))
29 #define EXTRACT_S_1(p) ((int8_t)(*(p)))
32 * Inline functions or macros to extract possibly-unaligned big-endian
35 #include "funcattrs.h"
38 * If we have versions of GCC or Clang that support an __attribute__
39 * to say "if we're building with unsigned behavior sanitization,
40 * don't complain about undefined behavior in this function", we
41 * label these functions with that attribute - we *know* it's undefined
42 * in the C standard, but we *also* know it does what we want with
43 * the ISA we're targeting and the compiler we're using.
45 * For GCC 4.9.0 and later, we use __attribute__((no_sanitize_undefined));
46 * pre-5.0 GCC doesn't have __has_attribute, and I'm not sure whether
47 * GCC or Clang first had __attribute__((no_sanitize(XXX)).
49 * For Clang, we check for __attribute__((no_sanitize(XXX)) with
50 * __has_attribute, as there are versions of Clang that support
51 * __attribute__((no_sanitize("undefined")) but don't support
52 * __attribute__((no_sanitize_undefined)).
54 * We define this here, rather than in funcattrs.h, because we
55 * only want it used here, we don't want it to be broadly used.
56 * (Any printer will get this defined, but this should at least
57 * make it harder for people to find.)
59 #if defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 409)
60 #define UNALIGNED_OK __attribute__((no_sanitize_undefined))
61 #elif __has_attribute(no_sanitize)
62 #define UNALIGNED_OK __attribute__((no_sanitize("undefined")))
67 #if (defined(__i386__) || defined(_M_IX86) || defined(__X86__) || defined(__x86_64__) || defined(_M_X64)) || \
68 (defined(__arm__) || defined(_M_ARM) || defined(__aarch64__)) || \
69 (defined(__m68k__) && (!defined(__mc68000__) && !defined(__mc68010__))) || \
70 (defined(__ppc__) || defined(__ppc64__) || defined(_M_PPC) || defined(_ARCH_PPC) || defined(_ARCH_PPC64)) || \
71 (defined(__s390__) || defined(__s390x__) || defined(__zarch__))
73 * The processor natively handles unaligned loads, so we can just
74 * cast the pointer and fetch through it.
76 * XXX - are those all the x86 tests we need?
77 * XXX - do we need to worry about ARMv1 through ARMv5, which didn't
78 * support unaligned loads, and, if so, do we need to worry about all
79 * of them, or just some of them, e.g. ARMv5?
80 * XXX - are those the only 68k tests we need not to generated
81 * unaligned accesses if the target is the 68000 or 68010?
82 * XXX - are there any tests we don't need, because some definitions are for
83 * compilers that also predefine the GCC symbols?
84 * XXX - do we need to test for both 32-bit and 64-bit versions of those
85 * architectures in all cases?
87 static inline uint16_t UNALIGNED_OK
88 EXTRACT_BE_U_2(const void *p
)
90 return ((uint16_t)ntohs(*(const uint16_t *)(p
)));
93 static inline int16_t UNALIGNED_OK
94 EXTRACT_BE_S_2(const void *p
)
96 return ((int16_t)ntohs(*(const int16_t *)(p
)));
99 static inline uint32_t UNALIGNED_OK
100 EXTRACT_BE_U_4(const void *p
)
102 return ((uint32_t)ntohl(*(const uint32_t *)(p
)));
105 static inline int32_t UNALIGNED_OK
106 EXTRACT_BE_S_4(const void *p
)
108 return ((int32_t)ntohl(*(const int32_t *)(p
)));
111 static inline uint64_t UNALIGNED_OK
112 EXTRACT_BE_U_8(const void *p
)
114 return ((uint64_t)(((uint64_t)ntohl(*((const uint32_t *)(p
) + 0))) << 32 |
115 ((uint64_t)ntohl(*((const uint32_t *)(p
) + 1))) << 0));
119 static inline int64_t UNALIGNED_OK
120 EXTRACT_BE_S_8(const void *p
)
122 return ((int64_t)(((int64_t)ntohl(*((const uint32_t *)(p
) + 0))) << 32 |
123 ((uint64_t)ntohl(*((const uint32_t *)(p
) + 1))) << 0));
128 * Extract an IPv4 address, which is in network byte order, and not
129 * necessarily aligned, and provide the result in host byte order.
131 static inline uint32_t UNALIGNED_OK
132 EXTRACT_IPV4_TO_HOST_ORDER(const void *p
)
134 return ((uint32_t)ntohl(*(const uint32_t *)(p
)));
136 #elif defined(__GNUC__) && defined(HAVE___ATTRIBUTE__) && \
137 (defined(__alpha) || defined(__alpha__) || \
138 defined(__mips) || defined(__mips__))
140 * This is MIPS or Alpha, which don't natively handle unaligned loads,
141 * but which have instructions that can help when doing unaligned
142 * loads, and this is a GCC-compatible compiler and we have __attribute__,
143 * which we assume that mean we have __attribute__((packed)), which
144 * we can use to convince the compiler to generate those instructions.
146 * Declare packed structures containing a uint16_t and a uint32_t,
147 * cast the pointer to point to one of those, and fetch through it;
148 * the GCC manual doesn't appear to explicitly say that
149 * __attribute__((packed)) causes the compiler to generate unaligned-safe
150 * code, but it apppears to do so.
152 * We do this in case the compiler can generate code using those
153 * instructions to do an unaligned load and pass stuff to "ntohs()" or
154 * "ntohl()", which might be better than than the code to fetch the
155 * bytes one at a time and assemble them. (That might not be the
156 * case on a little-endian platform, such as DEC's MIPS machines and
157 * Alpha machines, where "ntohs()" and "ntohl()" might not be done
160 * We do this only for specific architectures because, for example,
161 * at least some versions of GCC, when compiling for 64-bit SPARC,
162 * generate code that assumes alignment if we do this.
164 * XXX - add other architectures and compilers as possible and
167 * HP's C compiler, indicated by __HP_cc being defined, supports
168 * "#pragma unaligned N" in version A.05.50 and later, where "N"
169 * specifies a number of bytes at which the typedef on the next
170 * line is aligned, e.g.
173 * typedef uint16_t unaligned_uint16_t;
175 * to define unaligned_uint16_t as a 16-bit unaligned data type.
176 * This could be presumably used, in sufficiently recent versions of
177 * the compiler, with macros similar to those below. This would be
178 * useful only if that compiler could generate better code for PA-RISC
179 * or Itanium than would be generated by a bunch of shifts-and-ORs.
181 * DEC C, indicated by __DECC being defined, has, at least on Alpha,
182 * an __unaligned qualifier that can be applied to pointers to get the
183 * compiler to generate code that does unaligned loads and stores when
184 * dereferencing the pointer in question.
186 * XXX - what if the native C compiler doesn't support
187 * __attribute__((packed))? How can we get it to generate unaligned
188 * accesses for *specific* items?
192 } __attribute__((packed
)) unaligned_uint16_t
;
196 } __attribute__((packed
)) unaligned_int16_t
;
200 } __attribute__((packed
)) unaligned_uint32_t
;
204 } __attribute__((packed
)) unaligned_int32_t
;
206 UNALIGNED_OK
static inline uint16_t
207 EXTRACT_BE_U_2(const void *p
)
209 return ((uint16_t)ntohs(((const unaligned_uint16_t
*)(p
))->val
));
212 UNALIGNED_OK
static inline int16_t
213 EXTRACT_BE_S_2(const void *p
)
215 return ((int16_t)ntohs(((const unaligned_int16_t
*)(p
))->val
));
218 UNALIGNED_OK
static inline uint32_t
219 EXTRACT_BE_U_4(const void *p
)
221 return ((uint32_t)ntohl(((const unaligned_uint32_t
*)(p
))->val
));
224 UNALIGNED_OK
static inline int32_t
225 EXTRACT_BE_S_4(const void *p
)
227 return ((int32_t)ntohl(((const unaligned_int32_t
*)(p
))->val
));
230 UNALIGNED_OK
static inline uint64_t
231 EXTRACT_BE_U_8(const void *p
)
233 return ((uint64_t)(((uint64_t)ntohl(((const unaligned_uint32_t
*)(p
) + 0)->val
)) << 32 |
234 ((uint64_t)ntohl(((const unaligned_uint32_t
*)(p
) + 1)->val
)) << 0));
237 UNALIGNED_OK
static inline int64_t
238 EXTRACT_BE_S_8(const void *p
)
240 return ((int64_t)(((uint64_t)ntohl(((const unaligned_uint32_t
*)(p
) + 0)->val
)) << 32 |
241 ((uint64_t)ntohl(((const unaligned_uint32_t
*)(p
) + 1)->val
)) << 0));
245 * Extract an IPv4 address, which is in network byte order, and not
246 * necessarily aligned, and provide the result in host byte order.
248 UNALIGNED_OK
static inline uint32_t
249 EXTRACT_IPV4_TO_HOST_ORDER(const void *p
)
251 return ((uint32_t)ntohl(((const unaligned_uint32_t
*)(p
))->val
));
255 * This architecture doesn't natively support unaligned loads, and either
256 * this isn't a GCC-compatible compiler, we don't have __attribute__,
257 * or we do but we don't know of any better way with this instruction
258 * set to do unaligned loads, so do unaligned loads of big-endian
259 * quantities the hard way - fetch the bytes one at a time and
262 #define EXTRACT_BE_U_2(p) \
263 ((uint16_t)(((uint16_t)(*((const uint8_t *)(p) + 0)) << 8) | \
264 ((uint16_t)(*((const uint8_t *)(p) + 1)) << 0)))
265 #define EXTRACT_BE_S_2(p) \
266 ((int16_t)(((uint16_t)(*((const uint8_t *)(p) + 0)) << 8) | \
267 ((uint16_t)(*((const uint8_t *)(p) + 1)) << 0)))
268 #define EXTRACT_BE_U_4(p) \
269 ((uint32_t)(((uint32_t)(*((const uint8_t *)(p) + 0)) << 24) | \
270 ((uint32_t)(*((const uint8_t *)(p) + 1)) << 16) | \
271 ((uint32_t)(*((const uint8_t *)(p) + 2)) << 8) | \
272 ((uint32_t)(*((const uint8_t *)(p) + 3)) << 0)))
273 #define EXTRACT_BE_S_4(p) \
274 ((int32_t)(((uint32_t)(*((const uint8_t *)(p) + 0)) << 24) | \
275 ((uint32_t)(*((const uint8_t *)(p) + 1)) << 16) | \
276 ((uint32_t)(*((const uint8_t *)(p) + 2)) << 8) | \
277 ((uint32_t)(*((const uint8_t *)(p) + 3)) << 0)))
278 #define EXTRACT_BE_U_8(p) \
279 ((uint64_t)(((uint64_t)(*((const uint8_t *)(p) + 0)) << 56) | \
280 ((uint64_t)(*((const uint8_t *)(p) + 1)) << 48) | \
281 ((uint64_t)(*((const uint8_t *)(p) + 2)) << 40) | \
282 ((uint64_t)(*((const uint8_t *)(p) + 3)) << 32) | \
283 ((uint64_t)(*((const uint8_t *)(p) + 4)) << 24) | \
284 ((uint64_t)(*((const uint8_t *)(p) + 5)) << 16) | \
285 ((uint64_t)(*((const uint8_t *)(p) + 6)) << 8) | \
286 ((uint64_t)(*((const uint8_t *)(p) + 7)) << 0)))
287 #define EXTRACT_BE_S_8(p) \
288 ((int64_t)(((uint64_t)(*((const uint8_t *)(p) + 0)) << 56) | \
289 ((uint64_t)(*((const uint8_t *)(p) + 1)) << 48) | \
290 ((uint64_t)(*((const uint8_t *)(p) + 2)) << 40) | \
291 ((uint64_t)(*((const uint8_t *)(p) + 3)) << 32) | \
292 ((uint64_t)(*((const uint8_t *)(p) + 4)) << 24) | \
293 ((uint64_t)(*((const uint8_t *)(p) + 5)) << 16) | \
294 ((uint64_t)(*((const uint8_t *)(p) + 6)) << 8) | \
295 ((uint64_t)(*((const uint8_t *)(p) + 7)) << 0)))
298 * Extract an IPv4 address, which is in network byte order, and not
299 * necessarily aligned, and provide the result in host byte order.
301 #define EXTRACT_IPV4_TO_HOST_ORDER(p) \
302 ((uint32_t)(((uint32_t)(*((const uint8_t *)(p) + 0)) << 24) | \
303 ((uint32_t)(*((const uint8_t *)(p) + 1)) << 16) | \
304 ((uint32_t)(*((const uint8_t *)(p) + 2)) << 8) | \
305 ((uint32_t)(*((const uint8_t *)(p) + 3)) << 0)))
306 #endif /* unaligned access checks */
309 * Extract numerical values in *host* byte order. (Some metadata
310 * headers are in the byte order of the host that wrote the file,
311 * and libpcap translate them to the byte order of the host
312 * reading the file. This means that if a program on that host
313 * reads with libpcap and writes to a new file, the new file will
314 * be written in the byte order of the host writing the file. Thus,
315 * the magic number in pcap files and byte-order magic in pcapng
316 * files can be used to determine the byte order in those metadata
319 * XXX - on platforms that can do unaligned accesses, just cast and
320 * dereference the pointer.
322 static inline uint16_t
323 EXTRACT_HE_U_2(const void *p
)
327 UNALIGNED_MEMCPY(&val
, p
, sizeof(uint16_t));
331 static inline uint16_t
332 EXTRACT_HE_S_2(const void *p
)
336 UNALIGNED_MEMCPY(&val
, p
, sizeof(int16_t));
340 static inline uint16_t
341 EXTRACT_HE_U_4(const void *p
)
345 UNALIGNED_MEMCPY(&val
, p
, sizeof(uint32_t));
349 static inline uint16_t
350 EXTRACT_HE_S_4(const void *p
)
354 UNALIGNED_MEMCPY(&val
, p
, sizeof(int32_t));
359 * Extract an IPv4 address, which is in network byte order, and which
360 * is not necessarily aligned on a 4-byte boundary, and provide the
361 * result in network byte order.
363 * This works the same way regardless of the host's byte order.
365 static inline uint32_t
366 EXTRACT_IPV4_TO_NETWORK_ORDER(const void *p
)
370 UNALIGNED_MEMCPY(&addr
, p
, sizeof(uint32_t));
375 * Non-power-of-2 sizes.
377 #define EXTRACT_BE_U_3(p) \
378 ((uint32_t)(((uint32_t)(*((const uint8_t *)(p) + 0)) << 16) | \
379 ((uint32_t)(*((const uint8_t *)(p) + 1)) << 8) | \
380 ((uint32_t)(*((const uint8_t *)(p) + 2)) << 0)))
382 #define EXTRACT_BE_S_3(p) \
383 (((*((const uint8_t *)(p) + 0)) & 0x80) ? \
384 ((int32_t)(((uint32_t)(*((const uint8_t *)(p) + 0)) << 16) | \
385 ((uint32_t)(*((const uint8_t *)(p) + 1)) << 8) | \
386 ((uint32_t)(*((const uint8_t *)(p) + 2)) << 0))) : \
387 ((int32_t)(0xFF000000U | \
388 ((uint32_t)(*((const uint8_t *)(p) + 0)) << 16) | \
389 ((uint32_t)(*((const uint8_t *)(p) + 1)) << 8) | \
390 ((uint32_t)(*((const uint8_t *)(p) + 2)) << 0))))
392 #define EXTRACT_BE_U_5(p) \
393 ((uint64_t)(((uint64_t)(*((const uint8_t *)(p) + 0)) << 32) | \
394 ((uint64_t)(*((const uint8_t *)(p) + 1)) << 24) | \
395 ((uint64_t)(*((const uint8_t *)(p) + 2)) << 16) | \
396 ((uint64_t)(*((const uint8_t *)(p) + 3)) << 8) | \
397 ((uint64_t)(*((const uint8_t *)(p) + 4)) << 0)))
399 #define EXTRACT_BE_S_5(p) \
400 (((*((const uint8_t *)(p) + 0)) & 0x80) ? \
401 ((int64_t)(((uint64_t)(*((const uint8_t *)(p) + 0)) << 32) | \
402 ((uint64_t)(*((const uint8_t *)(p) + 1)) << 24) | \
403 ((uint64_t)(*((const uint8_t *)(p) + 2)) << 16) | \
404 ((uint64_t)(*((const uint8_t *)(p) + 3)) << 8) | \
405 ((uint64_t)(*((const uint8_t *)(p) + 4)) << 0))) : \
406 ((int64_t)(INT64_T_CONSTANT(0xFFFFFF0000000000U) | \
407 ((uint64_t)(*((const uint8_t *)(p) + 0)) << 32) | \
408 ((uint64_t)(*((const uint8_t *)(p) + 1)) << 24) | \
409 ((uint64_t)(*((const uint8_t *)(p) + 2)) << 16) | \
410 ((uint64_t)(*((const uint8_t *)(p) + 3)) << 8) | \
411 ((uint64_t)(*((const uint8_t *)(p) + 4)) << 0))))
413 #define EXTRACT_BE_U_6(p) \
414 ((uint64_t)(((uint64_t)(*((const uint8_t *)(p) + 0)) << 40) | \
415 ((uint64_t)(*((const uint8_t *)(p) + 1)) << 32) | \
416 ((uint64_t)(*((const uint8_t *)(p) + 2)) << 24) | \
417 ((uint64_t)(*((const uint8_t *)(p) + 3)) << 16) | \
418 ((uint64_t)(*((const uint8_t *)(p) + 4)) << 8) | \
419 ((uint64_t)(*((const uint8_t *)(p) + 5)) << 0)))
421 #define EXTRACT_BE_S_6(p) \
422 (((*((const uint8_t *)(p) + 0)) & 0x80) ? \
423 ((uint64_t)(((uint64_t)(*((const uint8_t *)(p) + 0)) << 40) | \
424 ((uint64_t)(*((const uint8_t *)(p) + 1)) << 32) | \
425 ((uint64_t)(*((const uint8_t *)(p) + 2)) << 24) | \
426 ((uint64_t)(*((const uint8_t *)(p) + 3)) << 16) | \
427 ((uint64_t)(*((const uint8_t *)(p) + 4)) << 8) | \
428 ((uint64_t)(*((const uint8_t *)(p) + 5)) << 0))) : \
429 ((int64_t)(INT64_T_CONSTANT(0xFFFFFFFF00000000U) | \
430 ((uint64_t)(*((const uint8_t *)(p) + 0)) << 40) | \
431 ((uint64_t)(*((const uint8_t *)(p) + 1)) << 32) | \
432 ((uint64_t)(*((const uint8_t *)(p) + 2)) << 24) | \
433 ((uint64_t)(*((const uint8_t *)(p) + 3)) << 16) | \
434 ((uint64_t)(*((const uint8_t *)(p) + 4)) << 8) | \
435 ((uint64_t)(*((const uint8_t *)(p) + 5)) << 0))))
437 #define EXTRACT_BE_U_7(p) \
438 ((uint64_t)(((uint64_t)(*((const uint8_t *)(p) + 0)) << 48) | \
439 ((uint64_t)(*((const uint8_t *)(p) + 1)) << 40) | \
440 ((uint64_t)(*((const uint8_t *)(p) + 2)) << 32) | \
441 ((uint64_t)(*((const uint8_t *)(p) + 3)) << 24) | \
442 ((uint64_t)(*((const uint8_t *)(p) + 4)) << 16) | \
443 ((uint64_t)(*((const uint8_t *)(p) + 5)) << 8) | \
444 ((uint64_t)(*((const uint8_t *)(p) + 6)) << 0)))
446 #define EXTRACT_BE_S_7(p) \
447 (((*((const uint8_t *)(p) + 0)) & 0x80) ? \
448 ((int64_t)(((uint64_t)(*((const uint8_t *)(p) + 0)) << 48) | \
449 ((uint64_t)(*((const uint8_t *)(p) + 1)) << 40) | \
450 ((uint64_t)(*((const uint8_t *)(p) + 2)) << 32) | \
451 ((uint64_t)(*((const uint8_t *)(p) + 3)) << 24) | \
452 ((uint64_t)(*((const uint8_t *)(p) + 4)) << 16) | \
453 ((uint64_t)(*((const uint8_t *)(p) + 5)) << 8) | \
454 ((uint64_t)(*((const uint8_t *)(p) + 6)) << 0))) : \
455 ((int64_t)(INT64_T_CONSTANT(0xFFFFFFFFFF000000U) | \
456 ((uint64_t)(*((const uint8_t *)(p) + 0)) << 48) | \
457 ((uint64_t)(*((const uint8_t *)(p) + 1)) << 40) | \
458 ((uint64_t)(*((const uint8_t *)(p) + 2)) << 32) | \
459 ((uint64_t)(*((const uint8_t *)(p) + 3)) << 24) | \
460 ((uint64_t)(*((const uint8_t *)(p) + 4)) << 16) | \
461 ((uint64_t)(*((const uint8_t *)(p) + 5)) << 8) | \
462 ((uint64_t)(*((const uint8_t *)(p) + 6)) << 0))))
465 * Macros to extract possibly-unaligned little-endian integral values.
466 * XXX - do loads on little-endian machines that support unaligned loads?
468 #define EXTRACT_LE_U_2(p) \
469 ((uint16_t)(((uint16_t)(*((const uint8_t *)(p) + 1)) << 8) | \
470 ((uint16_t)(*((const uint8_t *)(p) + 0)) << 0)))
471 #define EXTRACT_LE_S_2(p) \
472 ((int16_t)(((uint16_t)(*((const uint8_t *)(p) + 1)) << 8) | \
473 ((uint16_t)(*((const uint8_t *)(p) + 0)) << 0)))
474 #define EXTRACT_LE_U_4(p) \
475 ((uint32_t)(((uint32_t)(*((const uint8_t *)(p) + 3)) << 24) | \
476 ((uint32_t)(*((const uint8_t *)(p) + 2)) << 16) | \
477 ((uint32_t)(*((const uint8_t *)(p) + 1)) << 8) | \
478 ((uint32_t)(*((const uint8_t *)(p) + 0)) << 0)))
479 #define EXTRACT_LE_S_4(p) \
480 ((int32_t)(((uint32_t)(*((const uint8_t *)(p) + 3)) << 24) | \
481 ((uint32_t)(*((const uint8_t *)(p) + 2)) << 16) | \
482 ((uint32_t)(*((const uint8_t *)(p) + 1)) << 8) | \
483 ((uint32_t)(*((const uint8_t *)(p) + 0)) << 0)))
484 #define EXTRACT_LE_U_3(p) \
485 ((uint32_t)(((uint32_t)(*((const uint8_t *)(p) + 2)) << 16) | \
486 ((uint32_t)(*((const uint8_t *)(p) + 1)) << 8) | \
487 ((uint32_t)(*((const uint8_t *)(p) + 0)) << 0)))
488 #define EXTRACT_LE_S_3(p) \
489 ((int32_t)(((uint32_t)(*((const uint8_t *)(p) + 2)) << 16) | \
490 ((uint32_t)(*((const uint8_t *)(p) + 1)) << 8) | \
491 ((uint32_t)(*((const uint8_t *)(p) + 0)) << 0)))
492 #define EXTRACT_LE_U_8(p) \
493 ((uint64_t)(((uint64_t)(*((const uint8_t *)(p) + 7)) << 56) | \
494 ((uint64_t)(*((const uint8_t *)(p) + 6)) << 48) | \
495 ((uint64_t)(*((const uint8_t *)(p) + 5)) << 40) | \
496 ((uint64_t)(*((const uint8_t *)(p) + 4)) << 32) | \
497 ((uint64_t)(*((const uint8_t *)(p) + 3)) << 24) | \
498 ((uint64_t)(*((const uint8_t *)(p) + 2)) << 16) | \
499 ((uint64_t)(*((const uint8_t *)(p) + 1)) << 8) | \
500 ((uint64_t)(*((const uint8_t *)(p) + 0)) << 0)))
501 #define EXTRACT_LE_S_8(p) \
502 ((int64_t)(((uint64_t)(*((const uint8_t *)(p) + 7)) << 56) | \
503 ((uint64_t)(*((const uint8_t *)(p) + 6)) << 48) | \
504 ((uint64_t)(*((const uint8_t *)(p) + 5)) << 40) | \
505 ((uint64_t)(*((const uint8_t *)(p) + 4)) << 32) | \
506 ((uint64_t)(*((const uint8_t *)(p) + 3)) << 24) | \
507 ((uint64_t)(*((const uint8_t *)(p) + 2)) << 16) | \
508 ((uint64_t)(*((const uint8_t *)(p) + 1)) << 8) | \
509 ((uint64_t)(*((const uint8_t *)(p) + 0)) << 0)))
512 * Macros to check the presence of the values in question.
514 #define ND_TTEST_1(p) ND_TTEST_LEN((p), 1)
515 #define ND_TCHECK_1(p) ND_TCHECK_LEN((p), 1)
517 #define ND_TTEST_2(p) ND_TTEST_LEN((p), 2)
518 #define ND_TCHECK_2(p) ND_TCHECK_LEN((p), 2)
520 #define ND_TTEST_3(p) ND_TTEST_LEN((p), 3)
521 #define ND_TCHECK_3(p) ND_TCHECK_LEN((p), 3)
523 #define ND_TTEST_4(p) ND_TTEST_LEN((p), 4)
524 #define ND_TCHECK_4(p) ND_TCHECK_LEN((p), 4)
526 #define ND_TTEST_5(p) ND_TTEST_LEN((p), 5)
527 #define ND_TCHECK_5(p) ND_TCHECK_LEN((p), 5)
529 #define ND_TTEST_6(p) ND_TTEST_LEN((p), 6)
530 #define ND_TCHECK_6(p) ND_TCHECK_LEN((p), 6)
532 #define ND_TTEST_7(p) ND_TTEST_LEN((p), 7)
533 #define ND_TCHECK_7(p) ND_TCHECK_LEN((p), 7)
535 #define ND_TTEST_8(p) ND_TTEST_LEN((p), 8)
536 #define ND_TCHECK_8(p) ND_TCHECK_LEN((p), 8)
538 #define ND_TTEST_16(p) ND_TTEST_LEN((p), 16)
539 #define ND_TCHECK_16(p) ND_TCHECK_LEN((p), 16)