1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
5 #include <rte_hexdump.h>
6 #include <rte_string_fns.h>
11 rte_hexdump(FILE *f, const char *title, const void *buf, unsigned int len)
13 unsigned int i, out, ofs;
14 const unsigned char *data = buf;
15 char line[LINE_LEN]; /* space needed 8+16*3+3+16 == 75 */
17 fprintf(f, "%s at [%p], len=%u\n",
18 title ? : " Dump data", data, len);
21 /* format the line in the buffer */
22 out = snprintf(line, LINE_LEN, "%08X:", ofs);
23 for (i = 0; i < 16; i++) {
25 snprintf(line + out, LINE_LEN - out,
26 " %02X", (data[ofs + i] & 0xff));
28 strcpy(line + out, " ");
34 out += snprintf(line + out, LINE_LEN - out, " | ");
36 for (i = 0; ofs < len && i < 16; i++, ofs++) {
37 unsigned char c = data[ofs];
39 if (c < ' ' || c > '~')
41 out += snprintf(line + out, LINE_LEN - out, "%c", c);
43 fprintf(f, "%s\n", line);
49 rte_memdump(FILE *f, const char *title, const void *buf, unsigned int len)
52 const unsigned char *data = buf;
56 fprintf(f, "%s: ", title);
59 for (i = 0, out = 0; i < len; i++) {
60 /* Make sure we do not overrun the line buffer length. */
61 if (out >= LINE_LEN - 4) {
62 fprintf(f, "%s", line);
66 out += snprintf(line + out, LINE_LEN - out, "%02x%s",
67 (data[i] & 0xff), ((i + 1) < len) ? ":" : "");
70 fprintf(f, "%s", line);