From 6dc40e44e2355ac3192492916edaa344125431bd Mon Sep 17 00:00:00 2001 From: Kim Woelders Date: Mon, 15 Oct 2018 07:55:00 +0200 Subject: [PATCH] Enable debug logging data too --- ttynvt.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/ttynvt.c b/ttynvt.c index de5acb6..1e51608 100644 --- a/ttynvt.c +++ b/ttynvt.c @@ -97,10 +97,38 @@ _PRF2_ static void _log(int prio, const char *fmt, ...) va_end(arg); } +#define BPL 16 /* Bytes per line */ + +void _log_buf(int prio, const char *txt, const void *ptr_, unsigned int len) +{ + unsigned int ix, i, imax; + int l, n; + char buf[128]; + const unsigned char *ptr = ptr_; + + for (ix = 0; ix < len || (len == 0 && ix == 0); ix += BPL) + { + n = snprintf(buf, sizeof(buf), "%s: %04x:", txt, ix); + if (n <= 0) + return; /* Just playing it safe */ + imax = (len - ix < BPL) ? len - ix : BPL; + for (i = 0; i < imax; i++) + { + l = snprintf(buf + n, sizeof(buf) - n, " %02x", *ptr++); + if (l <= 0) + return; /* Just playing it safe */ + n += l; + } + _log(prio, "%s\n", buf); + } +} + #define DBG(...) \ if (ttynvt_param.debug > 0) _log(LOG_DEBUG, __VA_ARGS__) #define DBG2(...) \ if (ttynvt_param.debug > 1) _log(LOG_DEBUG, __VA_ARGS__) +#define DBG2_BUF(txt, ptr, len) \ + if (ttynvt_param.debug > 1) _log_buf(LOG_DEBUG, txt, ptr, len) static volatile char _is_interrupted = 0; @@ -226,9 +254,12 @@ static void *_read_net(void *arg) break; } tty->net_cnt += res; + DBG2_BUF("Serv in A", tty->net_buf, tty->net_cnt); res = telnet_rx(tty->tn, tty->net_buf, &tty->net_cnt); + DBG2_BUF("Serv in B", tty->net_buf, tty->net_cnt); if (tty->net_cnt > 0 && res == 0) { + DBG2_BUF("TtyM out ", tty->net_buf, tty->net_cnt); res = write(tty->fds[FD_MASTER].fd, tty->net_buf, tty->net_cnt); if (res < 0) @@ -248,6 +279,7 @@ static void *_read_net(void *arg) _log(LOG_ERR, "master read error: %m\n"); break; } + DBG2_BUF("TtyM in ", tty->tmp_buf, res); telnet_tx(tty->tn, tty->tmp_buf, res); } @@ -309,6 +341,8 @@ static int _srv_write(void *cctx, const void *buf, int len) ttynvt_t *tty = cctx; int res; + DBG2_BUF("Serv out ", buf, len); + res = write(tty->fds[FD_NET].fd, buf, len); DBG2("%s: fd=%d: len=%u: res=%d\n", __func__, @@ -340,7 +374,9 @@ static int _srv_read(void *cctx, int timeout) if (res <= 0) return res; tty->net_cnt += res; + DBG2_BUF("Serv in a", tty->net_buf, tty->net_cnt); res = telnet_rx(tty->tn, tty->net_buf, &tty->net_cnt); + DBG2_BUF("Serv in b", tty->net_buf, tty->net_cnt); DBG2("%s: res=%d net_cnt=%d\n", __func__, res, tty->net_cnt); if (res == 0) break;