* For 8-bit values; needed to fetch a one-byte value. Byte order
* isn't relevant, and alignment isn't an issue.
*/
-#define EXTRACT_U_1(p) (*(p))
+#define EXTRACT_U_1(p) ((uint8_t)(*(p)))
#define EXTRACT_S_1(p) ((int8_t)(*(p)))
/*
* XXX - do we need to test for both 32-bit and 64-bit versions of those
* architectures in all cases?
*/
-static inline uint16_t UNALIGNED_OK
+UNALIGNED_OK static inline uint16_t
EXTRACT_BE_U_2(const void *p)
{
return ((uint16_t)ntohs(*(const uint16_t *)(p)));
}
-static inline int16_t UNALIGNED_OK
+UNALIGNED_OK static inline int16_t
EXTRACT_BE_S_2(const void *p)
{
return ((int16_t)ntohs(*(const int16_t *)(p)));
}
-static inline uint32_t UNALIGNED_OK
+UNALIGNED_OK static inline uint32_t
EXTRACT_BE_U_4(const void *p)
{
return ((uint32_t)ntohl(*(const uint32_t *)(p)));
}
-static inline int32_t UNALIGNED_OK
+UNALIGNED_OK static inline int32_t
EXTRACT_BE_S_4(const void *p)
{
return ((int32_t)ntohl(*(const int32_t *)(p)));
}
-static inline uint64_t UNALIGNED_OK
+UNALIGNED_OK static inline uint64_t
EXTRACT_BE_U_8(const void *p)
{
return ((uint64_t)(((uint64_t)ntohl(*((const uint32_t *)(p) + 0))) << 32 |
}
-static inline int64_t UNALIGNED_OK
+UNALIGNED_OK static inline int64_t
EXTRACT_BE_S_8(const void *p)
{
return ((int64_t)(((int64_t)ntohl(*((const uint32_t *)(p) + 0))) << 32 |
* Extract an IPv4 address, which is in network byte order, and not
* necessarily aligned, and provide the result in host byte order.
*/
-static inline uint32_t UNALIGNED_OK
+UNALIGNED_OK static inline uint32_t
EXTRACT_IPV4_TO_HOST_ORDER(const void *p)
{
return ((uint32_t)ntohl(*(const uint32_t *)(p)));
}
-#elif defined(__GNUC__) && defined(HAVE___ATTRIBUTE__) && \
+#elif ND_IS_AT_LEAST_GNUC_VERSION(2,0) && \
(defined(__alpha) || defined(__alpha__) || \
defined(__mips) || defined(__mips__))
/*
* This is MIPS or Alpha, which don't natively handle unaligned loads,
* but which have instructions that can help when doing unaligned
- * loads, and this is a GCC-compatible compiler and we have __attribute__,
- * which we assume that mean we have __attribute__((packed)), which
- * we can use to convince the compiler to generate those instructions.
+ * loads, and this is GCC 2.0 or later or a compiler that claims to
+ * be GCC 2.0 or later, which we assume that mean we have
+ * __attribute__((packed)), which we can use to convince the compiler
+ * to generate those instructions.
*
* Declare packed structures containing a uint16_t and a uint32_t,
* cast the pointer to point to one of those, and fetch through it;
return val;
}
-static inline uint16_t
+static inline int16_t
EXTRACT_HE_S_2(const void *p)
{
int16_t val;
return val;
}
-static inline uint16_t
+static inline uint32_t
EXTRACT_HE_U_4(const void *p)
{
uint32_t val;
return val;
}
-static inline uint16_t
+static inline int32_t
EXTRACT_HE_S_4(const void *p)
{
int32_t val;