]> git.meshlink.io Git - utcp/commitdiff
speed up utcp print_packet debug output and print in hex
authorHannes <hannes.ahrens@everbase.net>
Thu, 15 Oct 2015 18:35:04 +0000 (20:35 +0200)
committerGuus Sliepen <guus@sliepen.org>
Sun, 2 Jul 2017 10:04:16 +0000 (12:04 +0200)
utcp.c

diff --git a/utcp.c b/utcp.c
index c125ce0a04d50414b69f22a9cae4abbf62f5f25a..047f70fe795653db1b4abb2ccfb20add21ce6459 100644 (file)
--- a/utcp.c
+++ b/utcp.c
@@ -86,11 +86,24 @@ static void print_packet(struct utcp *utcp, const char *dir, const void *pkt, si
                debug("ACK");
 
        if(len > sizeof hdr) {
-               debug(" data=");
-               for(int i = sizeof hdr; i < len; i++) {
-                       const char *data = pkt;
-                       debug("%c", data[i] >= 32 ? data[i] : '.');
+               uint32_t datalen = len - sizeof hdr;
+               uint8_t *str = malloc((datalen << 1) + 7);
+               memcpy(str, " data=", 6);
+               uint8_t *strptr = str + 6;
+               const uint8_t *data = pkt;
+               const uint8_t *dataend = data + datalen;
+
+               while(data != dataend) {
+                       *strptr = (*data >> 4) > 9? (*data >> 4) + 55 : (*data >> 4) + 48;
+                       ++strptr;
+                       *strptr = (*data & 0xf) > 9? (*data & 0xf) + 55 : (*data & 0xf) + 48;
+                       ++strptr;
+                       ++data;
                }
+               *strptr = 0;
+
+               debug(str);
+               free(str);
        }
 
        debug("\n");