- improved packet logging function (added ASCII dump to hexdump)

This commit is contained in:
Volker Ruppert 2012-09-24 19:32:57 +00:00
parent 7ca95178b0
commit 723dfc2ad7

View File

@ -234,19 +234,34 @@ int execute_script(bx_devmodel_c *netdev, const char* scriptname, char* arg1)
void write_pktlog_txt(FILE *pktlog_txt, const Bit8u *buf, unsigned len, bx_bool host_to_guest)
{
Bit8u *charbuf = (Bit8u *)buf;
unsigned n;
Bit8u rawbuf[18];
unsigned c, n;
if (!host_to_guest) {
fprintf(pktlog_txt, "a packet from guest to host, length %u\n", len);
} else {
fprintf(pktlog_txt, "a packet from host to guest, length %u\n", len);
}
for (n = 0; n < len; n++) {
if (((n % 16) == 0) && (n > 0))
fprintf(pktlog_txt, "\n");
n = 0;
c = 0;
while (n < len) {
fprintf(pktlog_txt, "%02x ", (unsigned)charbuf[n]);
if ((charbuf[n] >= 0x20) && (charbuf[n] < 0x80)) {
rawbuf[c++] = charbuf[n];
} else {
rawbuf[c++] = '.';
}
n++;
if (((n % 16) == 0) || (n == len)) {
rawbuf[c] = 0;
if (n == len) {
while (c++ < 16) fprintf(pktlog_txt, " ");
}
fprintf(pktlog_txt, " %s\n", rawbuf);
c = 0;
}
}
fprintf(pktlog_txt, "\n--\n");
fprintf(pktlog_txt, "--\n");
fflush(pktlog_txt);
}