diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2007-05-29 18:03:26 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2007-05-29 18:03:26 +0000 |
commit | 77cec5547fcb2bb4116363eafb5c8e596af921e9 (patch) | |
tree | 812f17b80657b2d779b35da67a38ef097a638f89 /sys | |
parent | f3760801ec67d778ae5bdbfb1b9fadaccb192f35 (diff) |
Beef up malo_hexdump() to emulate hexdump -C output. Helps to see hidden
agendas in buffers that stupidly encode numbers as strings so that we need
to parse them in the kernel as seen on che(4). OK mglocker@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/ic/malo.c | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/sys/dev/ic/malo.c b/sys/dev/ic/malo.c index 26ecbc40dd4..6f34de7deb8 100644 --- a/sys/dev/ic/malo.c +++ b/sys/dev/ic/malo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: malo.c,v 1.70 2007/05/25 18:31:02 mglocker Exp $ */ +/* $OpenBSD: malo.c,v 1.71 2007/05/29 18:03:25 claudio Exp $ */ /* * Copyright (c) 2006 Claudio Jeker <claudio@openbsd.org> @@ -1998,16 +1998,33 @@ malo_update_slot(struct ieee80211com *ic) void malo_hexdump(void *buf, int len) { - int i; - - for (i = 0; i < len; i++) { - if (i % 16 == 0) - printf("%s%4i:", i ? "\n" : "", i); - if (i % 4 == 0) - printf(" "); - printf("%02x", (int)*((u_char *)buf + i)); + u_char b[16]; + int i, j, l; + + for (i = 0; i < len; i += l) { + printf("%4i:", i); + l = min(sizeof(b), len - i); + bcopy(buf + i, b, l); + + for (j = 0; j < sizeof(b); j++) { + if (j % 2 == 0) + printf(" "); + if (j % 8 == 0) + printf(" "); + if (j < l) + printf("%02x", (int)b[j]); + else + printf(" "); + } + printf(" |"); + for (j = 0; j < l; j++) { + if (b[j] >= 0x20 && b[j] <= 0x7e) + printf("%c", b[j]); + else + printf("."); + } + printf("|\n"); } - printf("\n"); } #endif |