strace/print_mac.c
Dmitry V. Levin b93d52fe3d Change the license of strace to LGPL-2.1-or-later
strace is now provided under the terms of the GNU Lesser General
Public License version 2.1 or later, see COPYING for more details.

strace test suite is now provided under the terms of the GNU General
Public License version 2 or later, see tests/COPYING for more details.
2018-12-10 00:00:00 +00:00

36 lines
640 B
C

/*
* Copyright (c) 2018 The strace developers.
* All rights reserved.
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "defs.h"
#include "error_prints.h"
#include "xstring.h"
#ifndef MAX_ADDR_LEN
# define MAX_ADDR_LEN 32
#endif
const char *
sprint_mac_addr(const uint8_t addr[], size_t size)
{
static char res[MAX_ADDR_LEN * 3];
if (size > MAX_ADDR_LEN) {
error_func_msg("Address size (%zu) is more than maximum "
"supported (%u)", size, MAX_ADDR_LEN);
return NULL;
}
char *ptr = res;
for (size_t i = 0; i < size; i++)
ptr = xappendstr(res, ptr, "%s%02x", i ? ":" : "", addr[i]);
return res;
}