I have uint8_t orig[ETH_ALEN];
How can I print it using __printf(3, 4)
which is defined as #define __printf(a, b) __attribute__((format(printf, a, b)))
the Orig should be ethernet hardware address.
I have uint8_t orig[ETH_ALEN];
How can I print it using __printf(3, 4)
which is defined as #define __printf(a, b) __attribute__((format(printf, a, b)))
the Orig should be ethernet hardware address.
Use C99 format specifiers:
#include <inttypes.h>
printf("%" PRIu8 "\n", orig[0]);
You need to construct a format string that's suitable. The printf()
function has no way of printing an array in one go, so you need to split it and print each uint8_t
:
__printf("MAC: %02x:%02x:%02x:%02x:%02x:%02x\n",
orig[0] & 0xff, orig[1] & 0xff, orig[2] & 0xff,
orig[3] & 0xff, orig[4] & 0xff, orig[5] & 0xff);
The & 0xff
is to ensure onlu 8 bits is sent to printf()
; they shouldn't be needed for an unsigned type like uint8_t
though so you can try without too.
This assumes a regular 48-bit MAC, and prints using the conventional colon-separated hex style.