]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Use ISC_UxxTOyy_BE macros for {peek,get,put}_uint16 macros
authorOndřej Surý <ondrej@isc.org>
Mon, 18 Aug 2025 06:05:33 +0000 (08:05 +0200)
committerOndřej Surý <ondrej@isc.org>
Mon, 18 Aug 2025 10:36:47 +0000 (12:36 +0200)
Reduce the duplication and use existing macros from isc/endian.h for
network to host and vice versa conversion.

lib/dns/rdataslab_p.h

index 2fed31a2f0420dfe9b5f93adf1def1001f5a45b3..5ce39fbbc635aa59b1c9e84d5271df4fcbb162c2 100644 (file)
@@ -13,6 +13,8 @@
 
 #pragma once
 
+#include <isc/endian.h>
+
 #include <dns/rdataslab.h>
 
 #define ANCIENT(header)                                \
        ((atomic_load_acquire(&(header)->attributes) & \
          DNS_SLABHEADERATTR_ZEROTTL) != 0)
 
-#define peek_uint16(buffer) ({ ((uint16_t)*(buffer) << 8) | *((buffer) + 1); })
+#define peek_uint16(buffer) ISC_U8TO16_BE(buffer)
 #define get_uint16(buffer)                            \
        ({                                            \
                uint16_t __ret = peek_uint16(buffer); \
                buffer += sizeof(uint16_t);           \
                __ret;                                \
        })
-#define put_uint16(buffer, val)                  \
-       ({                                       \
-               *buffer++ = (val & 0xff00) >> 8; \
-               *buffer++ = (val & 0x00ff);      \
-       })
+#define put_uint16(buffer, val)               \
+       {                                     \
+               ISC_U16TO8_BE(buffer, val);   \
+               (buffer) += sizeof(uint16_t); \
+       }