Make async/sync/physical/hdlc dumps prettier by showing printable

characters at the end of the line in hexdump style.
This commit is contained in:
Brian Somers 1999-06-01 16:01:48 +00:00
parent a3bcef65cd
commit ba16c8408d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=47672

View File

@ -23,11 +23,12 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: log.c,v 1.37 1999/05/09 20:02:22 brian Exp $
* $Id: log.c,v 1.38 1999/05/12 09:48:52 brian Exp $
*/
#include <sys/types.h>
#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
@ -335,8 +336,8 @@ void
log_DumpBp(int lev, const char *hdr, const struct mbuf *bp)
{
if (log_IsKept(lev)) {
char buf[50];
char *b;
char buf[68];
char *b, *c;
const u_char *ptr;
int f;
@ -344,22 +345,28 @@ log_DumpBp(int lev, const char *hdr, const struct mbuf *bp)
log_Printf(lev, "%s\n", hdr);
b = buf;
c = b + 50;
do {
f = bp->cnt;
ptr = CONST_MBUF_CTOP(bp);
while (f--) {
sprintf(b, " %02x", (int) *ptr++);
sprintf(b, " %02x", (int) *ptr);
*c++ = isprint(*ptr) ? *ptr : '.';
ptr++;
b += 3;
if (b == buf + sizeof buf - 2) {
strcpy(b, "\n");
if (b == buf + 48) {
memset(b, ' ', 2);
strcpy(c, "\n");
log_Printf(lev, buf);
b = buf;
c = b + 50;
}
}
} while ((bp = bp->next) != NULL);
if (b > buf) {
strcpy(b, "\n");
memset(b, ' ', 50 - (b - buf));
strcpy(c, "\n");
log_Printf(lev, buf);
}
}
@ -369,16 +376,20 @@ void
log_DumpBuff(int lev, const char *hdr, const u_char *ptr, int n)
{
if (log_IsKept(lev)) {
char buf[50];
char *b;
char buf[68];
char *b, *c;
if (hdr && *hdr)
log_Printf(lev, "%s\n", hdr);
while (n > 0) {
b = buf;
for (b = buf; b != buf + sizeof buf - 2 && n--; b += 3)
sprintf(b, " %02x", (int) *ptr++);
strcpy(b, "\n");
c = b + 50;
for (b = buf; b != buf + 48 && n--; b += 3, ptr++) {
sprintf(b, " %02x", (int) *ptr);
*c++ = isprint(*ptr) ? *ptr : '.';
}
memset(b, ' ', 50 - (b - buf));
strcpy(c, "\n");
log_Printf(lev, buf);
}
}