diff rvinterf/trdump.c @ 126:811b138f1bed

rvtdump utility written, compiles
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Thu, 31 Oct 2013 19:59:16 +0000
parents
children f4f0c8738dcb
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/trdump.c	Thu Oct 31 19:59:16 2013 +0000
@@ -0,0 +1,77 @@
+/*
+ * This module implements the basic dump of any incoming packets
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include "pktmux.h"
+
+extern u_char rxpkt[];
+extern size_t rxpkt_len;
+
+void
+print_presumed_string(str, len)
+	u_char *str;
+	size_t len;
+{
+	int i, c;
+
+	for (i = 0; i < len; i++) {
+		c = str[i];
+		if (c & 0x80) {
+			putchar('M');
+			putchar('-');
+			c &= 0x7F;
+		}
+		if (c < 0x20) {
+			putchar('^');
+			putchar(c + '@');
+		} else if (c == 0x7F) {
+			putchar('^');
+			putchar('?');
+		} else
+			putchar(c);
+	}
+}
+
+void
+print_rv_trace()
+{
+	int i;
+
+	/* the SWE static ID is sent MSB first */
+	for (i = 1; i <= 4; i++)
+		printf("%02X", rxpkt[i]);
+	/* severity level */
+	printf(" %d ", rxpkt[5]);
+	print_presumed_string(rxpkt + 6, rxpkt_len - 6);
+	putchar('\n');
+}
+
+void
+print_l1_trace()
+{
+	fputs("L1: ", stdout);
+	print_presumed_string(rxpkt + 1, rxpkt_len - 1);
+	putchar('\n');
+}
+
+void
+print_rx_packet()
+{
+	int i;
+
+	switch (rxpkt[0]) {
+	case RVT_RV_HEADER:
+		print_rv_trace();
+		return;
+	case RVT_L1_HEADER:
+		print_l1_trace();
+		return;
+	}
+	/* default case: print the whole packet in hex as an unknown */
+	fputs("UNK:", stdout);
+	for (i = 0; i < rxpkt_len; i++)
+		printf(" %02X", rxpkt[i]);
+	putchar('\n');
+}