utils: Factor out hexdump code used by --enable-packet-dump.

Factor out the common code used to hexdump the protocol when
./configure --enable-packet-dump is used.

It's not quite a straight refactor because I had to fix some
signedness bugs in the code which were not revealed before because
this code is usually disabled.
This commit is contained in:
Richard W.M. Jones
2018-06-04 05:24:13 -04:00
parent b699111e04
commit 2add3c6995
4 changed files with 31 additions and 40 deletions

View File

@@ -115,26 +115,8 @@ main_loop (int _sock)
exit (EXIT_FAILURE);
#ifdef ENABLE_PACKET_DUMP
if (verbose) {
size_t i, j;
for (i = 0; i < len; i += 16) {
printf ("%04zx: ", i);
for (j = i; j < MIN (i+16, len); ++j)
printf ("%02x ", (unsigned char) buf[j]);
for (; j < i+16; ++j)
printf (" ");
printf ("|");
for (j = i; j < MIN (i+16, len); ++j)
if (c_isprint (buf[j]))
printf ("%c", buf[j]);
else
printf (".");
for (; j < i+16; ++j)
printf (" ");
printf ("|\n");
}
}
if (verbose)
guestfs_int_hexdump (buf, len, stdout);
#endif
gettimeofday (&start_t, NULL);