]> git.meshlink.io Git - meshlink/commitdiff
log incoming packet payload as hex (not verbatim)
authorSven M. Hallberg <pesco@khjk.org>
Thu, 6 Nov 2014 17:35:12 +0000 (18:35 +0100)
committerGuus Sliepen <guus@meshlink.io>
Sat, 27 Dec 2014 17:35:48 +0000 (18:35 +0100)
src/route.c

index 1cb60d87ddf0f98c997c161943f0ad18a9140bbb..92a360ff7cf7818a7b243c28a5c9d2cf4767a931 100644 (file)
@@ -56,9 +56,16 @@ void route(meshlink_handle_t *mesh, node_t *source, vpn_packet_t *packet) {
        }
 
        if(owner == mesh->self) {
-               logger(mesh, MESHLINK_DEBUG, "I received a packet for me with payload: %s \n", packet->data + sizeof *hdr);
+               const void *payload = packet->data + sizeof *hdr;
+               size_t len = packet->len - sizeof *hdr;
+
+               char hex[len*2 + 1];
+               if(mesh->log_level >= MESHLINK_DEBUG)
+                       bin2hex(payload, hex, len);     // don't do this unless it's going to be logged
+               logger(mesh, MESHLINK_DEBUG, "I received a packet for me with payload: %s\n", hex);
+
                if(mesh->receive_cb)
-                       mesh->receive_cb(mesh, (meshlink_node_t *)source, packet->data + sizeof *hdr, packet->len - sizeof *hdr);
+                       mesh->receive_cb(mesh, (meshlink_node_t *)source, payload, len);
                return;
        }