diff mbox

wpa_debug: Support outputting hexdumps into syslog.

Message ID 1327512516-9902-1-git-send-email-cavallar@lri.fr
State Accepted
Commit f31e19df3a97f0610300c847f13c4e4b4656c477
Headers show

Commit Message

Nicolas Cavallari Jan. 25, 2012, 5:28 p.m. UTC
This patch allows to log hexdumps into syslog.

This is useful when testing, as syslog's network logging
helps to collect debug outputs from several machines.

Signed-hostapd: Nicolas Cavallari <cavallar@lri.fr>
---
 src/utils/wpa_debug.c |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)

Comments

Sam Leffler Jan. 25, 2012, 7:37 p.m. UTC | #1
On Wed, Jan 25, 2012 at 9:28 AM, Nicolas Cavallari
<Nicolas.Cavallari@lri.fr> wrote:
> This patch allows to log hexdumps into syslog.
>

Ha, was just about to submit nearly the same thing.  You missed
hexdump_ascii which is a PITA so I punted and pushed the data through
the hexdump routine. Please look at this:

https://gerrit.chromium.org/gerrit/14800

which shows where I was going but is still changing.

Feel free to take from my change w/o attribution.

-Sam
Jouni Malinen Jan. 29, 2012, 10:15 a.m. UTC | #2
On Wed, Jan 25, 2012 at 06:28:35PM +0100, Nicolas Cavallari wrote:
> This patch allows to log hexdumps into syslog.
> 
> This is useful when testing, as syslog's network logging
> helps to collect debug outputs from several machines.

Thanks, applied.
Jouni Malinen Jan. 29, 2012, 10:19 a.m. UTC | #3
On Wed, Jan 25, 2012 at 11:37:18AM -0800, Sam Leffler wrote:
> Ha, was just about to submit nearly the same thing.  You missed
> hexdump_ascii which is a PITA so I punted and pushed the data through
> the hexdump routine. Please look at this:
> 
> https://gerrit.chromium.org/gerrit/14800

I guess that's fine for this purpose. You could remove the extra #ifdef
block in the end and just return from the function after the
_wpa_hexdump call to keep the code structure a bit simpler.
diff mbox

Patch

diff --git a/src/utils/wpa_debug.c b/src/utils/wpa_debug.c
index 5b56d83..274067a 100644
--- a/src/utils/wpa_debug.c
+++ b/src/utils/wpa_debug.c
@@ -166,6 +166,38 @@  static void _wpa_hexdump(int level, const char *title, const u8 *buf,
 	size_t i;
 	if (level < wpa_debug_level)
 		return;
+#ifdef CONFIG_DEBUG_SYSLOG
+	if (wpa_debug_syslog) {
+		const char* display;
+		char* strbuf = NULL;
+
+		if (buf == NULL) {
+			display = " [NULL]";
+		} else if (len == 0) {
+			display = "";
+		} else if (show && len) {
+			strbuf = os_malloc(1 + 3 * len);
+			if (strbuf == NULL) {
+				wpa_printf(MSG_ERROR, "wpa_hexdump: Failed to "
+					   "allocate message buffer");
+				return;
+			}
+
+			for (i = 0; i < len; i++)
+				os_snprintf(&strbuf[i * 3], 4, " %02x",
+					    buf[i]);
+
+			display = strbuf;
+		} else {
+			display = " [REMOVED]";
+		}
+
+		syslog(syslog_priority(level), "%s - hexdump(len=%lu):%s",
+		       title, len, display);
+		os_free(strbuf);
+		return;
+	}
+#endif /* CONFIG_DEBUG_SYSLOG */
 	wpa_debug_print_timestamp();
 #ifdef CONFIG_DEBUG_FILE
 	if (out_file) {