1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
8 #include <rte_hexdump.h>
9 #include <rte_string_fns.h>
14 rte_hexdump(FILE *f, const char *title, const void *buf, unsigned int len)
16 unsigned int i, out, ofs;
17 const unsigned char *data = buf;
18 char line[LINE_LEN]; /* space needed 8+16*3+3+16 == 75 */
20 fprintf(f, "%s at [%p], len=%u\n",
21 title ? : " Dump data", data, len);
24 /* format the line in the buffer */
25 out = snprintf(line, LINE_LEN, "%08X:", ofs);
26 for (i = 0; i < 16; i++) {
28 snprintf(line + out, LINE_LEN - out,
29 " %02X", (data[ofs + i] & 0xff));
31 strcpy(line + out, " ");
37 out += snprintf(line + out, LINE_LEN - out, " | ");
39 for (i = 0; ofs < len && i < 16; i++, ofs++) {
40 unsigned char c = data[ofs];
42 if (c < ' ' || c > '~')
44 out += snprintf(line + out, LINE_LEN - out, "%c", c);
46 fprintf(f, "%s\n", line);
52 rte_memdump(FILE *f, const char *title, const void *buf, unsigned int len)
55 const unsigned char *data = buf;
59 fprintf(f, "%s: ", title);
62 for (i = 0, out = 0; i < len; i++) {
63 /* Make sure we do not overrun the line buffer length. */
64 if (out >= LINE_LEN - 4) {
65 fprintf(f, "%s", line);
69 out += snprintf(line + out, LINE_LEN - out, "%02x%s",
70 (data[i] & 0xff), ((i + 1) < len) ? ":" : "");
73 fprintf(f, "%s", line);