-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil.c
More file actions
49 lines (39 loc) · 1.06 KB
/
util.c
File metadata and controls
49 lines (39 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// SPDX-License-Identifier: GPL-2.0-only
#include "lldp.h"
void *
memdup(const void* mem, size_t size)
{
void *out = malloc(size);
if (out != NULL)
memcpy(out, mem, size);
return out;
}
int
avl_mac_cmp(const void *k1, const void *k2, void *ptr)
{
return memcmp(k1, k2, ETH_ALEN);
}
void
blobmsg_add_ipv4(struct blob_buf *b, const char *name, const __u8 *addr)
{
char ip[16];
snprintf(ip, sizeof(ip), "%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]);
blobmsg_add_string(b, name, ip);
}
void
blobmsg_add_ipv6(struct blob_buf *b, const char *name, const __u16 *addr)
{
char ip[40];
snprintf(ip, sizeof(ip), "%x:%x:%x:%x:%x:%x:%x:%x",
ntohs(addr[0]), ntohs(addr[1]), ntohs(addr[2]), ntohs(addr[3]),
ntohs(addr[4]), ntohs(addr[5]), ntohs(addr[6]), ntohs(addr[7]));
blobmsg_add_string(b, name, ip);
}
void
blobmsg_add_mac(struct blob_buf *b, const char *name, const __u8 *addr)
{
char mac[18];
snprintf(mac, sizeof(mac), "%02x:%02x:%02x:%02x:%02x:%02x",
addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
blobmsg_add_string(b, name, mac);
}