diff options
author | brian <brian@FreeBSD.org> | 1999-06-01 16:01:48 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 1999-06-01 16:01:48 +0000 |
commit | f062ad877cb136630a0961452b636e1dfba9602d (patch) | |
tree | cc58157fe21ef061fc8f8fb7ea8d8bb14561bd7d /usr.sbin/ppp/log.c | |
parent | bfae8441dcae5619daec116cb7aaabd710f365b0 (diff) | |
download | FreeBSD-src-f062ad877cb136630a0961452b636e1dfba9602d.zip FreeBSD-src-f062ad877cb136630a0961452b636e1dfba9602d.tar.gz |
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/ppp/log.c')
-rw-r--r-- | usr.sbin/ppp/log.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/usr.sbin/ppp/log.c b/usr.sbin/ppp/log.c index febb5b9..d51bf28 100644 --- a/usr.sbin/ppp/log.c +++ b/usr.sbin/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.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); } } |