diff options
author | 1999-06-01 16:01:39 +0000 | |
---|---|---|
committer | 1999-06-01 16:01:39 +0000 | |
commit | 25fe6e667aaff34e573e7018aa23e924b79b67ca (patch) | |
tree | 91bde81228cb142a2dd65a97543a63aa970c894b | |
parent | getfsstat/getmntinfo do not require inclusion of <sys/ucred.h> (diff) | |
download | wireguard-openbsd-25fe6e667aaff34e573e7018aa23e924b79b67ca.tar.xz wireguard-openbsd-25fe6e667aaff34e573e7018aa23e924b79b67ca.zip |
Make async/sync/physical/hdlc dumps prettier by showing printable
characters at the end of the line in hexdump style.
-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); } } |