-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon_func.c
84 lines (69 loc) · 2.11 KB
/
common_func.c
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <stdio.h>
#include <string.h>
#include "common_func.h"
#include "lldp_debug.h"
void prefix_hex_dump(char *info, uint8_t *buf, int32_t size)
{
int i;
printf("%s ", info);
for (i = 0; i < size; ++i)
printf("%02x ", buf[i]);
printf("\n");
}
void lldp_hex_dump(uint8_t *buf, int32_t size)
{
int i, j, line, col;
line = size / 16;
col = size % 16;
uint8_t lastline[16] = {0};
uint8_t *p;
if (!buf) {
lldp_printf(MSG_WARNING, "[%s %d][WARNING]send buffer is NULL, now return\n",
__FUNCTION__, __LINE__);
return;
}
p = buf;
// lldp_printf(MSG_DEBUG, "[%s %d]>>>>> size %d <<<<<\n",
// __FUNCTION__, __LINE__, size);
for (i = 0; i < line; ++i) {
lldp_printf(MSG_DEBUG, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]);
p += 16;
}
if (col != 0) {
memcpy(lastline, p, col);
p = lastline;
lldp_printf(MSG_DEBUG, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]);
}
}
void show_lldp_pdu(uint8_t *buf, int32_t size)
{
int i, j, line, col;
line = size / 16;
col = size % 16;
uint8_t lastline[16] = {0};
uint8_t *p;
if (!buf) {
lldp_printf(MSG_WARNING, "[%s %d][WARNING]send buffer is NULL, now return\n",
__FUNCTION__, __LINE__);
return;
}
p = buf;
lldp_printf(MSG_INFO, "--------------- lldp pdu %d bytes-------------\n", size);
for (i = 0; i < line; ++i) {
lldp_printf(MSG_INFO, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]);
p += 16;
}
if (col != 0) {
memcpy(lastline, p, col);
p = lastline;
lldp_printf(MSG_INFO, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]);
}
}