Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

print_mac.c 640B

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * Copyright (c) 2018 The strace developers.
  3. * All rights reserved.
  4. *
  5. * SPDX-License-Identifier: LGPL-2.1-or-later
  6. */
  7. #include "defs.h"
  8. #include "error_prints.h"
  9. #include "xstring.h"
  10. #ifndef MAX_ADDR_LEN
  11. # define MAX_ADDR_LEN 32
  12. #endif
  13. const char *
  14. sprint_mac_addr(const uint8_t addr[], size_t size)
  15. {
  16. static char res[MAX_ADDR_LEN * 3];
  17. if (size > MAX_ADDR_LEN) {
  18. error_func_msg("Address size (%zu) is more than maximum "
  19. "supported (%u)", size, MAX_ADDR_LEN);
  20. return NULL;
  21. }
  22. char *ptr = res;
  23. for (size_t i = 0; i < size; i++)
  24. ptr = xappendstr(res, ptr, "%s%02x", i ? ":" : "", addr[i]);
  25. return res;
  26. }