From 59e5592fed20cc593b784a2ac6fb0e1a47c557ec Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 4 Apr 2021 14:03:58 +0900 Subject: [PATCH] [net] Dump nq udp packets Probably need some finer control, but it will do for now. --- libs/net/nm/net_udp.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/libs/net/nm/net_udp.c b/libs/net/nm/net_udp.c index 2ad422d16..ebc49a886 100644 --- a/libs/net/nm/net_udp.c +++ b/libs/net/nm/net_udp.c @@ -77,6 +77,7 @@ # include #endif +#include #include #include #include @@ -471,6 +472,29 @@ UDP_CheckNewConnections (void) #endif } +static void +hex_dump_buf (byte *buf, int len) +{ + int pos = 0, llen, i; + + while (pos < len) { + llen = (len - pos < 16 ? len - pos : 16); + printf ("%08x: ", pos); + for (i = 0; i < llen; i++) + printf ("%02x ", buf[pos + i]); + for (i = 0; i < 16 - llen; i++) + printf (" "); + printf (" | "); + + for (i = 0; i < llen; i++) + printf ("%c", isprint (buf[pos + i]) ? buf[pos + i] : '.'); + for (i = 0; i < 16 - llen; i++) + printf (" "); + printf ("\n"); + pos += llen; + } +} + int UDP_Read (int socket, byte *buf, int len, netadr_t *from) { @@ -528,6 +552,9 @@ UDP_Read (int socket, byte *buf, int len, netadr_t *from) UDP_AddrToString (from)); last_iface = default_iface; #endif + if (developer->int_val & SYS_net) { + hex_dump_buf (buf, ret); + } return ret; } @@ -576,6 +603,9 @@ UDP_Write (int socket, byte *buf, int len, netadr_t *to) return 0; Sys_MaskPrintf (SYS_net, "sent %d bytes to %s\n", ret, UDP_AddrToString (to)); + if (developer->int_val & SYS_net) { + hex_dump_buf (buf, len); + } return ret; }