mirror of
https://github.com/xemu-project/xemu.git
synced 2024-12-18 01:08:51 +00:00
a1555559ab
qemu_hexdump() in util/hexdump.c has been changed to give also include a ascii dump of the buffer. Also, calls to hex_dump() in net/net.c have been replaced with calls to qemu_hexdump(). This takes care of two misc BiteSized Tasks. Reviewed-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Isaac Lozano <109lozanoi@gmail.com> Signed-off-by: Jason Wang <jasowang@redhat.com>
50 lines
1.3 KiB
C
50 lines
1.3 KiB
C
/*
|
|
* Helper to hexdump a buffer
|
|
*
|
|
* Copyright (c) 2013 Red Hat, Inc.
|
|
* Copyright (c) 2013 Gerd Hoffmann <kraxel@redhat.com>
|
|
* Copyright (c) 2013 Peter Crosthwaite <peter.crosthwaite@xilinx.com>
|
|
* Copyright (c) 2013 Xilinx, Inc
|
|
*
|
|
* This work is licensed under the terms of the GNU GPL, version 2. See
|
|
* the COPYING file in the top-level directory.
|
|
*
|
|
* Contributions after 2012-01-13 are licensed under the terms of the
|
|
* GNU GPL, version 2 or (at your option) any later version.
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
|
#include "qemu-common.h"
|
|
|
|
void qemu_hexdump(const char *buf, FILE *fp, const char *prefix, size_t size)
|
|
{
|
|
unsigned int b, len, i, c;
|
|
|
|
for (b = 0; b < size; b += 16) {
|
|
len = size - b;
|
|
if (len > 16) {
|
|
len = 16;
|
|
}
|
|
fprintf(fp, "%s: %04x:", prefix, b);
|
|
for (i = 0; i < 16; i++) {
|
|
if ((i % 4) == 0) {
|
|
fprintf(fp, " ");
|
|
}
|
|
if (i < len) {
|
|
fprintf(fp, " %02x", (unsigned char)buf[b + i]);
|
|
} else {
|
|
fprintf(fp, " ");
|
|
}
|
|
}
|
|
fprintf(fp, " ");
|
|
for (i = 0; i < len; i++) {
|
|
c = buf[b + i];
|
|
if (c < ' ' || c > '~') {
|
|
c = '.';
|
|
}
|
|
fprintf(fp, "%c", c);
|
|
}
|
|
fprintf(fp, "\n");
|
|
}
|
|
}
|