mirror of
https://passt.top/passt
synced 2025-06-08 00:35:33 +02:00
util: Helper for formatting MAC addresses
There are a couple of places where we somewhat messily open code formatting an Ethernet like MAC address for display. Add an eth_ntop() helper for this. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
e6feb5a892
commit
066e69986b
4 changed files with 27 additions and 7 deletions
19
util.c
19
util.c
|
@ -676,6 +676,25 @@ const char *sockaddr_ntop(const void *sa, char *dst, socklen_t size)
|
|||
return dst;
|
||||
}
|
||||
|
||||
/** eth_ntop() - Convert an Ethernet MAC address to text format
|
||||
* @mac: MAC address
|
||||
* @dst: Output buffer, minimum ETH_ADDRSTRLEN bytes
|
||||
* @size: Size of buffer at @dst
|
||||
*
|
||||
* Return: On success, a non-null pointer to @dst, NULL on failure
|
||||
*/
|
||||
const char *eth_ntop(const unsigned char *mac, char *dst, size_t size)
|
||||
{
|
||||
int len;
|
||||
|
||||
len = snprintf(dst, size, "%02x:%02x:%02x:%02x:%02x:%02x",
|
||||
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
if (len < 0 || (size_t)len >= size)
|
||||
return NULL;
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
/** str_ee_origin() - Convert socket extended error origin to a string
|
||||
* @ee: Socket extended error structure
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue