diff options
author | brian <brian@cvs.openbsd.org> | 1999-06-01 16:01:40 +0000 |
---|---|---|
committer | brian <brian@cvs.openbsd.org> | 1999-06-01 16:01:40 +0000 |
commit | 0dad82b0794de40fafaff39aa8cf72f6f0d5df52 (patch) | |
tree | 80429ab9558f16af9521d4b24a0b99f534137b5f /usr.sbin | |
parent | 0eba56da5941159853f8eb2fd84bc4336cffeeaf (diff) |
Make async/sync/physical/hdlc dumps prettier by showing printable
characters at the end of the line in hexdump style.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/ppp/ppp/log.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/usr.sbin/ppp/ppp/log.c b/usr.sbin/ppp/ppp/log.c index a5b1f80d521..59a8bbb7374 100644 --- a/usr.sbin/ppp/ppp/log.c +++ b/usr.sbin/ppp/ppp/log.c @@ -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.5 1999/05/12 10:03:51 brian Exp $ + * $Id: log.c,v 1.6 1999/06/01 16:01:39 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); } } |